Environment Setup

Obtaining ATC

Set up the environment by following the instructions in CANN Software Installation Guide. Ensure that Ascend-CANN-Toolkit is installed. In this scenario, the ATC tool is installed in ${install_path}/latest/bin. Replace ${install_path} with the CANN installation directory. For example, if a root user installs the package, the installation directory is /usr/local/Ascend/ascend-toolkit.

Setting Environment Variables

  • If it takes too long to convert a model in the Arm (AArch64) development environment, fix it by referring to What Do I Do If Model Conversion Takes Too Long When the Development Environment Architecture Is Arm (AArch64)?
  • For details about the Python versions supported by this tool, see section "Appendix A: Reference > Dependencies" in CANN Software Installation Guide. This document uses Python 3.7.5 as an example. The environment variables and installation commands depend on the actual Python version.
  • During ATC model conversion, TBE Python libraries required for operator build in ../python/site-packages under the ATC installation directory will be automatically written into the PYTHONPATH environment variable.

    If other Python dependencies except the TBE module are imported during operator implementation, add the environment variable PYTHONPATH and configure the path of the imported Python dependencies in the following format:

    export PYTHONPATH=xxxx:$PYTHONPATH

  1. Required environment variables
    • Set public environment variables.

      After the CANN package is installed, log in to the environment as the CANN running user and run the following command to execute the environment variable:

      source ${install_path}/set_env.sh
      # If the Ascend-CANN-Toolkit package is installed on a non-Ascend device, the following environment variable must be executed to set the path of the dynamic link library (DLL). Otherwise, skip this step.
      export LD_LIBRARY_PATH=${install_path}/latest/<arch>-linux/devlib:$LD_LIBRARY_PATH

      ${install_path} indicates the CANN installation directory. For example, if a root user installs the package, the installation directory is /usr/local/Ascend/ascend-toolkit. Replace <arch> with the actual OS architecture.

    • Set Python environment variables.
      Model build requires Python. Take Python 3.7.5 as an example. Run the following command as the CANN running user to set environment variables related to Python 3.7.5:
      # If multiple Python 3 versions exist in the user environment, specify Python 3.7.5.
      export PATH=/usr/local/python3.7.5/bin:$PATH
      # Set the library path for Python 3.7.5.
      export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH

    The preceding environment variables take effect only in the current window. You can write the preceding commands to the ~/.bashrc file to make them take effect permanently. The method is as follows:

    1. Run the vi ~/.bashrc command in any directory as the installation user and append the preceding commands to the file.
    2. Run the :wq! command to save the file and exit.
    3. Run the source .bashrc command to make the environment variable take effect.
  2. Optional environment variables
    1. Use log flushing, printing to the screen, and redirection.
      • Log flushing:

        During the execution of the atc command, logs are flushed to the following path by default:

        • $HOME/ascend/log/debug/plog/plog-pid_*.log: debug log.

          In the debug log scenario, since the default value of --log is null, no logs about the atc process are generated in the directory. However, other logs may be generated in the directory, for example, logs about Python dependencies. To generate logs about the atc process, set --log to a value other than null.

        • $HOME/ascend/log/run/plog/plog-pid_*.log: run log.
        • $HOME/ascend/log/security/plog/plog-pid_*.log: security log.

        pid indicates the process ID, and * indicates the timestamp when the log file is created.

      • Log printing to the screen:
        During the execution of the atc command, log messages are not printed to the screen by default. To print log messages to the screen, set the following environment variable in the current window before you run the atc command:
        export ASCEND_SLOG_PRINT_TO_STDOUT=1

        For details about logs, see Log Reference. If no valid information is displayed after the preceding environment variable is set, run the atc command to set the --log option (to a value other than null) so that logs of the corresponding level can be printed to the screen.

      • Log redirection:

        To redirect logs to files rather than flushing them to a specific directory, set the preceding environment variables for log printing before model conversion and set the --log option (to a value other than null) in the atc command.

        atc xxx --log=debug >log.txt
    1. Enable parallel build of operators.
      If the network model to be converted is large, you can set the following environment variable to enable parallel build:
      export TE_PARALLEL_COMPILER=xx

      The value of TE_PARALLEL_COMPILER indicates the number of operator build processes. The value is an integer ranging from 1 to 32, and the default value is 8. A value greater than 1 indicates that the parallel build of operators is enabled. It is recommended that the value be less than or equal to: Number of CPU cores x 80%/Number of Ascend AI Processor.

    2. Print graph description in each phase of model conversion.
      export DUMP_GE_GRAPH=1

      The preceding environment variable controls the graph dump mode. The values are as follows:

      • 1: dumps all, including the edge relationships and data information.
      • 2: dumps information without data such as weights.
      • 3: dumps only node relationships.

      You can set the following environment variable to control the graphs to dump:

      export DUMP_GRAPH_LEVEL=1

      This environment variable takes effect only when DUMP_GE_GRAPH is enabled. The default value is 2. It can be configured in either of the following ways. Both of them are used to control the number of flushed graphs. You can use them as required. Note that the two configuration methods cannot be used together.

      • Set it to a value. Possible values are as follows:
        • 1: dumps all graphs.
        • 2 (default): dumps all graphs except subgraphs.
        • 3: dumps the last generated graph, that is, the graph optimized and compiled by the GE.
        • 4: dumps the earliest generated graph, that is, the entire graph that is first moved down to the device after the GE parsing and mapping operator. This graph has not been compiled or optimized by the GE.
      • Set it to a character string separated by vertical bars (|):

        For example, if this environment variable is set to aa|bb, graphs whose names contain aa and bb are dumped. aa and bb must be set to valid character strings during graph build. Valid strings can be obtained from a full dump of the graphs.

      After this environment variable is set, the following files are generated in the current path where the atc command is executed.

      • ge_onnx*.pbtxt: model description structure based on ONNX. You can open this file using visualizer software such as Netron.
      • ge_proto*.txt: text file stored in Protobuf format. You can convert it into a JSON file to facilitate fault locating. This file appears in pair with the ge_onnx*.pbtxt file, but has more attributes of the string type than the ge_onnx*.pbtxt file, making it more comprehensive. You can open either of them.

        Compared with the ge_onnx*.pbtxt file, the ge_proto*.txt file has a smaller size. Therefore, setting DUMP_GE_GRAPH to 2 or 3 has the same effect on the ge_proto*.txt file, that is, dumping information without data such as weights.

      Each of the preceding files corresponds to a step in the model build process, for example, the build begins with the execution of the ge_onnx_00000001_graph_0_PreRunBegin.pbtxt file and ends with the execution of the ge_onnx_00000078_graph_0_PreRunAfterBuild.pbtxt file. Each file contains all operators involved in this step. For details about dump graphs, see Dump Graph Details.

    3. For more optional environment variables, see Environment Variables.