afe.core.configsο
Classesο
Generic enumeration. |
|
An empty value class, used to initialize an empty Opt class. |
|
Generic immutable container class having either one value or no value. |
|
Parameters controlling how to quantize a network. |
|
Parameters for calibration. |
|
Used to store the threshold value for quantized model performance. |
|
Used to store the threshold value for quantized model performance. The threshold value is given as a value |
|
Used to store the threshold value for quantized model performance. The threshold value is given as an absolute |
|
Config used for quantization-aware partitioning |
|
Class for holding the configuration information used by the OptimizerClass |
|
Configuration parameters for how to execute networks in |
|
Enumeration specifying the layout conversion algorithm. |
|
Class holding the configuration information used by GraphTransformer and Partitioner. |
|
Dataclass holding all the configuration information used in end-to-end processing. |
Functionsο
Helper function for initializing empty QuantizationConfigs. |
|
|
Merge 2 QuantizationConfigs. |
|
Construct QuantizationConfigs. |
|
Given a field name and a value, if the QuantizationConfigs has attribute name same |
|
Construct CalibrationConfigs using parameters from the network test configuration data. |
|
Construct CalibrationConfigs using user-specified parameters. |
Module Contentsο
- class afe.core.configs.ModelConfigs[source]ο
-
- input_dtypes: List[afe.ir.tensor_type.ScalarType][source]ο
- property dtype_dict: Dict[afe.ir.defines.NodeName, afe.ir.tensor_type.ScalarType][source]ο
- class afe.core.configs.QuantizationPrecision[source]ο
Generic enumeration.
Derive from this class to define new enumerations.
- static from_string(precision: str) QuantizationPrecision [source]ο
- to_scalar_type() afe.ir.tensor_type.ScalarType [source]ο
- to_expected_int_scalar_type() afe.ir.tensor_type.ScalarType [source]ο
- class afe.core.configs.EmptyValue[source]ο
An empty value class, used to initialize an empty Opt class.
- class afe.core.configs.Opt[source]ο
Generic immutable container class having either one value or no value. It is used for storing values of QuantizationConfigs fields.
- value: _T | EmptyValue[source]ο
- class afe.core.configs.QuantizationConfigs[source]ο
Parameters controlling how to quantize a network.
Instances should be constructed using one of the construction functions, not using the class constructor.
Fields can be overridden for specific nodes using the custom_quantization_configs parameter of UpdateQuantizationConfigs. This parameter is accepted by several other functions, as well. See individual fields for restrictions on overriding.
- quantization_precision: Opt[QuantizationPrecision][source]ο
- biascorr_type: Opt[afe.ir.defines.BiasCorrectionType][source]ο
- requantization_mode: Opt[afe.ir.defines.RequantizationMode][source]ο
- afe.core.configs.initialize_empty_quant_config()[source]ο
Helper function for initializing empty QuantizationConfigs.
- afe.core.configs.merge_quantization_configs(*, config1: QuantizationConfigs, config2: QuantizationConfigs) QuantizationConfigs [source]ο
Merge 2 QuantizationConfigs. When merging, values from first config have higher priority and values from second are discarded so QuantizationConfigs with higher priority should be config1.
- afe.core.configs.create_quantization_configs(*, asymmetry: bool = True, per_channel: bool = False, leaky_relu_uses_udf: bool = True, quantization_precision: QuantizationPrecision = QuantizationPrecision.INT_8, quantization_sensitivity: int = 0, requantization_mode: afe.ir.defines.RequantizationMode = RequantizationMode.sima, intermediate_int32: bool = False, biascorr_type: afe.ir.defines.BiasCorrectionType = BiasCorrectionType.NONE, output_int32: bool = False, channel_equalization: bool = False, smooth_quant: bool = False) QuantizationConfigs [source]ο
Construct QuantizationConfigs.
- Parameters:
asymmetry β Whether to use asymmetric quantization.
per_channel β Whether to use per-channel quantization.
leaky_relu_uses_udf β Whether to use UDF instead of arithmetic instructions for quantization.
quantization_precision β Precision used during quantization.
quantization_sensitivity β Sensitivity for mixed precision quantization.
requantization_mode β A way of doing quantized arithmetic.
intermediate_int32 β Whether to use wide node outputs during quantization.
biascorr_type β Method to correct for quantization-induced bias: None/Regular/Iterative.
output_int32 β Whether to use the int32 numeric type in the output of convolution related operators.
channel_equalization β Whether to enable channel equalization.
smooth_quant β Whether to enable smooth quant.
- Returns:
QuantizationConfigs
- afe.core.configs.update_quantization_configs(quantization_configs: QuantizationConfigs, field_name: str, value: Any) None [source]ο
Given a field name and a value, if the QuantizationConfigs has attribute name same as the given field name, update the attribute with the given value.
Parametersο
- param quantization_configs:
QuantizationConfigs.
- param field_name:
str. Name of the target attribute in the given QuantizationConfigs object.
- param value:
Any. Target value that is going to be assigned to the attribute.
- class afe.core.configs.CalibrationConfigs[source]ο
Parameters for calibration.
Instances should be constructed using one of the construction functions.
Attributeο
- attribute calibration_method:
CalibrationMethod used during calibration. See the CalibrationMethod Enum class for currently supported methods.
- attribute num_calibration_samples:
int. Limit on number of data samples that we use to feed inputs to the AwesomeNet during calibration. If None, all data samples that are passed to calibration are used.
- attribute percentile_value:
Optional[float]. Percentage of values to keep when using histogram percentile.
- calibration_method: afe.apis.defines.CalibrationMethod[source]ο
- afe.core.configs.create_testcase_calibration_configs(num_calibration_samples: int, calibration_method: afe.apis.defines.CalibrationMethod = MinMaxMethod()) CalibrationConfigs [source]ο
Construct CalibrationConfigs using parameters from the network test configuration data.
- Parameters:
num_calibration_samples β Maximum number of calibration data samples to use for calibration.
calibration_method β CalibrationMethod used in calibration. See the CalibrationMethod Enum class for supported values.
- Returns:
Constructed value
- afe.core.configs.api_calibration_configs(calibration_method: afe.apis.defines.CalibrationMethod = MinMaxMethod()) CalibrationConfigs [source]ο
Construct CalibrationConfigs using user-specified parameters.
- Parameters:
calibration_method β CalibrationMethod used in calibration. See the CalibrationMethod Enum class for supported values.
percentile_value β Optional[float]. In case of Histogram percentile observer, configures percentage of values to keep in the histogram.
- Returns:
Constructed value
- class afe.core.configs.PerfThreshold[source]ο
Used to store the threshold value for quantized model performance.
- class afe.core.configs.RelativePerfThreshold[source]ο
Used to store the threshold value for quantized model performance. The threshold value is given as a value relative to the floating-point model performance.
- Parameters:
rel_value β float. Quantized model performance threshold value relative to the floating-point model performance.
- class afe.core.configs.AbsolutePerfThreshold[source]ο
Used to store the threshold value for quantized model performance. The threshold value is given as an absolute value.
- Parameters:
abs_value β float. Quantized model performance threshold value.
- class afe.core.configs.QuantizationAwarePartitioningConfigs[source]ο
Config used for quantization-aware partitioning
Attributeο
- attribute performance_threshold:
PerfThreshold. Value used as a target for quantized model performance. Given either as an absolute value or as a value relative to the floating point model performance.
- attribute target_performance_mode:
PerformanceMode. Whether the target performance is given as an absolute value or as a value relative to the floating point model performance.
- attribute max_iterations:
int. Maximal number of iterations in the QAP loop. Represents the maximal number of layers that are to be fixed to floating point while performing the quantization-aware partitioning.
- attribute graph_analyzer_mode:
QuantizedGraphAnalyzerMode. Graph analysis execution mode.
- attribute graph_analyzer_metric:
str. Metric used in graph analysis.
- attribute graph_analyzer_number_of_samples:
int. Number of input samples to be used in graph analysis.
- performance_threshold: PerfThreshold[source]ο
- graph_analyzer_mode: afe.core.graph_analyzer.utils.QuantizedGraphAnalyzerMode[source]ο
- graph_analyzer_metric: afe.core.graph_analyzer.utils.Metric[source]ο
- class afe.core.configs.OptimizationConfigs[source]ο
Class for holding the configuration information used by the OptimizerClass
- calibration_configs: CalibrationConfigs[source]ο
- quantization_configs: QuantizationConfigs[source]ο
- compression_configs: CompressionConfigs[source]ο
- class afe.core.configs.RunConfigs[source]ο
Configuration parameters for how to execute networks in software emulation.
- Attribute fast_mode:
If True, use a fast implementation of an operator. Results may not match the result of executing on the MLA. If False, use an implementation that exactly matches execution on the MLA.
- class afe.core.configs.ConvertLayoutMethod[source]ο
Enumeration specifying the layout conversion algorithm.
Common processing flow requires the model to be converted to MLAβs native layout, that is βNHWCβ. This enumeration specifies what algorithm shall be used for layout conversion. Currently, the βlegacyβ algorithm is tested and proven on most CNN models. The βautomatedβ algorithm is being developed and is aimed mostly for ViT models. The βnoneβ option is used in internal test cases, and it specifies the processing flow where layout conversion is skipped. It should not be used in the general model processing pipeline.
- NONE = 'none'[source]ο
No layout conversion. This is backward-compatible value designating the case where layout conversion transform is disabled in some test cases. Since we would want to run the layout conversion algorithm for all of the test cases, this value would get deprecated in the future.
- static from_str(method: str) ConvertLayoutMethod [source]ο
Helper method for constructing an enumeration instance from string.
- Parameters:
method β String parameter defining the layout conversion method.
- Returns:
The ConvertLayoutMethod Enum instance.
- class afe.core.configs.TransformerConfigs(convert_layout_method: ConvertLayoutMethod = ConvertLayoutMethod.LEGACY, enable_graph_partition: bool = True, backend_indices_dict: dict[afe.backends.Backend, list[int | tuple[int, Ellipsis]]] | None = None, enable_quantization_based_partitioning: bool = False, *, requantization_mode: afe.ir.defines.RequantizationMode = RequantizationMode.sima, enabled_backends: afe._tvm._tvm_graph_partition.CompileMode = CompileMode.MLA_EV74_CPU)[source]ο
Class holding the configuration information used by GraphTransformer and Partitioner.
Attributesο
- attribute convert_layout_method:
Specifies the algorithm used for converting the model layout.
- attribute enable_graph_partition:
bool. Whether to apply graph partitioning on the model.
- attribute indices_to_backend_dict:
Optional[Dict[int, afe.backends.Backend]]. Dictionary containing mapping of layer indices to itβs targeted backend, if any. If a layer {index: target_backend} pair is present in the dictionary, it means that the layer with given index will be executed on the target_backend Backend. If the index is absent from the dictionary, it means that the layer with that index will be executed on the highest-priority backend that is supported for that layer.
- attribute enable_quantization_based_partitioning:
bool. Flag containing information whether to apply quantization-based partitioning.
- attribute requantization_mode:
How to convert TVM quantized operators to SiMa IR quantized operators. Only quantized TVM operators that are assigned the MLA are affected.
- attribute enabled_backends:
Which set of backends to assign nodes to in graph partitioning. Any assignment in backend_indices_dict overrides this parameter.
Exampleο
The example shows how to create a TransformerConfigs that will convert the layout to NHWC, enable the graph partitioning, and set the node with index = [1, 13, 22] to APU:
backend_indices_dict = {Backend.APU: [1, 13, 22]} transformer_configs = TransformerConfigs(convert_layout=True,
enable_graph_partition=True, backend_indices_dict=backend_indices_dict)
- convert_layout_method: ConvertLayoutMethod[source]ο
- indices_to_backend_dict: dict[int, afe.backends.Backend][source]ο
- requantization_mode: afe.ir.defines.RequantizationMode[source]ο
- property convert_layout: bool[source]ο
Property defining whether layout conversion algorithm is enabled.
This property is defined due to backward portability issues, and should be used only in some helper test functions (i.e. determining whether model inputs and/or outputs should be transposed during the test run). This property should not be used to define any aspect of tvm transformations, as it would be deprecated in near future.
- Returns:
Boolean flag determining whether layout conversion algorithm is run during tvm transformations.
- class afe.core.configs.AfeProcessingConfigs[source]ο
Dataclass holding all the configuration information used in end-to-end processing.
Attributesο
- attribute model_configs:
ModelConfigs. Configuration information on model that is being processed.
- attribute transformer_configs:
TransformerConfigs. Configuration information on transformations being used in model processing.
- attribute optimization_configs:
OptimizationConfigs. Configuration information on optimizations being used in processing.
- attribute qap_configs:
QuantizationAwarePartitioningConfigs. Configuration information being used in quantization-aware partitioning algorithm.
- attribute target:
A target platform that a model is compiled for.
- model_configs: ModelConfigs[source]ο
- transformer_configs: TransformerConfigs[source]ο
- optimization_configs: OptimizationConfigs[source]ο
- qap_configs: QuantizationAwarePartitioningConfigs[source]ο