quantize_preprocess

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product

Atlas training product

Description

Preprocesses the quantization of a graph based on the quantization configuration file, inserts the balanced quantization operators, generates a balanced quantization factor record file record_file, and returns an ONNX model ready for calibration.

Prototype

1
quantize_preprocess(config_file, record_file, model_file, modified_onnx_file)

Parameters

Parameter

Input/Output

Description

config_file

Input

User-generated distillation configuration file, which is used to specify the configuration of the quantization layer in the model network.

A string.

record_file

Input

Path (including the file name) of the balanced quantization factor record file.

A string.

model_file

Input

Original ONNX model file or updated model generated by the create_quant_config API.

A string.

modified_onnx_file

Input

Name of the file for storing the ONNX calibration model for activation quantization.

A string.

Returns

None

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import amct_onnx as amct

model_file = "resnet101.onnx"
tensor_balance_factor_record_file  = os.path.join(TMP, 'tensor_balance_factor_record.txt')
modified_model = os.path.join(TMP, 'modified_model.onnx')
config_file="./configs/config.json"
# Insert the quantization API.
amct.quantize_preprocess(config_file,
                         tensor_balance_factor_record_file,
                         model_file,
                         modified_model)