aclgrphCalibration

Description

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

Prototype

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 the specified 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>:

    • Run the npu-smi info command on the server where the Ascend AI Processor is installed to obtain the Chip Name information. The actual value is AscendChip Name. For example, if Chip Name is xxxyy, the actual value is Ascendxxxyy.
  • 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 of the configuration file, see Simplified 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 200/300/500 Inference Product supports this parameter.
    • The Atlas Training Series Product supports this parameter.
  • infer_aicore_num (optional): number of AI Cores used for post-training quantization calibration and inference. You are advised not to set it to any value but the default. The default argument of this option varies according to the SoC version. You can view the default value of aicore_num in the ${INSTALL_DIR}/x86_64-linux/data/platform_config/<soc_version>.ini file as follows:
    [SoCInfo]
    #aicore_num default value, also the allowed maximum.
    ai_core_cnt=xx 

    Replace ${INSTALL_DIR} with the actual CANN component directory. If the Ascend-CANN-Toolkit package is installed as the root user, the CANN component directory is /usr/local/Ascend/ascend-toolkit/latest.

  • IP_ADDR: IP address of the server where the Neural Compute Server (NCS) is located.
    • The Atlas 200/300/500 Inference Product does not support this parameter.
    • The Atlas Training Series Product does not support this parameter.
  • PORT: port of the server where the NCS is located.
    • The Atlas 200/300/500 Inference Product does not support this parameter.
    • The Atlas Training Series Product does not support this parameter.
  • 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

SUCCESS: Graph changed successfully.

Other values: Change failed.

Restrictions