NPURunConfig Parameters

Basic Options

Option

Description

graph_run_mode

Graph run mode. Values are as follows:

  • 0: online inference.
  • 1 (default): training

Example:

config = NPURunConfig(graph_run_mode=1)

session_device_id

Logical ID of a device. Setting this parameter allows you to run different models on multiple devices by executing a single training script.

Generally, you can create sessions for multiple graphs and pass the corresponding argument of session_device_id to the session. This parameter takes precedence over the environment variable ASCEND_DEVICE_ID.

Example:

config0 = NPURunConfig(..., session_device_id=0, ...)
estimator0 = NPUEstimator(..., config=config0, ...)
...
config1 = NPURunConfig(..., session_device_id=1, ...)
estimator1 = NPUEstimator(..., config=config1, ...)
...
config7 = NPURunConfig(..., session_device_id=7, ...)
estimator7 = NPUEstimator(..., config=config7, ...)
...

distribute

ParameterServerStrategy object for distributed training in the PS-Worker architecture.

Example:

config = NPURunConfig(distribute=strategy)

deterministic

Whether to enable deterministic computing. If enabled, the same output is generated if an operator is executed for multiple times with the same hardware and input.

The values are as follows:

  • 0 (default): disables deterministic computing.
  • 1: enables deterministic computing.

By default, deterministic computing does not need to be enabled, because it slows down operator execution and affects performance. If it is disabled, the results of multiple executions may be different. This is generally caused by asynchronous multi-thread executions during operator implementation, which changes the accumulation sequence of floating point numbers.

However, if the execution results of a model are different for multiple times or the precision needs to be tuned, you can enable deterministic computing to assist model debugging and tuning. Note that if you want a completely definite result, you need to set a definite random seed in the training script to ensure that the random numbers generated in the program are also definite.

Example:

config = NPURunConfig(deterministic=1)

Memory Management

Option

Description

memory_config

System memory usage mode. Before creating NPURunConfig, you can instantiate a MemoryConfig class to configure functions. For details about the constructor of the MemoryConfig class, see MemoryConfig Constructor.

external_weight

When multiple models are loaded in a session, if the weights of these models can be reused, you are advised to use this configuration item to externalize the weights of the Const/Constant nodes on the network to implement weight reuse among multiple models and reduce the memory usage of the weights.

  • False (default): The weights are not externalized but are saved in graphs.
  • True: The weights of all Const/Constant nodes on the network are flushed to the disk and are converted to the FileConstant type. The weight file is named in the format of weight_<hash value>.

    If the environment variable ASCEND_WORK_PATH is not configured in the environment, the weight files are flushed to the current execution directory tmp_weight_<pid>_<sessionid>.

    If ASCEND_WORK_PATH is configured in the environment, the weight files are flushed to the ${ASCEND_WORK_PATH}/tmp_weight_<pid>_<sessionid> directory. For details about ASCEND_WORK_PATH, see "Installation" in Environment Variables.

    When the model is uninstalled, the tmp_weight_<pid>_<sessionid> directory is automatically deleted.

Note: This parameter is usually not required. If the model loading environment has limitations on memory, you can flush the weight externally.

Example:
config = NPURunConfig(external_weight=True)

input_fusion_size

Threshold for fusing and copying multiple discrete pieces of user input data during H2D transmission. The unit is byte. The minimum value is 0 byte, the maximum value is 33554432 bytes (32 MB), and the default value is 131072 bytes (128 KB). If:
  • Size of input data ≤ threshold: The data is fused before transferred from the host to the device.
  • Size of input data > threshold or threshold = 0 (function disabled): The data is not fused before transferred from the host to the device.
Assume there are 10 user inputs, including two 100 KB inputs, two 50 KB inputs, and the other inputs greater than 100 KB:
  • input_fusion_size set to 100KB: The preceding four inputs are fused into 300 KB data for transfer. The other six inputs are directly transferred from the host to the device.
  • input_fusion_size set to 0KB: This function is disabled. That is, the data is not fused, and the ten inputs are directly transferred from the host to the device.

Note: This parameter takes effect only for static shape graphs.

Example:

config = NPURunConfig(input_fusion_size=25600)

input_batch_cpy

Whether to enable the batch memory copy function when input data is transferred from the host to the device.
  • True: The batch memory copy function is enabled. This value takes effect only when the number of user inputs is greater than 1.
  • False (default): The batch memory copy function is disabled.
NOTE:
  • This parameter is supported only on the following products:
    • Atlas A3 training products / Atlas A3 inference products
    • Atlas A2 training products / Atlas A2 inference products
  • This parameter improves data transfer performance from the host to the device. It applies to scenarios that require frequent data transfer and have low PCIe bandwidth utilization. Enabling the batch copy function using this parameter can improve bandwidth utilization.
  • If the network initially has only one input, the batch copy function does not take effect even if it is enabled.
  • When both the input_fusion_size parameter (for enabling fusion and copy) and the input_batch_cpy parameter (for enabling batch copy) are configured, the threshold for the fusion and copy function may affect the batch copy function.

    For example, if there are five inputs and four of them are smaller than the threshold for fusion and copy and meet the fusion conditions, these four inputs will be processed using fusion and copy. The remaining input does not meet the input quantity requirement for batch copy and therefore will not be batch-copied.

Example:

config = NPURunConfig(input_batch_cpy=True)

Dynamic Shape

Option

Description

ac_parallel_enable

Whether to allow AI CPU operators and AI Core operators to run in parallel in a dynamic shape graph.

In a dynamic shape graph, when this option is enabled, the system automatically identifies AI CPU operators that can be concurrently executed with the AI Core operators in the graph. Operators of different engines are distributed to different flows to implement parallel execution among multiple engines, improving resource utilization and dynamic shape execution performance.
  • 1: AI CPU operators and AI Core operators are allowed to run in parallel.
  • 0 (default): AI CPU operators are not separately distributed.

Example:

config = NPURunConfig(ac_parallel_enable="1")

compile_dynamic_mode

Whether to generalize all input shapes in the graph.
  • True: All input shapes are generalized to -1. Also, static shape graphs are generalized to dynamic ones.
  • False (default): Input shapes are not generalized.

Example:

config = NPURunConfig(compile_dynamic_mode=True)

all_tensor_not_empty

Whether to remove control nodes for empty tensor checks in the execution graph. In dynamic shape graph scenarios, control nodes are typically inserted to check whether a node is empty to prevent empty tensor nodes from being sent to the device. If you are certain that the graph does not contain empty tensors, you can enable this option to remove these control nodes and improve graph execution performance.
  • True: Removes the control nodes used for empty tensor checks in the execution graph. Set it to True only when you are sure that the graph does not contain empty tensor nodes; otherwise, some operators may fail.
  • False (default): Retains the control nodes used for empty tensor checks in the execution graph.

Example:

config = NPURunConfig(all_tensor_not_empty=True)

Mixed Computing

Option

Description

mix_compile_mode

Mixed computing enable.

  • True: enabled.
  • False (default): disabled (full offload mode)

In full offload mode, all compute operators are offloaded to the device. As a supplement to the full offload mode, mixed computing allows certain operators to be executed online within the frontend framework, improving the Ascend AI Processor's adaptability to TensorFlow.

Example:

config = NPURunConfig(mix_compile_mode=True)

Debugging

Option

Description

enable_exception_dump

Whether to dump data of exception operators.
  • 0: Disables the exception operator data dump function.
  • 1: Enables the common ExceptionDump function to dump the input and output data, tensor description information (such as shape, dtype, and format), and workspace information of exception operators.

    The dump data is stored in the following directories in descending order of priority: NPU_COLLECT_PATH > ASCEND_WORK_PATH > default directory (extra-info in the script execution directory).

  • 2 (default): Enables the LiteExceptionDump function to dump the input and output data, workspace information, and tiling information of exception operators. The exported data is used to analyze AI Core errors. For details about how to collect and locate AI Core errors, see "Typical Faults > AI Core Error Locating" in Troubleshooting.

    The dump data is stored in the following directories in descending order of priority: ASCEND_WORK_PATH > default directory (extra-info/data-dump/<device_id> in the script execution directory).

NOTE:

If the environment variable NPU_COLLECT_PATH is configured, exception operator data is dumped in accordance with mode 1 (common ExceptionDump) regardless of the value of enable_exception_dump, and the dump data is stored in the directory specified by NPU_COLLECT_PATH.

For details about the environment variable, see Environment Variables.

Example:

config = NPURunConfig(enable_exception_dump=1)

op_debug_config

Enable for global memory check.

The value is the path of the .cfg configuration file. Multiple options in the configuration file are separated by commas (,).

  • oom: checks whether memory overwriting occurs in the global memory during operator execution.

    During operator compilation, the .o file (operator binary file) and .json file (operator description file) are retained in the kernel_meta folder in the current execution path, and the following detection logic is added:

    inline __aicore__ void  CheckInvalidAccessOfDDR(xxx) {
        if (access_offset < 0 || access_offset + access_extent > ddr_size) {
            if (read_or_write == 1) {
                trap(0X5A5A0001);
            } else {
                trap(0X5A5A0002);
            }
        }
    }

    You can use dump_cce to view the preceding code in the generated .cce file.

    If memory overwriting occurs during compilation, the error code EZ9999 is reported.

  • dump_cce: Retains the .cce file, .o file, and .json file of the operator in the kernel_meta folder in the current execution path during operator compilation.
  • dump_loc: Retains the .cce file, .o file, and .json file of the operator, as well as the _loc.json file (mapping file of python-cce) in the kernel_meta folder in the current execution path during operator compilation.
  • ccec_O0: Enables the default option -O0 of the CCEC during operator compilation. This option does not perform any optimization based on the debugging information.
  • ccec_g: Enables the -g option of the CCEC during operator compilation. Compared with -O0, this option generates optimization and debugging information.
  • check_flag: Checks whether the pipeline synchronization signals in an operator are valid and consistent during operator execution.

    Retain the .o file and .json file in the generated kernel_meta folder and add the following detection logic during operator compilation:

      set_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID0);
      set_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID1);
      set_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID2);
      set_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID3);
      ....
      pipe_barrier(PIPE_MTE3);
      pipe_barrier(PIPE_MTE2);
      pipe_barrier(PIPE_M);
      pipe_barrier(PIPE_V);
      pipe_barrier(PIPE_MTE1);
      pipe_barrier(PIPE_ALL);
      wait_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID0);
      wait_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID1);
      wait_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID2);
      wait_flag(PIPE_MTE3, PIPE_MTE2, EVENT_ID3);
      ...

    You can use dump_cce to view the preceding code in the generated .cce file.

    During compilation, if a mismatch exists in the pipeline synchronization signals in an operator, a timeout error is reported at the faulty operator. The following is an example of the error message:

    Aicore kernel execute failed, ..., fault kernel_name=Operator name,...
    rtStreamSynchronizeWithTimeout execute failed....

Example:

config = NPURunConfig(op_debug_config="/root/test0.cfg") 

The information about the test0.cfg file is as follows:

op_debug_config = ccec_O0,ccec_g,oom

Restrictions:

During operator compilation, if you want to compile only some instead of all AI Core operators, add the op_debug_list field to the test0.cfg configuration file. By doing so, only the operators specified in the list are built, based on the options configured in op_debug_config. The op_debug_list field has the following requirements:
  • The operator name or operator type can be specified.
  • Operators are separated by commas (,). The operator type is configured in the OpType::typeName format. The operator type and operator name can be configured in a mixed manner.
  • The operator to be compiled must be stored in the configuration file specified by op_debug_config.

The following is an example of the test0.cfg file:

op_debug_config= ccec_g,oom
op_debug_list=GatherV2,opType::ReduceSum

During model compilation, the GatherV2 and ReduceSum operators are compiled based on the ccec_g and oom options.

NOTE:
  • When ccec_O0 and ccec_g are enabled, the size of the operator kernel file (*.o file) increases. In dynamic shape scenarios, all possible scenarios are traversed during operator build, which may cause operator build failures due to large operator kernel files. In this case, do not enable the options of the CCE compiler.

    If the build failure is caused by the large operator kernel file, the following log is displayed:

    message:link error ld.lld: error: InputSection too large for range extension thunk ./kernel_meta_xxxxx.o:(xxxx)
  • The CCEC options ccec_O0 and oom cannot be enabled at the same time. Otherwise, an AI Core error is reported. The following is an example of the error message:
    ...there is an aivec error exception, core id is 49, error code = 0x4 ...
  • If this option is set to dump_cce or dump_loc, you can use debug_dir to specify the path for storing debugging-related process files.
  • When the build options oom, dump_cce, and dump_loc are configured, if the model contains the following MC2 operators, the *.o, *.json, and *.cce files of the operators are not generated in the operator build folder kernel_meta.

    MatMulAllReduce

    MatMulAllReduceAddRmsNorm

    AllGatherMatMul

    MatMulReduceScatter

    AlltoAllAllGatherBatchMatMul

    BatchMatMulReduceScatterAlltoAll

  • If NPU_COLLECT_PATH is configured, the function of checking whether memory overwriting occurs in the global memory cannot be enabled. That is, this option cannot be set to oom. Otherwise, an error is reported when the compiled model file or operator kernel package is used.

debug_dir

Directory of the debug files generated during operator building, including the .o, .json, and .cce files.

The storage priority of the debugging files generated during operator compilation is as follows:

debug_dir > ASCEND_WORK_PATH > default storage path (current script execution path).

For details about the environment variable ASCEND_WORK_PATH, see Environment Variables.

Example:
config = NPURunConfig(debug_dir="/home/test")

export_compile_stat

Whether to generate the operator fusion result file fusion_result.json during graph compilation. The options are as follows:
  • 0: The operator fusion result file is not generated.
  • 1 (default): The operator fusion result file is generated when the program exits normally.
  • 2: The operator fusion result file is generated after graph compilation is complete. That is, if graph compilation is complete but the program is interrupted, the result file is also generated.
The fusion_result.json file records the fusion patterns used during graph compilation. The key fields in the file are described as follows:
  • session_and_graph_id_xx_xx: thread and graph ID of the fusion result.
  • graph_fusion: graph fusion.
  • ub_fusion: UB fusion.
  • match_times: number of times that the fusion pattern is matched during graph build.
  • effect_times: actual number of times that the fusion takes effect.
  • repository_hit_times: number of times that the UB fusion repository is hit.
NOTE:
  • If ASCEND_WORK_PATH is not configured in the environment, the operator fusion result is saved to the fusion_result.json file in the current execution directory. If ASCEND_WORK_PATH is configured, the operator fusion result is saved to the $ASCEND_WORK_PATH/FE/${Process ID}/fusion_result.json file. For details about the environment variable, see Environment Variables.
  • The fusion patterns disabled by fusion_switch_file are not displayed in fusion_result.json.

Example:

config = NPURunConfig(export_compile_stat=1)

Accuracy Tuning

Option

Description

precision_mode_v2

Operator precision mode, which must be of the string type.

  • fp16

    Indicates that float16 is forcibly selected if the operator precision in the original graph is float16, bfloat16, or float32.

  • origin
    Retains the original precision.
    • If the precision of an operator in the original graph is float16, and the implementation of the operator in the AI Core does not support float16 but supports only float32 and bfloat16, the system automatically uses high-precision float32.
    • If the precision of an operator in the original graph is float16, and the implementation of the operator in the AI Core does not support float16 but supports only bfloat16, the AI CPU operator of float16 is used. If the AI CPU operator is not supported, an error is reported.
    • If the precision of an operator in the original graph is float32, and the implementation of the operator in the AI Core does not support float32 but supports only float16, the AI CPU operator of float32 is used. If the AI CPU operator is not supported, an error is reported.
  • cube_fp16in_fp32out
    The system selects a processing mode based on the operator type for AI Core operators supporting both float32 and float16.
    • For cube operators, the system processes the computation based on the operator implementation.
      1. The preferred input data type is float16 and the output data type is float32.
      2. If the float16 input data and float32 output data types are not supported, set both the input and output data types to float32.
      3. If the float32 input and output data types are not supported, set both the input and output data types to float16.
      4. If the float16 input and output data types are not supported, an error is reported.
    • For vector compute operators, the operator precision in the original graph is float16 or bfloat16, and float32 is forcibly selected.

      This option is invalid if the original graph contains operators not supporting float32 in the AI Core, for example, an operator that supports only float16. In this case, float16 is retained. If the operator in the AI Core does not support float32 and it is configured to the blocklist of precision reduction (by setting precision_reduce to false), the counterpart AI CPU operator supporting float32 is used. If the AI CPU operator does not support float32, an error is reported.

  • mixed_float16

    Mixed precision of float16, bfloat16, and float32 is used for neural network processing. For float32 and befloat16 operators in the original graph, float16 is automatically used for certain float32 and bfloat16 operators based on the built-in tuning policy. This will improve system performance and reduce memory usage with minimal precision degradation.

    Use the mixed precision mode in conjunction with loss scaling to compensate for the accuracy degradation caused by precision reduction.

  • mixed_bfloat16

    Mixed precision of bfloat16 and float32 is used for neural network processing. In this mode, bfloat16 is automatically used for certain float32 operators in the original graph based on the built-in tuning policy. This will improve system performance and reduce memory usage with minimal precision degradation. If the operators do not support bfloat16 and float32, the AI CPU operators are used for computation. If AI CPU operators also do not support float16 and float32, an error is reported during execution.

    Note: This configuration is supported only by Atlas A3 training products / Atlas A3 inference products Atlas A2 training products / Atlas A2 inference products .

In training scenarios:
  • For Atlas A3 training products / Atlas A3 inference products , the default value is origin.
  • For Atlas A2 training products / Atlas A2 inference products , the default value is origin.
  • For Atlas training products , this parameter does not have a default value. The default value of the precision_mode parameter is used, that is, allow_fp32_to_fp16.

In online inference scenarios, the default value is fp16.

Example:

config = NPURunConfig(precision_mode_v2="origin")
NOTE:
  • This option cannot be used together with precision_mode. precision_mode_v2 is recommended.
  • This option can be used to set the global precision mode of a network, but it may result in performance or precision issues on particular operators. In this case, you are advised to call keep_dtype_scope to keep the precision of some operators unchanged.
  • For details about the built-in tuning policy of each operator in mixed precision mode, see the description of modify_mixlist.
  • The bfloat16 data type does not support the following products:
    • Atlas training products
    • Atlas inference products

precision_mode

Operator precision mode, which must be of the string type.

  • allow_fp32_to_fp16
    • For matrix operators:
      • If the operator precision in the original graph is float32, the precision is preferably reduced to float16. If the operator in the AI Core does not support float16, float32 is used. If the operator in the AI Core does not support float32, the AI CPU operator is used for computation. If the AI CPU operator also does not support float32, an error is reported during execution.
      • If the operator precision in the original graph is bfloat16, the precision of the original graph is preferably used. If the operator in the AI Core does not support bfloat16, float32 is used. If the operator in the AI Core does not support float32, the precision is directly reduced to float16. If the operator in the AI Core does not support float16, the AI CPU operator is used for computation. If the AI CPU operator also does not support float16, an error is reported during execution.
    • For vector operators, the precision of the original graph is retained preferably.
      • If the operator precision in the original graph is float32, the precision of the original graph is preferably used. If the operator in the AI Core does not support float32, the precision is directly reduced to float16. If the operator in the AI Core does not support float16, the AI CPU operator is used for computation. If the AI CPU operator also does not support float16, an error is reported during execution.
      • If the operator precision in the original graph is bfloat16, the precision of the original graph is preferably used. If the operator in the AI Core does not support bfloat16, float32 is used. If the operator in the AI Core does not support float32, the precision is directly reduced to float16. If the operator in the AI Core does not support float16, the AI CPU operator is used for computation. If the AI CPU operator also does not support float16, an error is reported during execution.
  • force_fp16

    Forces float16 for operators supporting float16, bfloat16, and float32. This parameter applies only to online inference scenarios.

  • force_fp32/cube_fp16in_fp32out
    force_fp32 and cube_fp16in_fp32out have the same effect. This option indicates that the system selects different processing modes based on the operator type when the operator in the AI Core supports both the float32 and float16 data types. cube_fp16in_fp32out is newly added to the new version. For cube operators, this option has clearer semantics.
    • For cube operators, the system processes the computation based on the operator implementation.
      1. The preferred input data type is float16 and the output data type is float32.
      2. If the float16 input data and float32 output data types are not supported, set both the input and output data types to float32.
      3. If the float32 input and output data types are not supported, set both the input and output data types to float16.
      4. If the float16 input and output data types are not supported, an error is reported.
    • For vector compute operators, the operator precision in the original graph is float16 or bfloat16, and float32 is forcibly selected.

      This option is invalid if the original graph contains operators not supporting float32 in the AI Core, for example, an operator that supports only float16. In this case, float16 is retained. If the operator in the AI Core does not support float32 and it is configured to the blocklist of precision reduction (by setting precision_reduce to false), the counterpart AI CPU operator supporting float32 is used. If the AI CPU operator does not support float32, an error is reported.

  • must_keep_origin_dtype
    Retains the original precision.
    • If the precision of an operator in the original graph is float16, and the implementation of the operator in the AI Core does not support float16 but supports only float32 and bfloat16, the system automatically uses high-precision float32.
    • If the precision of an operator in the original graph is float16, and the implementation of the operator in the AI Core does not support float16 but supports only bfloat16, the AI CPU operator of float16 is used. If the AI CPU operator is not supported, an error is reported.
    • If the precision of an operator in the original graph is float32, and the implementation of the operator in the AI Core does not support float32 but supports only float16, the AI CPU operator of float32 is used. If the AI CPU operator is not supported, an error is reported.
  • allow_mix_precision_fp16/allow_mix_precision

    allow_mix_precision has the same effect as that of allow_mix_precision_fp16, indicating that mixed precision of float16, bfloat16, and float32 is used for neural network processing. allow_mix_precision_fp16 is newly added to the new version, which has clearer semantics for easy understanding.

    For float32 and befloat16 operators in the original model, float16 is automatically used for certain float32 and bfloat16 operators based on the built-in tuning policy. This will improve system performance and reduce memory usage with minimal precision degradation.

  • allow_mix_precision_bf16

    Mixed precision of bfloat16 and float32 is used for neural network processing. In this mode, bfloat16 is automatically used for certain float32 operators on the original model based on the built-in tuning policy. This will improve system performance and reduce memory usage with minimal precision degradation. If the operator in the AI Core does not support bfloat16 and float32, the AI CPU operator is used for computation. If AI CPU operator also does not support bfloat16 and float32, an error is reported during execution.

    Note: This configuration is supported only by Atlas A3 training products / Atlas A3 inference products Atlas A2 training products / Atlas A2 inference products .

  • allow_fp32_to_bf16
    • If the operator precision in the original graph is float32, the precision of the original graph is preferably used. If the operator in the AI Core does not support float32, the precision is reduced to bfloat16. If the operator in the AI Core does not support bfloat16, the AI CPU operator is used for computation. If the AI CPU operator also does not support bfloat16, an error is reported during execution.
    • If the operator precision in the original graph is bfloat16, the precision of the original graph is preferably used. If the operator in the AI Core does not support bfloat16, float32 is used. If the operator in the AI Core does not support float32, the AI CPU operator is used for computation. If the AI CPU operator also does not support float32, an error is reported during execution.

    Note: This configuration is supported by Atlas A3 training products / Atlas A3 inference products Atlas A2 training products / Atlas A2 inference products .

For the Atlas A3 training products / Atlas A3 inference products , the default value is must_keep_origin_dtype.

For the Atlas A2 training products / Atlas A2 inference products , the default value is must_keep_origin_dtype.

For the Atlas training products , the default value is allow_fp32_to_fp16.

Example:

config = NPURunConfig(precision_mode="allow_mix_precision")
NOTE:
  • This option cannot be used together with precision_mode_v2. precision_mode_v2 is recommended.
  • This parameter can be used to set the global precision mode of a network, but it may result in performance or precision problems on particular operators. In this case, you are advised to call keep_dtype_scope to keep the precision of some operators unchanged.

modify_mixlist

When mixed precision is enabled, you can use this parameter to specify the path and file name of the blocklist, trustlist, and graylist, and specify the operators that allow precision reduction and those that do not allow precision reduction.

You can enable the mixed precision by configuring precision_mode_v2 (recommended) or precision_mode in the script.

The blocklist, trustlist, and graylist storage files are in JSON format. A configuration example is as follows:
config = NPURunConfig(modify_mixlist="/home/test/ops_info.json")

You can specify the operator types in ops_info.json as shown below. Separate operators with commas (,).

{
  "black-list": {                  // Blocklist
     "to-remove": [                // Move an operator from the blocklist to the graylist.
     "Xlog1py"
     ],
     "to-add": [                   // Move an operator from the trustlist or graylist to the blocklist.
     "MatMul",
     "Cast"
     ]
  },
  "white-list": {                  // Trustlist
     "to-remove": [                // Move an operator from the trustlist to the graylist.
     "Conv2D"
     ],
     "to-add": [                   // Move an operator from the blocklist or graylist to the trustlist.
     "Bias"
     ]
  }
}

Note: The operators in the preceding example configuration file are for reference only. The configuration should be based on the actual hardware environment and the built-in tuning policies of the operators.

You can query the built-in tuning policy of each operator in mixed precision mode in CANN software installation directory/opp/built-in/op_impl/ai_core/tbe/config/<soc_version>/aic-<soc_version>-ops-info-<opType>.json. Example:

"Conv2D":{
    "precision_reduce":{
        "flag":"true"
},
...
}
  • true (trustlist): The precision of operators on the trustlist can be reduced in mixed precision mode.
  • false (blocklist): The precision of operators on the blocklist cannot be reduced in mixed precision mode.
  • Not specified (graylist): Follows the same mixed precision processing as the upstream operator.

enable_reduce_precision

Not supported in the current version.

customize_dtypes

If precision_mode_v2 or precision_mode is used to set the global precision mode of a network, precision problems may occur on particular operators. In this case, you can use customize_dtypes to configure the precision mode of these operators, and still compile other operators using the precision mode specified by precision_mode_v2 or precision_mode. Note if precision_mode_v2 is set to origin or precision_mode is set to must_keep_origin_dtype, customize_dtypes does not take effect.

Set it to the path (including the name of the configuration file), for example, /home/test/customize_dtypes.cfg.

Example:

config = NPURunConfig(customize_dtypes="/home/test/customize_dtypes.cfg")

List the names or types of operators whose precision needs customization in the configuration file. Each operator occupies a line, and the operator type must be defined based on Ascend IR. If both operator name and type are configured for an operator, the operator name applies during building.

The structure of the configuration file is as follows:

# By operator name
Opname1::InputDtype:dtype1,dtype2,...OutputDtype:dtype1,...
Opname2::InputDtype:dtype1,dtype2,...OutputDtype:dtype1,...
# By operator type
OpType::TypeName1:InputDtype:dtype1,dtype2,...OutputDtype:dtype1,...
OpType::TypeName2:InputDtype:dtype1,dtype2,...OutputDtype:dtype1,...

Example:

# By operator name
resnet_v1_50/block1/unit_3/bottleneck_v1/Relu::InputDtype:float16,int8,OutputDtype:float16,int8
# By operator type
OpType::Relu:InputDtype:float16,int8,OutputDtype:float16,int8
NOTE:
  • You can find the operator precisions supported in the operator information library, which is saved in opp/built-in/op_impl/ai_core/tbe/config/<soc_version>/aic-<soc_version>-ops-info-<opType>.json under the CANN component directory by default.
  • The data type specified by this parameter takes high priority, which may invite accuracy or performance degradation. If the specified data type is not supported, the compilation will fail.
  • If the configuration is performed based on the operator name, the operator name may change due to operations such as fusion and splitting during model compilation. As a result, the configuration does not take effect and the accuracy is not improved. In this case, you need to obtain logs to locate the fault. For details about the logs, see Log Reference.

Accuracy Comparison

Option

Description

dump_config

Dump configuration. Before creating NPURunConfig, you can instantiate a DumpConfig class for dump configuration. For details about the constructor of the DumpConfig class, see DumpConfig Constructor.

Example:

config = NPURunConfig(dump_config=dump_config)

quant_dumpable

If the TensorFlow network is quantized by the AMCT tool, this option can be used to specify whether to collect the dump data before quantization. The default value is 0.
  • 0: disabled. The input and output before quantization may be optimized during graph compilation. In this case, the dump data before quantization cannot be obtained.
  • 1: enabled. The dump data before quantization can be collected.

Example:

config = NPURunConfig(quant_dumpable="1")
NOTE:

This option applies only to online inference scenarios.

When data dump is enabled, you can set this option to 1 to ensure that the dump data before quantization can be collected.

fusion_switch_file

Directory of the fusion switch configuration file, including the file name.

The value can contain letters, digits, underscores (_), hyphens (-), and periods (.).

The built-in graph fusion and UB fusion patterns are enabled by default. You can disable selected fusion patterns in the configuration file as needed. For details about fusion patterns that can be disabled, see Graph Fusion and UB Fusion Patterns.

Example:
config = NPURunConfig(fusion_switch_file="/home/test/fusion_switch.cfg")

The following is a template of the fusion_switch.cfg configuration file. on indicates that a fusion pattern is enabled, and off indicates that a fusion pattern is disabled.

{
    "Switch":{
        "GraphFusion":{
            "RequantFusionPass":"on",
            "ConvToFullyConnectionFusionPass":"off",
            "SoftmaxFusionPass":"on",
            "NotRequantFusionPass":"on",
            "ConvConcatFusionPass":"on",
            "MatMulBiasAddFusionPass":"on",
            "PoolingFusionPass":"on",
            "ZConcatv2dFusionPass":"on",
            "ZConcatExt2FusionPass":"on",
            "TfMergeSubFusionPass":"on"
        },
        "UBFusion":{
            "TbePool2dQuantFusionPass":"on"
        }
    }
}

To disable all fusion patterns at a time, refer to this configuration file example.

{
    "Switch":{
        "GraphFusion":{
            "ALL":"off"
        },
        "UBFusion":{
            "ALL":"off"
         }
    }
}

Notes:

  1. Some built-in fusion patterns are not switchable due to functionality restrictions and these fusion patterns will remain enabled despite user's switch settings.
  2. To disable all fusion patterns except selected ones, refer to the following example.
    {
        "Switch":{
            "GraphFusion":{
                "ALL":"off",
                "SoftmaxFusionPass":"on"
            },
            "UBFusion":{
                "ALL":"off",
                "TbePool2dQuantFusionPass":"on"
            }
        }
    }

buffer_optimize

Enables buffer optimization. This is an advanced switch.

  • l2_optimize (default): enabled
  • off_optimize: disabled.

Example:

config = NPURunConfig(buffer_optimize="l2_optimize")

Performance Tuning

  • Basic configuration

    Option

    Description

    iterations_per_loop

    Number of iterations per training loop performed on the Ascend AI Processor per sess.run() call. Defaults to 1. The total number of training iterations per loop must be an integer multiple of the value of iterations_per_loop. Training is performed according to the specified number of iterations per loop (iterations_per_loop) on Ascend AI Processor and then the result is returned to the host. This parameter can save unnecessary interactions between the host and device and reduce the training time consumption.

    In mixed compute mode (with mix_compile_mode set to True), iterations_per_loop must be set to 1.

    Note: When iterations_per_loop is set to a value greater than 1, the total number of training iterations set by the user may be different from the actual total number of iterations due to issues such as loop offload and loss scale overflow.

    Example:

    config = NPURunConfig(iterations_per_loop=1000)
  • Advanced configuration

    Option

    Description

    hcom_parallel

    Whether to enable AllReduce gradient update and forward and backward propagation in parallel during distributed training.

    • True (default): enabled.
    • False: disabled.

    For a small network (for example, ResNet-18), you are advised to set this parameter to False.

    Example:

    config = NPURunConfig(hcom_parallel=True)

    op_precision_mode

    High-precision or high-performance mode of an operator. You can pass a custom mode configuration file op_precision.ini to set different modes for operators.

    You can set this option by operator type (low priority) or node name (high priority). Example:
    [ByOpType]
    optype1=high_precision
    optype2=high_performance
    optype3=enable_hi_float_32_execution
    optype4=support_out_of_bound_index
    [ByNodeName]
    nodename1=high_precision
    nodename2=high_performance
    nodename3=enable_hi_float_32_execution
    nodename4=support_out_of_bound_index
    • high_precision: high precision.
    • high_performance: high performance.
    • enable_float_32_execution: The FP32 data type is used for internal processing of operators. In this scenario, the FP32 data type is not automatically converted to the HF32 data type. If you are using the HF32 data type for computation and find that the accuracy drop exceeds your expectation, enable this option to specify the use of FP32 for internal computation of certain operators in order to maintain accuracy.

      This option is supported only by the following products:

      Atlas A3 training products / Atlas A3 inference products

      Atlas A2 training products / Atlas A2 inference products

    • enable_hi_float_32_execution: The HF32 data type is used for internal processing of operators. After this option is enabled, the FP32 data type is automatically converted to the HF32 data type. This configuration can reduce the space occupied by data and improve performance. This option is not supported in the current version.
    • support_out_of_bound_index: The out-of-bounds verification is performed on the indices of the gather, scatter, and segment operators. The verification deteriorates the operator execution performance.
    • keep_fp16: The FP16 data type is used for internal operator processing. In this mode, FP16 is not automatically converted to FP32. If FP32 computation fails to meet performance expectations and high accuracy is not required, you can enable the keep_fp16 mode. This low-precision mode trades accuracy for performance and is not recommended.
    • super_performance: ultra-high performance. Compared with high performance, the algorithm calculation formula is optimized.

    You can view the supported precision and performance mode values for a specific operator in the opp/built-in/op_impl/ai_core/tbe/impl_mode/all_ops_impl_mode.ini file under the CANN software installation directory.

    This parameter is mutually exclusive with op_select_implmode and optypelist_for_implmode. If they are all specified, op_precision_mode takes precedence.

    Generally, you do not need to set this parameter. It is used if you need to adjust the precision of a specific operator using the configuration .ini file in the case that you fail to obtain optimal network performance or accuracy in the high-performance or high-precision mode.

    Example:

    config = NPURunConfig(op_precision_mode="/home/test/op_precision.ini")

    enable_scope_fusion_passes

    Scope fusion pattern (or scope fusion patterns separated by commas) to take effect during build. Name of the registered fusion pattern. You can pass multiple names. Separate the names by commas (,).

    Scope fusion patterns (either built-in or custom) are classified into the following two types:

    • General: common scope fusion patterns applicable to all networks. They are enabled by default and cannot be manually invalidated.
    • Non-general scope fusion patterns: applicable to specific networks. By default, they are disabled. You can use enable_scope_fusion_passes to enable selected fusion patterns.

    Example:

    config = NPURunConfig(enable_scope_fusion_passes="ScopeLayerNormPass,ScopeClipBoxesPass")

    stream_max_parallel_num

    This parameter applies only to NMT networks.

    It specifies the degree of parallelism of AI CPU and AI Core engines for parallel execution of AI CPU and AI Core operators.

    Example:

    config = NPURunConfig(stream_max_parallel_num="DNN_VM_AICPU:10,AIcoreEngine:1")

    DNN_VM_AICPU is the name of the AI CPU engine. In this example, the number of concurrent tasks on the AI CPU engine is 10.

    AIcoreEngine is the name of the AI Core engine. In this example, the number of concurrent tasks on the AI Core engine is 1.

    Defaults to 1. The value cannot exceed the maximum number of AI Cores.

    is_tailing_optimization

    This parameter applies only to BERT networks.

    Enabling communication tailing optimization in distributed training scenarios improves performance. By changing a computation dependency relationship, a computation operation that does not depend on the last AR (gradient aggregation fragment) is scheduled to be performed in parallel with the last AR, to optimize communication tailing. Value:

    • True: enabled.
    • False (default): disabled.

    This parameter must be used in pair with NPUOptimizer Constructor and the value must be the same as that of is_tailing_optimization in NPUOptimizer Constructor.

    Example:

    config = NPURunConfig(is_tailing_optimization=True)

    enable_small_channel

    Small channel optimization enable. If it is enabled, performance benefits are yielded at the convolutional layers with channel size <= 4.
    • 0: disabled. This function is disabled by default in the training scenario (graph_run_mode is 1). You are advised not to enable this function in the training scenario.
    • 1 (default): enabled. This option cannot be modified in online inference scenarios (graph_run_mode is 0).
    NOTE:

    After this function is included, performance benefits can be obtained on the ResNet50, ResNet101, and ResNet152 networks. For other network models, the performance may deteriorate.

    Example:

    config = NPURunConfig(enable_small_channel=0)

    variable_placement

    If the network weight is large, network execution may fail due to insufficient device memory. In this case, you can deploy the variable to the host to reduce the memory usage of the device.

    • Device: The variable is deployed on the device.
    • Host: The variable is deployed on the host.

    Default value: Device

    Constraints:
    1. If this configuration option is set to Host, mixed computing must be enabled (mix_compile_mode = True).
    2. If the training script contains APIs of TensorFlow V1 control flow operators, such as tf.case, tf.cond, and tf.while_loop, setting variable_placement to Host may cause the network execution to fail. To avoid this problem, add the following APIs to the training script to convert the control flow operators of TensorFlow V1 to V2 and enable resource variables:
      tf.enable_control_flow_v2()
      tf.enable_resource_variables()

    Example:

    config = NPURunConfig(variable_placement="Device")

    graph_max_parallel_model_num

    In online inference scenarios, you can set this option to specify the maximum number of threads for parallel graph execution. If the value of this option is greater than 1, the corresponding number of threads are started for parallel graph execution, improving the overall graph pipeline efficiency.

    The value must be an integer in the range of [1, INT32_MAX]. The default value is 1. INT32_MAX is the maximum value of the INT32 type, which is 2147483647.

    Example:

    config = NPURunConfig(graph_max_parallel_model_num=4)

Profiling

Option

Description

profiling_config

Profiling configuration. Before creating NPURunConfig, you can instantiate a ProfilingConfig class for profiling configuration. For details about the constructor of the ProfilingConfig class, see ProfilingConfig Constructor.

Example:

config = NPURunConfig(profiling_config=profiling_config)

AOE

The AOE tuning feature supports only the following products:

  • Atlas A3 training products / Atlas A3 inference products
  • Atlas A2 training products / Atlas A2 inference products
  • Atlas training products

Option

Description

aoe_mode

Tuning mode of AOE.

  • 1: subgraph tuning.
  • 2: operator tuning.
  • 4: gradient splitting tuning.

    In the data parallel scenario, AllReduce is used to aggregate gradients. The gradient splitting mode is closely related to the distributed training performance. If the splitting is improper, the communication hangover time is long after the backward propagation is complete, affecting the cluster training performance and linearity. It is sophisticated to perform manual tuning through the gradient splitting API (set_split_strategy_by_idx or set_split_strategy_by_size) of collective communication. AOE collects profile data in the real-device environment and automatically looks up for the optimal splitting strategy. You only need to set the obtained policy to your network by passing it to the set_split_strategy_by_idx call.

NOTE:
  • The tuning mode can be configured by modifying the training script or the AOE_MODE environment variable. If both configuration methods are used, the configuration by modifying the training script takes precedence.
  • For the Atlas A2 training products / Atlas A2 inference products , subgraph tuning is not supported.
  • For the Atlas A2 training products / Atlas A2 inference products , subgraph tuning is not supported.

Example:

config = NPURunConfig(aoe_mode="2")

work_path

Working directory of AOE, which stores the configuration and tuning result files. By default, the files are generated in the current directory.

The value is a string. Create the specified directory in advance in the environment (either container or host) where training is performed. The running user configured during installation must have the read and write permissions on this directory. The value can be an absolute path or a path relative to the path where the training script is executed.

  • An absolute path starts with a slash (/), for example, /home/test/output.
  • A relative path starts with a directory name, for example, output.

Example:

config = NPURunConfig(work_path="/home/test/output")

aoe_config_file

Tunes only operators with low performance on the network with AOE. Set this parameter to the path and name of the configuration file that contains the operator information, for example, /home/test/cfg/tuning_config.cfg.

Example:

config = NPURunConfig(aoe_config_file="/home/test/cfg/tuning_config.cfg")

The configuration file contains information about the operators to be tuned. The file content format is as follows:

{
       "tune_ops_name":["bert/embeddings/addbert/embeddings/add_1","loss/MatMul"],
       "tune_ops_type":["Add", "Mul"],
       "tune_optimization_level":"O1",
       "feature":["deeper_opat"]
}
  • tune_ops_name: name of the specified operator (whole word match). You can specify one or more operator names. If multiple operator names are specified, separate them with commas (,). The operator name must be the node name of the network model processed by Graph Compiler. You can obtain the operator name from profiling tuning data. For details, see Profiling Instructions.
  • tune_ops_type: specified operator type (whole word match). You can specify one or more operator types. If multiple operator types are specified, separate them with commas (,). If a fused operator contains the specified operator type, the fused operator will also be tuned.
  • tune_optimization_level: tuning mode. The value O1 indicates the high-performance tuning mode, and the value O2 indicates the normal mode. The default value is O2.
  • feature: tuning feature switch. The value can be deeper_opat or nonhomo_split. The value deeper_opat indicates that in-depth operator tuning is enabled. In this case, aoe_mode must be set to 2. The value nonhomo_split indicates that non-uniform subgraph partition tuning is enabled. In this case, aoe_mode must be set to 1.
NOTE:

In the preceding configuration file, tune_ops_type and tune_ops_name can exist at the same time or one of them. If they exist at the same time, use the union set.

Operator Building

Option

Description

op_compiler_cache_mode

Disk cache mode for operator building. enable is the default value.

  • enable: disk cache mode enabled. The operator build information is cached to the disk, which can be reused by operators with the same build parameters, improving build efficiency.
  • force: cache mode enabled. This mode deletes the existing cache, then recompiles the operators and adds them to the cache. For example, for Python changes, dependency library changes, or repository changes after operator optimization, you need to set this option to force to clean up the existing cache and then change it to enable to prevent the cache from being forcibly refreshed during each build. Note that you are not advised to set the force option for parallel program compilation. Otherwise, the cache used by other models may be cleaned up, causing compilation failures.
  • disable: disabled.

Notes:

  • When enabling the operator compilation cache function, you can configure the path for storing the operator compilation cache file by using op_compiler_cache_dir.
  • disable and force are recommended for publishing the final model.
  • If op_debug_level is set to a non-zero value, the op_compiler_cache_mode configuration is ignored, the operator compilation cache function is disabled, and all operators are recompiled.
  • If op_debug_config is not empty and the op_debug_list field is not configured, the op_compiler_cache_mode configuration is ignored, the operator compilation cache function is disabled, and all operators are recompiled.
  • If op_debug_config is not empty, the op_debug_list field is configured, and op_compiler_cache_mode is set to enable or force, the operators in the list are recompiled, and the operator compilation cache function is enabled for operators that are not in the list. However, operators that are not in the list will not be recompiled.
  • When the operator compilation cache function is enabled, the default disk space allocated for cache files is 500 MB. If disk space becomes insufficient, cache files are deleted and 50% of the cache space is reserved by default. You can also customize the disk space allocated for cache files and the percentage of cache space to retain as follows:
    1. Using the op_cache.ini configuration file

      After the operator is compiled, the op_cache.ini file is automatically generated in the directory specified by op_compiler_cache_dir. You can use this file to set the disk space allocated for cache files and the percentage of cache space to retain. If the op_cache.ini file does not exist, manually create it.

      Add the following information to the op_cache.ini file:

      # Configure the file format (required). The automatically generated file contains the following information by default. When manually creating a file, enter the following information:
      [op_compiler_cache]
      # Limit the disk space of the cache folder on the Ascend AI Processor (unit: MB).
      max_op_cache_size=500
      # When the disk space is insufficient, set the percentage of cache files to retain. Value range: [1, 100] (%). For example, setting it to 80 means that when disk space becomes insufficient, 80% of the cache files will be retained and the rest will be deleted.
      remain_cache_size_ratio=80
      • The op_cache.ini file takes effect only when the values of max_op_cache_size and remain_cache_size_ratio in the preceding file are valid.
      • When the size of the compilation cache file exceeds the configured value of max_op_cache_size and the cache file has not been accessed for more than half an hour, the cache file will be aged out. (Operator compilation will not be interrupted if the cache file size exceeds the limit. Therefore, if max_op_cache_size is set too small, the actual compilation cache file size may exceed the configured value.)
      • To disable the compilation cache aging function, set max_op_cache_size to -1. In this case, the access time is not updated when the operator cache is accessed, the operator compilation cache is not aged, and the default disk space of 500 MB is used.
      • If multiple users use the same cache path, the configuration file affects all users.
    2. Using environment variable ASCEND_MAX_OP_CACHE_SIZE

      You can use the environment variable ASCEND_MAX_OP_CACHE_SIZE to limit the disk space for cache files under an Ascend AI Processor. When the compilation cache space reaches the value set by ASCEND_MAX_OP_CACHE_SIZE and a cache file has not been accessed for more than half an hour, the cache file will be aged out. ASCEND_REMAIN_CACHE_SIZE_RATIO can be used to set the percentage of cache space to retain. For details about environment variables, see "Operator Building" in Environment Variables.

      To disable the compilation cache aging function, set ASCEND_MAX_OP_CACHE_SIZE to -1.

    If both the op_cache.ini file and environment variables are configured, the configuration items in op_cache.ini take precedence. If neither is configured, the system uses the default values: 500 MB of disk space for the cache, with 50% of the cache space retained.

Example:
config = NPURunConfig(op_compiler_cache_mode="enable")

op_compiler_cache_dir

Disk cache directory for operator compilation.

The value can contain letters, digits, underscores (_), hyphens (-), and periods (.).

If the specified directory exists and is valid, the kernel_cache subdirectory is automatically created. If the specified directory does not exist but is valid, the system automatically creates a directory and the kernel_cache subdirectory.

The storage priority of the operator compilation cache files is as follows:

op_compiler_cache_dir > ${ASCEND_CACHE_PATH}/kernel_cache > Default path ($HOME/atc_data)

For details about ASCEND_CACHE_PATH, see Environment Variables.

Example:
config = NPURunConfig(op_compiler_cache_dir="/home/test/kernel_cache")

aicore_num

Maximum number of Cube cores and Vector cores used for operator compilation.

Format: Integer 1|Integer 2, where the two values are separated by vertical bars (|). Integer 1 specifies the maximum number of Cube cores to use, and Integer 2 specifies the maximum number of Vector cores to use. Both values must be greater than 0 and less than or equal to the actual number of Cube cores and Vector cores available on the Ascend AI Processor.
NOTE:
  • This option is supported by the following products:

    Atlas A3 training products / Atlas A3 inference products

    Atlas A2 training products / Atlas A2 inference products

  • The maximum number of Cube cores and Vector cores for different Ascend AI Processors can be found in the CANN installation directory/<arch>-linux/data/platform_config/<soc_version>.ini file. The following example indicates that there are 24 Cube cores and 48 Vector cores on the Ascend AI Processor.
    [SoCInfo]
    ai_core_cnt=24
    cube_core_cnt=24
    vector_core_cnt=48
  • In static shape scenarios, if an existing operator binary is reused during model compilation (that is, jit_compile set to false), aicore_num does not take effect.

Example:

config = NPURunConfig(aicore_num="2|4")

oo_constant_folding

Enables or disables constant folding.

Constant folding evaluates and replaces constant expressions during graph compilation to reduce memory usage. In most cases, you are advised to retain the default value to enable constant folding. However, some networks require more memory during compilation and running, and the constant memory is occupied throughout the entire lifecycle of a graph. If enabling constant folding increases the overall memory consumption, you can disable it using this parameter.
  • True (default): enables constant folding.

    In this case, a node marked with the _grappler_do_not_remove attribute via TensorFlow's Grappler will not be folded, while other nodes that meet the folding conditions will still be folded.

  • False: disables constant folding.
config = NPURunConfig(oo_constant_folding=True)
NOTE:

If constant folding is disabled and an error occurs during network compilation and running, an error message similar to the following will be displayed:

  • Example 1:

    Error message from the debug log:

    [ERROR] GE(3469659,python3.7):2025-02-25-05:** [ge_deleted_op.cc:21]3470503 Run: ErrorNo: 4294967295(failed) [Delete][Node] Node:HcomAllReduce/input type is ExpandDims, should be deleted by ge.

    This error indicates that the network contains an ExpandDims operator that requires constant folding during graph compilation, meaning that constant folding cannot be disabled.

  • Example 2:
    Screen output with error code EZ3003:
    Error Message is :
    EZ3003: [PID: 3482331] 2025-02-25-14:07:19.774.362 No supported Ops kernel and engine are found for [import/conv2d_1/convolutionimport/batch_normalization_1/FusedBatchNorm_1_filter_host], optype [ConvBnFilterHost].
    Possible Cause: The operator is not supported by the system. Therefore, no hit is found in any operator information library.

    This error indicates that the network contains a ConvBnFilterHost operator that requires constant folding during graph compilation, meaning that constant folding cannot be disabled.

Solution:

Enable constant folding by setting oo_constant_folding to True, and then use the _grappler_do_not_remove attribute via TensorFlow's Grappler to selectively disable constant folding for specific operators.

Data Augmentation

Option

Description

local_rank_id

Rank ID of the current process, used in data parallel processing in recommendation networks. The main process deduplicates the data and distributes the deduplicated data to the devices of other processes for forward and backward propagation.

In this mode, multiple devices on a host share one main process for data preprocessing, leaving other processes to receive preprocessed data from the main process.

To identify the main process, call the collective communication API get_local_rank_id() to get the rank ID of the current process on its server.

Example:

config = NPURunConfig(local_rank_id=0, local_device_list="0,1")

local_device_list

Devices that the main process sends data to, used in conjunction with local_rank_id.

config = NPURunConfig(local_rank_id=0, local_device_list="0,1")

Exception Remedy

Option

Description

hccl_timeout

Synchronization timeout for inter-device task execution, in seconds.

You can set the timeout interval if the default value does not meet your requirement (for example, when a communication failure occurs).

  • For Atlas training products , the value range is (0, 17340], in seconds. The default value is 1836.

    Note: For Atlas training products , actual timeout interval set in the system = (Value of this parameter // 68) × 68 (unit: s). If the parameter value is less than 68, 68s is used by default.

    For example, if hccl_timeout is set to 600, the actual timeout interval set in the system is 544s (600 // 68 × 68 = 8 × 68).

  • For the Atlas 300I Duo inference card, the value range is (0, 17340], in seconds. The default value is 1836.

    Note: For Atlas 300I Duo inference card, actual timeout interval set in the system = (Value of this parameter // 68) × 68 (unit: s). If the parameter value is less than 68, 68s is used by default.

    For example, if hccl_timeout is set to 600, the actual timeout interval set in the system is 544s (600 // 68 × 68 = 8 × 68).

  • For Atlas A2 training products / Atlas A2 inference products , the value range is [0, 2147483647], in seconds. The default value is 1836. The value 0 indicates that the session never times out.
  • For Atlas A3 training products / Atlas A3 inference products , the value range is [0, 2147483647], in seconds. The default value is 1836. The value 0 indicates that the session never times out.
NOTE:

hccl_timeout takes precedence over the environment variable HCCL_EXEC_TIMEOUT. If both are configured, the value of hccl_timeout prevails. For details about HCCL_EXEC_TIMEOUT, see Environment Variables.

Example:

config = NPURunConfig(hccl_timeout=1800)

op_wait_timeout

Operator wait timeout interval (s). Defaults to 120.

Example:

config = NPURunConfig(op_wait_timeout=120)

op_execute_timeout

Operator execution timeout interval (s).

Example:

config = NPURunConfig(op_execute_timeout=90)

stream_sync_timeout

Timeout interval for stream synchronization during graph execution. If the timeout interval exceeds the configured value, a synchronization failure is reported. The unit is ms.

The default value is -1, indicating that there is no waiting time and no error is reported when the synchronization fails.

Note: In cluster scenarios, the value of this option (timeout interval for stream synchronization) must be greater than the collective communication timeout interval, that is, the value of hccl_timeout or the environment variable HCCL_EXEC_TIMEOUT.

Example:

config = NPURunConfig(stream_sync_timeout=60000)

event_sync_timeout

Timeout interval for event synchronization during graph execution. If the timeout interval exceeds the configured value, a synchronization failure is reported. The unit is ms.

The default value is -1, indicating that there is no waiting time and no error is reported when the synchronization fails.

Example:

config = NPURunConfig(event_sync_timeout=60000)

Experiment Parameters

The experiment parameters are extended parameters for debugging and may be changed in later versions. Therefore, they cannot be used in commercial products.

Option

Description

experimental_config

Extended parameter. Currently, this parameter is not recommended. Before creating NPURunConfig, you can instantiate an ExperimentalConfig class to configure functions. For details about the constructor of the ExperimentalConfig class, see ExperimentalConfig Constructor.

jit_compile

Determines whether to compile the operator online or use the compiled operator binary file.

  • auto (default): For a static shape network, compile the operator online. For a dynamic shape network, search for the compiled operator binary file in the system first. If the corresponding binary file is not available, compile the operator.
  • true: Operators are compiled online. The system performs fusion and tuning based on the obtained graph information to get better performing operators.
  • false: The compiled operator binary file in the system is preferentially searched. If the file can be found, operators are not compiled anymore, which produces better compilation performance. If the file cannot be found, operators will be compiled.
NOTICE:

This option is used only for networks of large recommendation models.

Example:

config = NPURunConfig(jit_compile="auto")

shape_generalization_mode

When jit_compile is set to true (online operator compilation), use this parameter to configure the shape generalization mode.
  • STRICT (default): Uses the shape of the current iteration as is, without any generalization.
  • FULL: Generalizes all axes to -1 if the shape changes between iterations.
  • ADAPTIVE: Generalizes only the shape of the changed axis to -1 if the shape changes between iterations.
NOTICE:

If compile_dynamic_mode is set to True, all input shapes are generalized to -1 in the first iteration. In this case, the configuration of shape_generalization_mode does not take effect.

Example:

config = NPURunConfig(shape_generalization_mode="FULL")

auto_multistream_parallel_mode

This option applies only to graphs with a static shape. You can enable parallel execution of Cube and Vector operators to improve graph execution performance.
  • cv: Parallel execution of Cube and Vector operators is enabled.
  • None (default): Parallel execution of Cube and Vector operators is disabled.
NOTICE:
  • This option is used only for recommendation networks.
  • Parallel execution of Cube and Vector operators cannot be enabled at the same time as the multi-stream concurrency function (configured by the ENABLE_DYNAMIC_SHAPE_MULTI_STREAM environment variable).

    For details about the environment variable, see Environment Variables.

Example:
config = NPURunConfig(auto_multistream_parallel_mode="cv")

Parameters That Will Be Deprecated in Later Versions

The following parameters will be deprecated in later versions. You are advised not to use them anymore.

Option

Description

enable_data_pre_proc

Performance tuning.

Enable for the GetNext operator offload to the Ascend AI Processor. The GetNext operator offload is a prerequisite for iteration offload.

  • True (default): enabled. The prerequisite for GetNext operator offload is that the TensorFlow Dataset mode is used to read data.
  • False: disabled.

Example:

config = NPURunConfig(enable_data_pre_proc=True)

variable_format_optimize

Performance tuning.

Variable format optimization enable.

  • True: enabled.
  • False: disabled.

To improve training efficiency, the format of the variables is converted to a format more compatible with the Ascend AI Processor during variable initialization performed by the network. Enable or disable this function as needed.

This parameter is left empty by default, indicating that the configuration is disabled.

Example:

config = NPURunConfig(variable_format_optimize=True)

op_debug_level

Operator debug enable. The values are as follows:

  • 0: disables operator debug.
  • 1: Enables operator debug. TBE instruction mapping files are generated in the kernel_meta directory under the training script execution path, including operator CCE files (.cce), Python-CCE mapping files (_loc.json), .o files, and .json files. These files are used for AI Core error analysis with related tools.
  • 2: Enables operator debug. TBE instruction mapping files are generated in the kernel_meta directory under the training script execution path, including operator CCE files (.cce), Python-CCE mapping files (_loc.json), .o files, and .json files. The compilation optimization of the CCE compiler is disabled and the CCE compiler debugging function is enabled (by setting the compiler option to -O0-g). These files are used for AI Core error analysis with related tools.
  • 3: disables operator debug. The operator .o and .json files are retained in the kernel_meta folder in the training script execution directory.
  • 4: disables operator debug. The operator binary (.o) and operator description file (.json) are retained, and a TBE instruction mapping file (.cce) and a UB fusion description file ({$kernel_name}_compute.json) are generated in the kernel_meta folder under the training script execution directory.
    NOTICE:
    • If this option is set to 0 and op_debug_config is configured, the operator compilation directory kernel_meta is still generated in the current execution path during training. The content generated in the directory is subject to op_debug_config.
    • You are advised to set this option to 0 or 3 for training. To locate AI Core errors, set this parameter to 1 or 2, which might compromise the network performance.
    • If this option is set to 2 (the CCE compiler is enabled), it cannot be used together with the oom option in op_debug_config. Otherwise, an AI Core error is reported. The following is an example of the error message:
      ...there is an aivec error exception, core id is 49, error code = 0x4 ...
    • If this parameter is set to 2 (the CCE compiler is enabled), the size of the operator kernel file (*.o file) increases. In dynamic shape scenarios, all possible scenarios are traversed during operator build, which may cause operator build failures due to large operator kernel files. In this case, 2 is not recommended.

      If the build failure is caused by the large operator kernel file, the following log is displayed:

      message:link error ld.lld: error: InputSection too large for range extension thunk ./kernel_meta_xxxxx.o:(xxxx)
    • If the value of this option is not 0, you can use the debug_dir option to specify the path for storing debugging-related process files.
    • If this option is set to 0 and NPU_COLLECT_PATH is set, the operator compilation directory kernel_meta is generated in the current path after the command is executed. If ASCEND_WORK_PATH is set, kernel_meta is generated in the path specified by the environment variable. For details about the environment variable, see Environment Variables.
    • When the debug function is enabled, if the model contains the following merged compute and communication (MC2) operators, the *.o, *.json, and *.cce files of the operators are not generated in the operator build folder kernel_meta.

      MatMulAllReduce

      MatMulAllReduceAddRmsNorm

      AllGatherMatMul

      MatMulReduceScatter

      AlltoAllAllGatherBatchMatMul

      BatchMatMulReduceScatterAlltoAll

This parameter is left empty by default, indicating that the configuration is disabled.

Example:

config = NPURunConfig(op_debug_level=1)

op_select_implmode

Operator implementation mode. Certain operators built in the Ascend AI Processor can be implemented in either high-precision or high-performance mode at model build time. Arguments:

  • high_precision: high-precision implementation mode. In high-precision mode, Taylor's theorem or Newton's method is used to improve operator precision with float16 input.
  • high_performance (default): high-performance implementation mode. In high-performance mode, the optimal performance is implemented without affecting the network precision (float16).

This parameter is left empty by default, indicating that the configuration is disabled.

Example:
config = NPURunConfig(op_select_implmode="high_precision")

optypelist_for_implmode

List of operator types (separated by commas) that use the mode specified by the op_select_implmode parameter. Currently, Pooling, SoftmaxV2, LRN, and ROIAlign operators are supported.

Use this parameter in conjunction with op_select_implmode, for example:

config = NPURunConfig(
    op_select_implmode="high_precision",
    optypelist_for_implmode="Pooling,SoftmaxV2")

This parameter is left empty by default, indicating that the configuration is disabled.

dynamic_input

Whether it is a dynamic input.

  • True: yes.
  • False (default): no.
Example:
config = NPURunConfig(dynamic_input=True)

dynamic_graph_execute_mode

Execution mode of a dynamic input. That is, this option takes effect when dynamic_input is set to True. Possible values are:

dynamic_execute: dynamic graph compilation. In this mode, the shape range configured in dynamic_inputs_shape_range is used for compilation.

Example:
config = NPURunConfig(dynamic_graph_execute_mode="dynamic_execute")

dynamic_inputs_shape_range

Shape range of each dynamic input. If a graph has two dataset inputs and one placeholder input, a configuration example is as follows.

config = NPURunConfig(dynamic_inputs_shape_range="getnext:[128 ,3~5, 2~128, -1],[64 ,3~5, 2~128, -1];data:[128 ,3~5, 2~128, -1]")

Precautions:

  • getnext indicates the dataset inputs and data indicates the placeholder inputs.
  • The size of a static dimension is specified by a determinant value. The size range of a dynamic dimension is specified by using a tilde (~). A dynamic dimension without size range specified is denoted by –1.
  • Assume that your graph has three dataset inputs but the first dataset input has a static shape; the static shape must be specified as shown below.
    config = NPURunConfig(dynamic_inputs_shape_range="getnext:[3,3,4,10],[-1,3,2~1000,-1],[-1,-1,-1,-1]")
  • For scalar inputs, you also need to fill in the shape range by using square brackets ([]). No space is allowed before the square brackets.
  • If there are multiple getnext inputs or data inputs on the network, the input ordering must be preserved. For example:
    • If there are multiple dataset inputs on the network:
      def func(x):
          x = x + 1
          y = x + 2
          return x,y
      dataset = tf.data.Dataset.range(min_size, max_size)
      dataset = dataset.map(func)

      Assume that the first input of the network is x (with shape range [3~5]) and the second input is y (with shape range [3~6]). When configuring the dynamic ranges in dynamic_inputs_shape_range, the ordering must be preserved.

      config = NPURunConfig(dynamic_inputs_shape_range ="getnext:[3~5],[3~6]")
    • If there are multiple placeholder inputs on the network:

      If the placeholder names are not specified, for example:

      x = tf.placeholder(tf.int32)
      y = tf.placeholder(tf.int32)

      Set the dynamic ranges of the placeholder inputs in dynamic_inputs_shape_range in the same order as that defined in the script. That is, the first input x (with shape range [3~5]) goes first and the second input y (with shape range [3~6]) follows.

      config = NPURunConfig(dynamic_inputs_shape_range= "data:[3~5],[3~6]")

      If the placeholder names are specified, for example:

      x = tf.placeholder(tf.int32, name='b')
      y = tf.placeholder(tf.int32, name='a')

      The inputs are in the alphabetical order of the name fields,

      that is, when setting dynamic_inputs_shape_range, the first input y (with shape range [3~6]) goes first and the second input x (with shape range [3~5]) follows.

      config = NPURunConfig(dynamic_inputs_shape_range = "data:[3~6],[3~5]")
    NOTICE:
    • For subgraphs with different input shapes, set_graph_exec_config is recommended for supporting dynamic inputs. dynamic_inputs_shape_range applies only to a single graph, which may cause execution errors.
    • If the placeholder names are not specified in the network script, the placeholders are named in the following format:

      xxx_0, xxx_1, xxx_2, ......

      The content following the underscore (_) is the sequence index of a placeholder in the network script. Placeholders are arranged in alphabetical order based on these indexes. If the number of placeholders is greater than 10, the sequence is xxx_0 -> xxx_10 -> xxx_2 -> xxx_3. In the network script, the placeholder with index 10 is placed before the placeholder with index 2. As a result, the defined shape range does not match the input placeholder.

      To avoid this problem, when the number of input placeholders is greater than 10, you are advised to specify the placeholder names in the network script. In this case, the placeholders are named based on the specified names to associate the shape ranges with the placeholder names.

    • This option cannot be used together with dynamic_dims. If both are configured, dynamic_dims takes precedence and this option is ignored.

graph_memory_max_size

Sizes of the network static memory and the maximum dynamic memory (used in earlier versions).

In the current version, this parameter does not take effect. The system dynamically allocates memory resources based on the actual memory usage of the network.

variable_memory_max_size

Size of the variable memory (used in earlier versions).

In the current version, this parameter does not take effect. The system dynamically allocates memory resources based on the actual memory usage of the network.