更新时间:2024-08-17 GMT+08:00
分享

显存溢出错误

在训练过程中,常见显存溢出报错,示例如下:

RuntimeError: NPU out of memory. Tried to allocate 1.04 GiB (NPU 4; 60.97 GiB total capacity; 56.45 GiB already allocated; 56.45 GiB current active; 1017.81 MiB free; 56.84 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.

解决方法

  • 通过npu-smi info查看是否有进程资源占用NPU,导致训练时显存不足。解决可通过kill掉残留的进程或等待资源释放。
  • 可调整参数:TP张量并行(tensor-model-parallel-size) 和PP流水线并行(pipeline-model-parallel-size),可以尝试增加 TP和PP的值,一般TP×PP≤NPU数量,并且要被整除,具体调整值可参照表1进行设置。
  • 可调整参数:MBS指最小batch处理的样本量(micro-batch-size)、GBS指一个iteration所处理的样本量(global-batch-size)。可将MBS参数值调小至1,但需要遵循GBS/MBS的值能够被NPU/(TP×PP)的值进行整除。
  • 可调整参数:SEQ_LEN要处理的最大的序列长度(seq-length),参数值过大很容易发生显存溢出的错误。
  • 可添加参数:在3_training.sh文件中添加开启重计算的参数。其中recompute-num-layers的值为模型网络中num-layers的参数值。
--recompute-granularity full \
--recompute-method block \
--recompute-num-layers {NUM_LAYERS} \

相关文档