AttributeError: module ‘torch.distributed‘ has no attribute ‘deprecated‘ (已解决)

本博客主要解决 “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:

务必重新启动,否则还是用不了。

 

 

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值