afe.ir.build_node ================= .. py:module:: afe.ir.build_node .. autoapi-nested-parse:: Functions for building and initializing AwesomeNodes for specific operators. These functions provide a simpler way to create an instance of a chosen operator and initialize all the data structure fields. These functions are not used for transformations on arbitrary operators. Attributes ---------- .. autoapisummary:: afe.ir.build_node.NodeOrHandle Classes ------- .. autoapisummary:: afe.ir.build_node.NodeHandle Functions --------- .. autoapisummary:: afe.ir.build_node.create_tuple_output_node afe.ir.build_node.create_tuple_get_item_nodes afe.ir.build_node.create_tuple_node afe.ir.build_node.create_tuple_get_item_nodes_2 afe.ir.build_node.create_placeholder_node afe.ir.build_node.create_quantization_node afe.ir.build_node.create_dequantization_node afe.ir.build_node.create_requantization_node afe.ir.build_node.create_cast_node afe.ir.build_node.create_softmax_node afe.ir.build_node.create_argmax_node afe.ir.build_node.create_broadcast_to_node afe.ir.build_node.create_batch_matmul_node afe.ir.build_node.create_add_node afe.ir.build_node.create_subtract_node afe.ir.build_node.create_mul_node afe.ir.build_node.create_sigmoid_node afe.ir.build_node.create_swish_node afe.ir.build_node.create_gelu_node afe.ir.build_node.create_quick_gelu_node afe.ir.build_node.create_slice_concat_node afe.ir.build_node.create_slice_node afe.ir.build_node.create_conv_node afe.ir.build_node.create_rms_norm_node afe.ir.build_node.create_concat_node afe.ir.build_node.create_constant_node afe.ir.build_node.create_net_node Module Contents --------------- .. py:class:: NodeHandle Information about a SiMa IR node that can be used when creating other nodes. .. py:attribute:: name :type: afe.ir.defines.NodeName .. py:attribute:: type :type: afe.ir.defines.DataValue[afe.ir.tensor_type.TensorType] .. py:attribute:: quantization :type: afe.ir.defines.DataValue[afe.ir.defines.Quantization | None] .. py:method:: from_node(n: afe.ir.node.AwesomeNode) -> NodeHandle :staticmethod: Create a NodeHandle representing a given node. :param n: Node to be represented by the handle .. py:data:: NodeOrHandle .. py:function:: create_tuple_output_node(tuple_inputs: List[afe.ir.node.AwesomeNode], prefix: str) -> afe.ir.node.AwesomeNode Creates a Tuple AwesomeNode. Used to accommodate AwesomeNet with multiple outputs. :param tuple_inputs: List of AwesomeNodes that serve as input nodes to resulting Tuple AwesomeNode. :return: The created Tuple AwesomeNode. .. py:function:: create_tuple_get_item_nodes(input_node_name: afe.ir.defines.NodeName, output_types: List[afe.ir.tensor_type.TensorType], prefix: str, input_quant: Optional[afe.ir.defines.TupleValue[afe.ir.attributes.QuantResultTensorType]] = None) -> List[afe.ir.node.AwesomeNode] Creates a TupleGetItem node that is used to split the Tuple output node. :param input_node_name: The name of the input Tuple node. :param output_types: List of types corresponding to the output types of the Tuple node. :param prefix: The prefix string that is prepended to the TupleGetItem node name. :param input_quant: Quantization parameters of the input nodes. :return: The list of TupleGtItem AwesomeNodes. .. py:function:: create_tuple_node(fields: List[NodeOrHandle], name_counter: int) -> afe.ir.node.AwesomeNode Creates a Tuple AwesomeNode. Used to accommodate AwesomeNet with multiple outputs. :param fields: List of AwesomeNodes that serve as input nodes to resulting Tuple AwesomeNode. :return: The created Tuple AwesomeNode. .. py:function:: create_tuple_get_item_nodes_2(data: NodeOrHandle, name_counter: int) -> list[afe.ir.node.AwesomeNode] .. py:function:: create_placeholder_node(node_name: str, input_type: afe.ir.tensor_type.TensorType) -> afe.ir.node.AwesomeNode Creates a Placeholder AwesomeNode. Each AwesomeNet must have PlaceholderNodes to hold the input data. :param node_name: The name of the placeholder node to be created. :param input_type: The input type for the placeholder node. :return: Placeholder node that is created. .. py:function:: create_quantization_node(input_name: afe.ir.defines.NodeName, name_counter: int, cast: afe.ir.defines.QuantCast, backend: afe.backends.Backend = Backend.EV) -> afe.ir.node.AwesomeNode Create a quantization node to quantize from float to integer (int8, int16) :param input_name: Input node name :param name_counter: Node index :param cast: Cast to perform quantization :param backend: Backend on which node will be executed :return: AwesomeNode .. py:function:: create_dequantization_node(input_name: afe.ir.defines.NodeName, name_counter: int, cast: afe.ir.defines.DequantCast, backend: afe.backends.Backend = Backend.EV) -> afe.ir.node.AwesomeNode Create a dequantization node to dequantize from integer (int8, int16, int32) to float. :param input_name: Input node name :param name_counter: Node index :param cast: Cast to perform dequantization :param backend: Backend on which node will be executed :return: AwesomeNode .. py:function:: create_requantization_node(input_name: afe.ir.defines.NodeName, name_counter: int, input_type: afe.ir.tensor_type.TensorType, input_quant: afe.ir.defines.Quantization, output_quant: afe.ir.defines.Quantization, requant_method: afe.ir.defines.RequantMethod, requant: ml_kernels.requantization.BaseRequantization[numpy.ndarray]) -> afe.ir.node.AwesomeNode Create requantization node that will be used for converting data from int32 to int16 or int8 type. :param input_name: Input node name :param name_counter: Node index :param input_type: TensorType of the input tensor :param input_quant: Quantization of input tensor :param output_quant: Quantization of output tensor :param requant_method: Requantization method :param requant: Requantization to perform :return: AwesomeNode .. py:function:: create_cast_node(data: NodeOrHandle, name_counter: int, output_type: afe.ir.tensor_type.ScalarType) -> afe.ir.node.AwesomeNode Create a node that casts tensors from one scalar type to another. Casting does not requantize, but only converts the data to a different numeric type. :param data: Input of the new cast node :param name_counter: Node index :param output_type: Scalar type of the output :returns: New cast node. .. py:function:: create_softmax_node(data: NodeOrHandle, name_counter: int, axis: int) -> afe.ir.node.AwesomeNode Create a softmax node. :param data: Input node :param name_counter: Node index :param axis: Axis over which softmax is computed :returns: Softmax node. .. py:function:: create_argmax_node(data: NodeOrHandle, name_counter: int, output_type: afe.ir.tensor_type.ScalarType) -> afe.ir.node.AwesomeNode Create an argmax node. :param data: Input node :param name_counter: Node index :param output_type: Type of output. Must be int8 or int32. :returns: Argmax node. .. py:function:: create_broadcast_to_node(data: NodeOrHandle, name_counter: int, output_shape: tuple[int, Ellipsis]) -> afe.ir.node.AwesomeNode Create a broadcast_to node. :param data: Input of the new node :param name_counter: Node index :param output_shape: Shape of the output :returns: Broadcast_to node. .. py:function:: create_batch_matmul_node(lhs: NodeOrHandle, rhs: NodeOrHandle, name_counter: int, transpose_b: bool) -> afe.ir.node.AwesomeNode Create a batch_matmul node. :param lhs: LHS input of the new node :param rhs: RHS input of the new node :param name_counter: Node index :param transpose_b: Whether the batch_matmul computation transposes the rhs :returns: batch_matmul node .. py:function:: create_add_node(lhs: NodeOrHandle, rhs: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create an add node. :param lhs: LHS input of the new node :param rhs: RHS input of the new node :param name_counter: Node index :returns: Add node .. py:function:: create_subtract_node(lhs: NodeOrHandle, rhs: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a subtract node. :param lhs: LHS input of the new node :param rhs: RHS input of the new node :param name_counter: Node index :returns: subtract node .. py:function:: create_mul_node(lhs: NodeOrHandle, rhs: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a multiply node. :param lhs: LHS input of the new node :param rhs: RHS input of the new node :param name_counter: Node index :returns: multiply node .. py:function:: create_sigmoid_node(data: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a sigmoid node. :param data: The input node :param name_counter: Node index :returns: sigmoid node .. py:function:: create_swish_node(data: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a swish node. :param data: The input node :param name_counter: Node index :returns: swish node .. py:function:: create_gelu_node(data: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a gelu node. :param data: The input node :param name_counter: Node index :returns: gelu node .. py:function:: create_quick_gelu_node(data: NodeOrHandle, name_counter: int) -> afe.ir.node.AwesomeNode Create a quick_gelu node. :param data: The input node :param name_counter: Node index :returns: quick_gelu node .. py:function:: create_slice_concat_node(data: NodeOrHandle, name_counter: int, axis: int, split_axis: int, split_block: int, split_repeat: int) Create a slice_concat node. :param data: Input of the slice_concat node :param name_counter: Node index :param axis: Axis to concatenate :param split_axis: Axis to split :param split_block: Number of parts to split into :param split_repeat: Number of repetitions of split parts :returns: Result of concatenation. .. py:function:: create_slice_node(data: NodeOrHandle, name_counter: int, begin: list[int], end: list[int], strides: list[int], axes: list[int]) -> afe.ir.node.AwesomeNode .. py:function:: create_conv_node(data: NodeOrHandle, name_counter: int, weights: numpy.ndarray, bias: numpy.ndarray | None, conv_attrs: afe.ir.attributes.ConvAttrs, activation: None, scales: numpy.ndarray | None = None) .. py:function:: create_rms_norm_node(data: NodeOrHandle, name_counter: int, epsilon: float, scale: numpy.ndarray) -> afe.ir.node.AwesomeNode Create an RMSNorm node. :param data: Input of node :param name_counter: Node index :param epsilon: Epsilon value used in RMSNorm calculation :param scale: Output scale factor. This is a 1D array used in per-channel multiplication as part of the RMSNorm operator. :returns: RMSNorm node .. py:function:: create_concat_node(tensors: Sequence[NodeOrHandle], name_counter: int, axis: int) -> afe.ir.node.AwesomeNode .. py:function:: create_constant_node(name_counter: int, value: numpy.ndarray) -> afe.ir.node.AwesomeNode Create a constant node. :param name_counter: Node index :param value: Constant tensor value :returns: Constant node .. py:function:: create_net_node(net: afe.ir.net.AwesomeNet, input_names: list[afe.ir.defines.NodeName]) -> afe.ir.node.AwesomeNode Create a node containing an AwesomeNet. :param net: Net to put into the node :param input_names: Inputs of the node. These are values from the network. :returns: Node containing the AwesomeNet.