aclgrphCalibration

Applicable Products

  • Ascend 950PR&950DT products: supported
  • Atlas A3 products: supported
  • Atlas A2 products: supported
  • Atlas 200I/500 A2 inference products: supported
  • Atlas inference products: supported
  • Atlas training products: supported

Header File/Library File

  • Header file: #include <amct/acl_graph_calibration.h>
  • Library file: libamctacl.so

Description

Automatically transforms a non-quantized graph into a quantized graph. For details about the application scenarios, see Quantization.

AMCT also provides two other quantization APIs: graphCalibration and amctGraphCalibration, which encapsulate quantization parameters. aclgrphCalibration is recommended.

Prototype

1
graphStatus aclgrphCalibration(ge::Graph &graph, const std::map<ge::AscendString, ge::AscendString> &quantizeConfigs)

Parameters

Parameter

Input/Output

Description

graph

Input

Original graph to be modified.

quantizeConfigs

Input

Key-value mapping table for the configuration options required for API execution. Both key (indicating the parameter type) and value (indicating the parameter value) are in string format. The configuration options are as follows:

  • INPUT_DATA_DIR: (mandatory) path to the .bin file used to compute quantization factors. You are advised to pass data of at least one batch. If the model has multiple inputs, separate the input data file paths with commas (,).
  • INPUT_SHAPE: (mandatory) shape of the input data. For example, "input_name1:n1,c1,h1,w1;input_name2:n2,c2,h2,w2". The specified nodes must be enclosed in double quotation marks ("") and separated by semicolons (;). input_name must be the name of a node in the graph.
  • SOC_VERSION: (mandatory) name of the chip used for PTQ calibration and inference.

    To query <soc_version>, perform the following steps:

    • For products except for the Atlas A3 products: Run the npu-smi info command on the server where the AI processor is installed to obtain Chip Name. The actual value is AscendChip Name. For example, if Chip Name is xxxyy, the actual value is Ascendxxxyy.
    • For the Atlas A3 products: Run the npu-smi info -t board -i id -c chip_id command on the server where AI processor is installed to obtain the Chip Name and NPU Name information. The actual value is Chip Name_NPU Name. For example, if the value of Chip Name is Ascendxxx and the value of NPU Name is 1234, the actual value is Ascendxxx_1234.

      Note that:

      • id: device ID, which is the NPU ID obtained by running the npu-smi info -l command.
      • chip_id: chip ID, which is obtained by running the npu-smi info -m command.
  • INPUT_FORMAT: (optional) input format. The value can be "NCHW", "NHWC", or "ND".
  • INPUT_FP16_NODES: (optional) name of the input node whose input data type is float16.
  • CONFIG_FILE: (optional) path to the configuration file for advanced options. For the configuration file example, see Simplified Quantization Configuration File.
  • LOG_LEVEL: (optional) level of logs printed in PTQ. The default log level is info.
    • debug: Outputs debug, info, warning, error, and event logs.
    • info: Outputs info, warning, error, and event logs.
    • warning: Outputs warning, error, and event logs.
    • error: Outputs error and event logs.
    In addition, the AMCT_LOG_DUMP environment variable controls the log flushing information in PTQ.
    • export AMCT_LOG_DUMP=1: Flushes logs to the amct_log_{timestamp}/amct_acl.log file in the current path and does not save the quantization factor record file and graph file.
    • export AMCT_LOG_DUMP=2: Flushes logs to the amct_log_{timestamp}/amct_acl.log file in the current path and saves the quantization factor record file under the amct_log_{timestamp} directory.
    • export AMCT_LOG_DUMP=3: Flushes logs to the amct_log_{timestamp}/amct_acl.log file in the current path and saves the quantization factor record file and the graph file that contains graph description information of each stage during quantization under the amct_log_{timestamp} directory.

    To prevent the disk from becoming full as log files, record files, and graph files are continuously saved to the disk, clean up these files in a timely manner.

    If the ASCEND_WORK_PATH environment variable is configured, the preceding logs, quantization factor record files, and graph files are stored in the path specified by this environment variable. For example, if ASCEND_WORK_PATH is set to /home/test, the storage path is /home/test/amct_acl/amct_log_{pid}_Timestamp. amct_acl is automatically created during model conversion, and {pid} indicates the process ID.

    NOTE:

    The preceding log files, record files, and graph files will be overwritten when quantization is performed again. You need to save them as required. In addition, the size of the generated log file is related to the number of layers of the model to be quantized. Ensure that the server has sufficient space.

    Take the ResNet-101 model as an example. If the log level is set to INFO, the log file size is about 12 KB, and the size of the intermediate temporary file is about 260 MB. If the log level is set to DEBUG, the log file size is about 390 KB, and the size of the intermediate temporary file is about 430 MB.

  • OUT_NODES: (optional) output node name of a graph.
  • DEVICE_ID: (optional) device ID. The default value is 0.
    • Ascend 950PR&950DT products: This option is supported.
    • Atlas training products: This option is supported.
    • Atlas inference products: This option is supported.
    • Atlas 200I/500 A2 inference products: This option is supported.
    • Atlas A2 products: This option is supported.
    • Atlas A3 products: This option is supported.
  • infer_aicore_num: (optional) number of AI Cores used for PTQ calibration and inference. For details about how to obtain the value, see "C++ APIs > Basic Data Structures and APIs of Graphs > Command-Line Options > Operator and Graph Build > AICORE_NUM" in GE APIs.
  • IP_ADDR: IP address of the server where the neural compute server (NCS) is located.
    • Ascend 950PR&950DT products: This option is not supported.
    • Atlas training products: This option is not supported.
    • Atlas inference products: This option is not supported.
    • Atlas 200I/500 A2 inference products: This option is supported and mandatory in Ascend RC scenarios.
    • Atlas A2 products: This option is not supported.
    • Atlas A3 products: This option is not supported.
  • PORT: port of the server where the NCS is located.
    • Ascend 950PR&950DT products: This option is not supported.
    • Atlas training products: This option is not supported.
    • Atlas inference products: This option is not supported.
    • Atlas 200I/500 A2 inference products: This option is supported and mandatory in Ascend RC scenarios.
    • Atlas A2 products: This option is not supported.
    • Atlas A3 products: This option is not supported.
  • INSERT_OP_CONF: path to the configuration file (including the file name) of the operator to be inserted, for example, the AIPP operator.

    The path to the configuration file (including the file name) can contain letters, digits, underscores (_), hyphens (-), and periods (.). The file name extension is not limited to .cfg, but the file content must be in .prototxt format.

    Example:

    aipp_op {
       aipp_mode:static
       input_format:YUV420SP_U8
       csc_switch:true
       var_reci_chn_0:0.00392157
       var_reci_chn_1:0.00392157
       var_reci_chn_2:0.00392157
    }

Returns

Parameter

Type

Description

-

graphStatus

GRAPH_SUCCESS(0): success.

Other values: failure.

Constraints

  • Quantization is not supported for graphs where quantization operators have already been inserted.
  • For details about the layers that support quantization and their constraints, see Quantifiable Layers and Constraints.
  • When the PTQ calibration function specified in the configuration file is used, only environments with an installed NPU device are supported. You can refer to CANN Software Installation to set up the product environment.
  • In the Atlas 200I/500 A2 inference productsAscend RC scenario, you also need to install the NCS software in the operating environment and configure the key certificate. For details, see AOE (Ascend RC) > Environment Setup in Ascend Optimization Engine (AOE).