AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘问题解决方案

问题

在参加一个分类比赛的时候down了一套demo用来做比赛,但是在导入from apex.parallel import DistributedDataParallel as DDP的时候提示错误:

AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘

解决方法:AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘

首先我的torch版本是1.5.1,CUDA是10.1。在最开始的时候我使用Phoenixtree_Zhao博客的方法:

  1. 如果已经安装过 apex,需要先卸载它:(windows10 环境下,打开 cmd)
pip uninstall apex
rm -rf apex
  1. 重新安装一个新的 apex,即 apex_no_distributed :
git clone https://github.com/ptrblck/apex.git
cd apex
git checkout apex_no_distributed
pip install -v --no-cache-dir ./

结果分别如下:
AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘问题解决方案_第1张图片
然而在实际使用时,AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘ 仍然存在,后来我注意到原文博客中torch版本为1.6.0,且github原文作者使用环境也为torch1.6.0。因此我怀疑原因可能是torch版本问题。于是我将现版本torch卸载安装1.7.0.最后重复操作。最后成功解决。

言外之语: nvidia的软件是真的难用,但凡碰到nVidia的问题基本就是些稀奇古怪的问题,软件安装过程就有一大堆问题,安装完成之后还会碰到一些稀奇古怪的问题,有的时候甚至按照GitHub上nVidia开发者的步骤(这个也想吐槽,安装过程前提条件一大堆,还说的语焉不详)来也是问题一大堆,经常安装不了。只能说以后写程序尽可能避开nVidia不然的话在不同电脑上兼容性就是一个大问题。

你可能感兴趣的:(Pytorch编译解决方案)