Pytorch 常见问题

人工智能炼丹师
2021-05-23 / 0 评论 / 1,210 阅读 / 正在检测是否收录...

1.CUDA_VISIBLE_DEVICES设置无效,始终占用GPU0?

1. 在import torch前设置环境变量
2. CUDA_DEVICE_ORDER=PCI_BUS_ID CUDA_VISIBLE_DEVICES=3 python train.py

2.RuntimeError: CUDA error: device-side assert triggered

设置环境变量,让报错显示更具体的代码行

import os
os.environ["CUDA_LAUNCH_BLOCKING"] = "1"

3.RuntimeError: DataLoader worker (pid xxx) is killed by signal: Aborted.
what(): CUDA error: initialization error

pytorch github issue ref
google找到的文章,大多怀疑是内存问题

  1. 尝试修改pin_memory没有效用
  2. 尝试修改shm没有效果,mount -o remount,size=32g /dev/shm
  3. 尝试改小num_worker无效果(16->8)将num_workers设置为0可以解决问题,但肯定不是最优解!!!

4.resume training时,出现GPU OOM的问题

在DDP训练场景下进行resume training可能出现该问题,原因在于每个进程torch.load都加载在同一块卡上,导致最后OOM。解决方案: map_location指定加载在哪块卡上

checkpoint = torch.load(checkpoint_path, map_location='cuda:{}'.format(opts.local_rank))

5.CUDNN和pytorch版本不匹配

可以从torch_stable.html下载安装

6 . unrecognized arguments: --local_rank,由于torch2.0升级导致,修复方案:

python -m torch.distributed.launch xxx 替换为 torchrun xxx

6

评论 (0)

取消
粤ICP备2021042327号