quantize_preprocess

Applicable Products

Product

Supported

Ascend 950PR/Ascend 950DT

√

Atlas A3 training products/Atlas A3 inference products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas 200I/500 A2 inference products

√

Atlas inference products

√

Atlas training products

√

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)