Environment Variable Configuration

Before starting training, you need to configure the training-related environment variables to set up the PyTorch training environment on NPU. A shell script is generally used for configuration. The specific configuration steps and examples are as follows:

  1. Configure the shell script for environment variables. The default configuration example is shown below. You can add other environment variables as needed. For details, refer to Environment Variable Reference.

    #!/bin/bash
    CANN_INSTALL_PATH_CONF='/etc/Ascend/ascend_cann_install.info'  # CANN configuration file path
    
    if [ -f $CANN_INSTALL_PATH_CONF ]; then
        CANN_INSTALL_PATH=$(cat $CANN_INSTALL_PATH_CONF | grep Install_Path | cut -d "=" -f 2)
    else
        CANN_INSTALL_PATH="/usr/local/Ascend"  # Actual CANN installation path
    fi
    
    source ${CANN_INSTALL_PATH}/cann/set_env.sh
    
    # Set the device-side log level to error
    msnpureport -g error -d 0
    msnpureport -g error -d 1
    msnpureport -g error -d 2
    msnpureport -g error -d 3
    msnpureport -g error -d 4
    msnpureport -g error -d 5
    msnpureport -g error -d 6
    msnpureport -g error -d 7
    # Disable device-side Event logging
    msnpureport -e disable
    # Output host logs to the serial port: 0-disable/1-enable
    export ASCEND_SLOG_PRINT_TO_STDOUT=0
    # Set the default log level: 0-debug/1-info/2-warning/3-error
    export ASCEND_GLOBAL_LOG_LEVEL=3
    # Set the Event logging enable flag: 0-disable/1-enable
    export ASCEND_GLOBAL_EVENT_ENABLE=0
    # Set whether to enable taskqueue: 0-disable/1-enable/2-taskqueue after two-level pipeline optimization
    export TASK_QUEUE_ENABLE=1
    # Set whether to enable PTCopy: 0-disable/1-enable
    export PTCOPY_ENABLE=1
    # Set whether to recompile in special scenarios, no modification required
    export DYNAMIC_OP="ADD#MUL"
    # Set HCCL whitelist: 1-disable/0-enable
    export HCCL_WHITELIST_DISABLE=1
    export HCCL_IF_IP=$(hostname -I |awk '{print $1}')
    
  2. Before starting training, execute the environment variable script configured in 1.

    source env.sh # env.sh is the name of the environment variable script. Modify it according to the actual situation.