Recovery Time (PyTorch)

This section describes the optimization items that can be used to shorten the resumable training time on PyTorch, including Fault Detection Time, Collective Communication Initialization Time, Training Rollback and Checkpoint Loading Time, and Operator Building Time.

Fault Detection Time

A parameter plane network fault in a cluster may not affect a training job. Therefore, the cluster scheduling components do not forcibly interrupt the job. When the parameter plane network fault affects a training job, the network timeout mechanism of collective communication is triggered. After a default waiting period of 30 minutes, the cluster scheduling components can detect the fault and trigger resumable training. To solve this problem, the PyTorch Adapter plugin (torch_npu) provides a watchdog fault detection function to determine if training jobs are affected and to reduce fault detection time. For details, see Table 1.

Table 1 Description of watchdog fault detection

Function

Watchdog fault detection

Function Highlights

When training is started, a monitoring thread is started at the same time to continuously obtain communication exceptions and job execution exceptions. After a fault is detected, an exception is quickly thrown, the training process is terminated, and rescheduling is triggered.

Instructions

Only PyTorch 1.11.0, 2.1.0, and later versions are supported. The version of torch_npu must be later than 6.0.RC1.

Key Operation

In PyTorch 2.1.0 and later versions, watchdog fault detection is enabled by default. You do not need to manually configure environment variables.

(Optional) To disable watchdog fault detection, modify the following environment variables in the shell startup script, for example, train_start.sh.

...
# env for breakpoint ckpt
export RESUME_MODE_ENABLE=1

export HCCL_ASYNC_ERROR_HANDLING=0               # For details about this environment variable, see Table 5.

Collective Communication Initialization Time

Parallel Store multi-thread link setup optimization: When PyTorch creates communication groups, TCP Store is used for information exchange. As the job scale increases, the information processing performance of the native TCP Store degrades, leading to prolonged times for creating communication groups. To solve this problem, torch_npu supports the optimized Parallel Store built on the native TCP Store. For details, see Table 2.

Table 2 Parallel Store description

Function

Parallel Store

Function Highlights

During multiple threads process link setup, this function can reduce both the waiting time of the link setup request queue and the overall link setup time.

Instructions

For PyTorch 1.11.0, the version of torch_npu must be later than 6.0.RC1.

For PyTorch 2.1.0 or later, the version of torch_npu must be later than 6.0.RC3.

Key Operation

In the shell script (for example, train_start.sh) for starting training, change the torchrun command to torch_npu_run. For example:

Change

torchrun train.py --train_parameter=xxx ....

To

torch_npu_run train.py --train_parameter=xxx ....

Training Rollback and Checkpoint Loading Time

Operator Building Time

If an operator needs to be re-executed during resumable training, building the operator takes a long time. To solve this problem, you can select the operator binary or operator building cache to reduce the building time. For details, see Table 7 and Table 8.

The operator binary and operator building cache are incompatible. Select either of them.

Table 7 Operator binary description

Function

Operator binary

Function Highlights

During operator building, the preset operator binary is loaded in advance so that the operator can be executed without building.

Instructions

Only CANN 8.0.RC2 and later versions are supported.

Key Operation

In the Python startup script, add the operator binary configuration command to enable operator binary.

torch.npu.set_compile_mode(jit_compile=False)
Table 8 Operator building cache description

Function

Operator building cache

Function Highlights

During operator building, the operator building cache file saved on the storage device is loaded, which can reduce the building time.

Instructions

Only CANN 8.0.RC2 and later versions are supported.

Key Operation

  1. In the Python startup script, add the following command to enable operator build cache.
    torch.npu.set_compile_mode(jit_compile=True)
  2. Add the following environment variables to the shell startup script (for example, train_start.sh) for training:
    export ASCEND_CACHE_PATH=xxx    # Add a shared storage path.
    export ASCEND_MAX_OP_CACHE_SIZE=-1    # Enable this environment variable when using shared storage to solve the problem of resource preemption when multiple nodes read the shared storage cache.