afe.ir.transform.quantization_transforms ======================================== .. py:module:: afe.ir.transform.quantization_transforms Classes ------- .. autoapisummary:: afe.ir.transform.quantization_transforms.UpdateQuantizationConfigs afe.ir.transform.quantization_transforms.QuantizeState afe.ir.transform.quantization_transforms.Quantize Functions --------- .. autoapisummary:: afe.ir.transform.quantization_transforms.add_external_nodes_to_float_node_list afe.ir.transform.quantization_transforms.traverse_network afe.ir.transform.quantization_transforms.quantized_operation_execution Module Contents --------------- .. py:class:: UpdateQuantizationConfigs(quant_configs: afe.core.configs.QuantizationConfigs, custom_quantization_configs: Optional[Dict[afe.ir.defines.NodeName, Dict[str, Any]]] = None) Update quantization configs to each node in AwesomeNet :attribute asymmetry: bool. Set to True if users want to do asymmetry quantization for all layers or False for symmetric quantization unless some layers are specific configured in the custom_quantization_configs. :attribute per_channel: bool. Set to True if users want to do per-channel quantization for all layers or False for per-tensor quantization unless some layers are specific configured in the custom_quantization_configs. :attribute leaky_relu_uses_udf: Default is True. If Ture, AFE will use UDF for LeakyRelu operation. Else AFE will breakdown the LeakyRelu into multiple elementwise operationis unless some layers are specific configured in the custom_quantization_configs. :attribute custom_quantization_configs: Optional[Dict[NodeName, Dict[str, Any]]]. A dictionary using NodeName as keys. The value to each key is a dictionary of the AwesomeQuantAttr's field names and sets target configuration. Example ------- The example shows how a custom_quantization_configs looks like to config the output_int32 field in a Conv2DQuantAttrs in a output conv2d_add node to True. custom_quantization_configs = {"MLA_1/conv2d_add_84": {"output_int32": True}} .. py:function:: add_external_nodes_to_float_node_list(net: afe.ir.net.AwesomeNet) -> None Adding names of external nodes to the net.float_node_list attributes. net.float_node_list is used to decide whether to apply quantization transforms on a node. Parameters ---------- :param net: AwesomeNet. .. py:function:: traverse_network(visit_node: Callable[[_State, Dict[afe.ir.defines.InputName, _A], Optional[_A], afe.ir.node.AwesomeNode], _A], state: _State, inputs: Dict[afe.ir.defines.InputName, _A], net: afe.ir.net.AwesomeNet) -> _A Traverse a network in topological order and process each node using visit_function. Values are propagated along graph edges. The network's topological order must have been computed. The topological order upon entry to the function is used. :param visit_node: Processing to do on a network node. Processing can access shared state and can read results from processing the node's inputs. Processing returns a result to be passed to other nodes. It may modify the node and the network. :param net: Network to traverse. :param state: Mutable data used by visit_node. :param inputs: An ordered dict of values for the net's inputs. :return: Result of processing the network's output node. .. py:class:: QuantizeState Data used by the quantization algorithm during traversal of a network's nodes. .. py:attribute:: casts :type: afe.ir.defines.QuantizationCasts .. py:attribute:: disallowed_quantization_nodes :type: Set[afe.ir.defines.NodeName] .. py:attribute:: num_calibration_inputs :type: int .. py:method:: initialize(num_calibration_inputs: int) -> QuantizeState :classmethod: Initialize a new QuantizeState for the beginning of the algorithm. .. py:method:: enter_awesome_net_scope(net: afe.ir.net.AwesomeNet, num_calibration_inputs: int) -> QuantizeState Prepare to process the nodes in net. Returns a new QuantizeState with information about the nodes in net. Some mutable data is shared with the original QuantizeState. .. py:function:: quantized_operation_execution(state: QuantizeState, inputs: Dict[afe.ir.defines.InputName, afe.ir.operations.QuantizationTensorData], placeholder_value: Optional[afe.ir.operations.QuantizationTensorData], node: afe.ir.node.AwesomeNode, node_casts: afe.ir.defines.InputsQuantCast) -> List[numpy.ndarray] .. py:class:: Quantize Quantizes an AwesomeNet