aclgrphCalibration

Applicability

Product

Supported or Not

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

Header File/Library File

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

Function Usage

Quantizes a graph. For details about the application scenarios, see Quantization.

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

A key-value mapping table, for the configuration options required for API execution, key indicates the parameter type, and value indicates the parameter value, both of type string. Set them as follows:

  • INPUT_DATA_DIR: (required) path of the .bin file used to compute the 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: (required) shape of the input data. For example, "input_name1:n1,c1,h1,w1;input_name2:n2,c2,h2,w2". Enclose all the nodes in double quotation marks (""), and separate them by semicolons (;). input_name must be the name of a node in the graph.
  • SOC_VERSION: (required) name of the chip used for post-training quantization calibration and inference.

    To query <soc_version>:

    • For the following products: Run the npu-smi info command on the server where Ascend AI Processor is installed to obtain the Name information. The actual value is AscendName. For example, if Name is xxxyy, the actual value is Ascendxxxyy.

      Atlas A2 training products / Atlas A2 inference products

      Atlas 200I/500 A2 inference products

      Atlas inference products

      Atlas training products

    • For the following products: Run the npu-smi info -t board -i id -c chip_id command on the server where Ascend 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.

      Atlas A3 training products / Atlas A3 inference products

  • 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 of the configuration file for configuring advanced options. For details about the example configuration file, see Simplified Quantization Configuration File.
  • LOG_LEVEL: (optional) level of logs printed during post-training quantization. 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 during the post-training quantization process.
    • 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 in 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 the graph description information of each phase during quantization in the amct_log_{timestamp} directory.

    To prevent the drive from being full due to continuous flushing of log files, record files, and graph files, delete 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 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 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.
    • The Atlas training products supports this option.
    • The Atlas inference products supports this option.
    • The Atlas 200I/500 A2 inference products supports this option.
    • The Atlas A2 training products / Atlas A2 inference products supports this option.
    • The Atlas A3 training products / Atlas A3 inference products supports this option.
  • infer_aicore_num (optional): number of AI Cores used for PTQ calibration and inference. For details about the query method, see aclgrphBuildInitialize Configuration Parameters > AICORE_NUM.
  • IP_ADDR: IP address of the server where the Neural Compute Server (NCS) is located.
    • The Atlas training products does not support this option.
    • The Atlas inference products does not support this option.
    • In Ascend RC scenarios, the Atlas 200I/500 A2 inference products supports this option, which is mandatory.
    • The Atlas A2 training products / Atlas A2 inference products does not support this option.
    • The Atlas A3 training products / Atlas A3 inference products does not support this option.
  • PORT: port of the server where the NCS is located.
    • The Atlas training products does not support this option.
    • The Atlas inference products does not support this option.
    • In Ascend RC scenarios, the Atlas 200I/500 A2 inference products supports this option, which is mandatory.
    • The Atlas A2 training products / Atlas A2 inference products does not support this option.
    • The Atlas A3 training products / Atlas A3 inference products does not support this option.
  • INSERT_OP_CONF: sets the configuration file directory (including the file name) of an operator to be inserted, for example, the Aipp operator for data preprocessing.

    The configuration file path (including the file name) can contain letters, digits, underscores (_), hyphens (-), and periods (.). The file name extension is not limited to .cfg, but the content in the configuration file 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
    }

    For details about the configuration file and parameter description, see AIPP.

Returns

Parameter

Type

Description

-

graphStatus

GRAPH_SUCCESS(0): success.

Other values: failure. For details, see ge::graphStatus.

Restrictions

  • Graphs that have been inserted with quantization operators cannot be quantized.
  • Refer to Layers That Support Quantization and Their Restrictions.
  • When the calibration feature in the configuration file is used, only installation scenarios with NPU-equipped devices are supported. For details, refer to CANN Software Installation Guide to set up the product environment.
  • In the Atlas 200I/500 A2 inference products Ascend RC scenario, you also need to install the NCS software in the operating environment and configure the key certificate. For details, see "AOE Tool (Ascend RC) >Environment Setup" in AOE Instructions.