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_logging_level

Sets the log levels of the messages printed to the screen and those saved in the amct_log/amct_tensorflow.log file.

GraphEvaluator

Provides a Python instance based on the input data of the bin type for a model to calibrate and infer the model.

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.

quantize_model

Quantizes a graph based on the quantization configuration file, inserts the quantization operators, generates a quantization factor record file record_file, and returns the list of newly added operators.

save_model

Inserts operators such as AscendQuant and AscendDequant into the original .pb model based on the quantization factor record file record_file and generates a .pb model file that serves for both accuracy simulation in the TensorFlow environment and inference deployment on the AI processor.

accuracy_based_auto_calibration

Calibrates the input model based on the input configuration file to search for a quantization configuration that meets accuracy requirements, and outputs a model suitable for both accuracy simulation in the TensorFlow environment and inference deployment on the AI processor.

quantize_preprocess

Preprocesses the quantization of a graph based on the quantization configuration file (currently, only balanced quantization is supported), inserts the balanced quantization operators, and generates a balance factor record file record_file that is to be read in the subsequent quantize_model phase.

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 model that can be used for both accuracy simulation and inference deployment.

Sparsity APIs

create_prune_retrain_model

Filter-level sparsity or 2:4 structured sparsity API. Only either of the two sparsity features can be enabled at a time.

save_prune_retrain_model

Filter-level sparsity or 2:4 structured sparsity API. Only either of the two sparsity features can be enabled at a time.

Auto Channel Pruning Search API

auto_channel_prune_search

Calculates the sparsity sensitivity (affecting accuracy) and sparsity gain (affecting performance) of each channel based on the user model. Then, the search policy searches for the optimal layer-wise channel sparsity ratio based on the input to balance accuracy and performance. Finally, a configuration file is generated.

Compression Combination APIs

create_compressed_retrain_model

Applies to static compression combination. Sparsifies the input graph (via either filter-level sparsity or 2:4 structured sparsity) based on the specified compression configuration file, inserts quantization operators, and returns the modified graph.

save_compressed_retrain_model

Applies to static compression combination. Generates the resultant model of static compression combination from the retrained model.

Tensor Decomposition APIs

auto_decomposition

Performs tensor decomposition on the original TensorFlow model, generating a new model file.

decompose_graph

Fine-tunes a decomposed model by decomposing the graph in the training code.

Model Adaptation APIs

convert_model

Converts a TensorFlow model based on the user-defined quantization factors into a model serving for both accuracy simulation in the TensorFlow environment and inference on the AI processor.

convert_qat_model

Converts a TensorFlow QAT model to a quantized model that serves for both accuracy simulation on the CPU and GPU and deployment on the AI processor.