本博客主要解决 “AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘” 问题,同时遇到
“git 不是内部或外部命令,也不是可运行的程序” 的问题,一并解决。
问题
最近在新的电脑上运行 pytorch,发现以前能用的代码突然不能用了。原因是,在调用 apex 时,用到了 torch.distributed.deprecate 这个分布式通信包。然而,torch.distributed.deprecated 是 torch.distributed 的早期版本,当前已被弃用,并且很快将被删除。
出现了如下报错:
AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘
解决方法:AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘
1. 如果已经安装过 apex,需要先卸载它:(windows10 环境下,打开 cmd)
pip uninstall apex
rm -rf apex
2. 重新安装一个新的 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 ./
结果分别如下:
解决方法:git 不是内部或外部命令,也不是可运行的程序
windows10 环境 cmd 中使用 git 指令时,可能会提示这个问题。这是因为没有安装 Git 软件。
1. 下载 Git:
下载windows版本的git:http://git-scm.com/downloads
或:https://github.com/git-for-windows/git/releases/tag/v2.15.0.windows.1
2. 安装 Git:
一直点击 next,Git 安装完毕。
3. 添加路径:
右键 ‘计算机’,选择 ‘属性 -> 高级系统设置 -> 环境变量’, 在对话框下面找到 ‘path’ 并双击,点击 ‘浏览’,将 "C:\Program Files\Git\mingw64\bin" 和 "C:\Program Files\Git\mingw64\libexec\git-core" 添加到路径中。
4. 重新启动 cmd:
务必重新启动,否则还是用不了。