General Restrictions and APIs

General Restrictions

  • AMCT does not perform security verification of passed file paths. Ensure that the file path arguments passed to any API call are correct.
  • If the API contains a parameter that requires the user to enter the file path, the value of the parameter will be overwritten when quantization is performed again. The quantization log printed to the screen also contains a warning message indicating that the related file is overwritten.

APIs

Category

API

Function

Common APIs

set_gpu_mode

Schedules AMCT weight quantization to the GPU.

set_cpu_mode

Schedules AMCT weight quantization to the CPU.

PTQ APIs

create_quant_config

Finds all quantizable layers in a graph, creates a quantization configuration file, and writes the quantization configuration of the quantizable layers to the configuration file.

init

Initializes AMCT, saves the quantization factor record file, and parses the user model into a graph that can be used for the quantize_model and save_model API calls.

quantize_model

Performs quantization on a graph based on the quantization configuration file config_file, inserts weight and activation quantization layers, and saves the modified network to a new model file.

save_model

Inserts operators such as AscendQuant and AscendDequant into the modified graph, and outputs a fake-quantized model for accuracy simulation in the Caffe environment and a deployable model on the AI processor for inference.

accuracy_based_auto_calibration

Performs automatic calibration on a model based on the input configuration file, searches for a quantization configuration that meets the accuracy requirement, and outputs a fake-quantized model for accuracy simulation in the Caffe environment and a deployable model on the AI processor for inference.

QAT APIs

create_quant_retrain_config

Finds all quantizable layers in a graph, creates a quantization configuration file, and writes the quantization configuration of the quantizable layers to the configuration file.

create_quant_retrain_model

Performs quantization on a graph based on the configuration file (config_file), inserts activation and weight fake-quantization layers, and saves the modified network to a new model file.

save_quant_retrain_model

Inserts operators such as AscendQuant and AscendDequant into the retrained model and generates a fake-quantized model for accuracy simulation and a deployable model.

Model Adaptation API

convert_model

Converts a Caffe model based on user-defined quantization factors into two models — one fake-quantized for accuracy simulation in the Caffe environment and the other deployable on the AI processor for online inference.

Tensor Decomposition API

auto_decomposition

Generates a decomposed model file and its weight file from a given Caffe model file (.prototxt) and its weight file (.caffemodel).