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 的早期版本,當前已被棄用,而且很快將被刪除。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:

務必從新啓動,不然仍是用不了。

相關文章
相關標籤/搜索