错误:
原因1:torch的cu版本与使用的CUDA版本不一致。
解决方案:因为我的CUDA是11.6,所以运行下方(需注意cu版本要低于nvidia-smi里的CUDA版本):
pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu116
原因2:torch的版本大于1.9:
从 PyTorch 1.9 开始,torch.distributed.launch
已被弃用,取而代之的是 torch.distributed.run
。因此,在较新版本中,继续使用旧的 launch
命令会引发错误。
解决方案:torch.distributed.launch
替换为新的 torch.distributed.run
python -m torch.distributed.run --nproc_per_node=NUM_GPUS_YOU_HAVE your_script.py