Windows下 pytorch 分布式训练方法
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 函数的参数更改为以下内容:
torch.distributed.init_process_group( backend="gloo",
init_method=r"file:///{your model path}",
world_size=args.world_size, # 本机gpu的数目
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
还没有评论,来说两句吧...