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