1. 程式人生 > 其它 >萬惡的環境2——安裝的torch版本是cpu版本如何改為GPU版本

萬惡的環境2——安裝的torch版本是cpu版本如何改為GPU版本

萬惡的環境2——安裝的torch版本是cpu版本如何改為GPU版本

目錄

感謝 參考的連結

[錯誤Torch not compiled with CUDA enabled解決方法附CUDA安裝教程及Pytorch安裝教程_nm235666的部落格-CSDN部落格](https://blog.csdn.net/moyong1572/article/details/119438286#:~:text=執行時報出AssertionError%3A

Torch not compiled with CUDA enabled錯誤 ,具體,” if torch. cuda.is_available () else “cpu”) 程式碼)

1 報錯

2 檢查

import torch as th
print(th.__version__)
print(th.cuda.is_available())
cuda1 = th.device('cuda')
print(f'device:{cuda1} device.type:{cuda1.type}')
s = th.randn((2,3),device=cuda1)
print(s)

3 結果與問題——torch版本是cpu版本的

4解決

4.1 首先檢查自己受否有安裝cuda

在命令列中輸入

nvcc -V

4.2 到官網去下載對應版本的torch

Start Locally | PyTorch

5 驗證效果

再次執行程式碼 ,發現成功