afe.ir.transform

Submodules

Classes

Calibrate

Calibrates an AwesomeNet.

InsertNodeObservers

Inserts NodeObservers into AwesomeNet's nodes. NodeObservers will not be added

RemoveNodeObservers

Remove NodeObservers from AwesomeNet's nodes. This is needed in order to remove

UpdateQuantizationConfigs

Update quantization configs to each node in AwesomeNet

Quantize

Quantizes an AwesomeNet

Compress

Compresses an AwesomeNet

Package Contents

class afe.ir.transform.Calibrate(length_hint: int | None, dataset: Iterable[Dict[str, numpy.ndarray]])[source]

Calibrates an AwesomeNet.

Parameters:
  • length_hint – If not None, gives the number of items in the data set. This is used for progress reporting and it does not affect the number of items used for calibration.

  • dataset – The input data set for calibration.

class afe.ir.transform.InsertNodeObservers(calibration_method: afe.apis.defines.CalibrationMethod)[source]

Inserts NodeObservers into AwesomeNet’s nodes. NodeObservers will not be added to nodes that don’t use information obtained from calibration pass, but obtain quantization parameters based on the quantization parameters of its inputs.

Parameters:
  • calibration_method – CalibrationMethod used in calibration. Determines the type of observers which shall be created. See CalibrationMethod Enum class for supported values.

  • percentile_value – If the Histogram percentile is being used, percentage of values to keep.

class afe.ir.transform.RemoveNodeObservers[source]

Remove NodeObservers from AwesomeNet’s nodes. This is needed in order to remove PyTorch infrastructure which is no longer needed from AwesomeNet’s nodes.

class afe.ir.transform.UpdateQuantizationConfigs(quant_configs: afe.core.configs.QuantizationConfigs, custom_quantization_configs: Dict[afe.ir.defines.NodeName, Dict[str, Any]] | None = None)[source]

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}}

class afe.ir.transform.Quantize[source]

Quantizes an AwesomeNet

class afe.ir.transform.Compress[source]

Compresses an AwesomeNet