解决 PyTorch 分布式训练中的 "unrecognized arguments" 错误
在使用 torch.distributed.run 进行 PyTorch 分布式训练时,你可能会遇到以下错误信息:
WARNING:torch.distributed.run:*****************************************
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
train.py: error: unrecognized arguments: --local-rank=1 convformer_b36_in21ft1k.pth
train.py: error: unrecognized arguments: --local-rank=0 convformer_b36_in21ft1k.pth
ERROR:torch.distributed.elastic.multiprocessing.api:failed (exitcode: 2) local_rank: 0 (pid: 31168) of binary: /home/lh/anaconda3/envs/metaformer/bin/python3
这个错误表明你的 train.py 文件中出现了无法识别的参数 --local-rank=1 和 --local-rank=0。这是因为 torch.distributed.run 会自动添加这些参数,所以你不需要手动传入。
为了解决这个问题,你需要检查 train.py 文件中的参数设置,并确保这些参数是有效的。具体来说,你需要:
- 确认你的代码中是否手动传递了
--local-rank参数。 如果是,请删除它,因为torch.distributed.run会自动处理。 - 检查你的
train.py文件中是否使用了其他需要local_rank信息的代码。 如果有,你需要确保这些代码使用的是torch.distributed.get_rank()或torch.distributed.get_world_size()来获取local_rank信息,而不是手动传入参数。 - 查看
train.py的文档或示例以了解正确的参数使用方法。 确保你的代码遵循官方文档的指导。
如果以上方法都无法解决问题,请确保你使用的 PyTorch 版本和 torch.distributed.run 的版本匹配,并尝试更新或降级版本进行测试。
原文地址: https://www.cveoy.top/t/topic/qzsF 著作权归作者所有。请勿转载和采集!