Windows下 pytorch 分布式训练方法

男娘i 2022-10-09 03:04 390阅读 0赞

torch1.7 以下版本不支持Windows下的分布式训练,会报错 AttributeError: module ‘torch.distributed‘ has no attribute ‘init_process_group‘

步骤:

1、将本机torch版本升到1.7.0以上,torchvision升到对应的0.8.0版本以上。(1.5~1.8 版本的 torch 代码基本都兼容)

温馨提示:建议离线下载 torch1.7.1 版本,torchvision0.8.2 版本。

下载链接如下:

https://download.pytorch.org/whl/

2、更换torch版本之后,在Windows下运行之前,将 init_process_group 函数的参数更改为以下内容:

  1. torch.distributed.init_process_group( backend="gloo",
  2. init_method=r"file:///{your model path}",
  3. world_size=args.world_size, # 本机gpu的数目
  4. rank=args.rank ) # rank是本机gpu的编号列表,如2个gpu即为 [0,1]

其他细节和 torch 在Linux的分布式训练相同,可以参考下面这篇博客:

pytorch多gpu训练,单机多卡,多机多卡
https://blog.csdn.net/kejizuiqianfang/article/details/102454278?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-3.nonecase

发表评论

表情:
评论列表 (有 0 条评论,390人围观)

还没有评论,来说两句吧...

相关阅读