Reputation: 21
I run this code in Anaconda prompt, and it returns True.
(base) C:\User
torch.cuda.is_available()
True
But when I run other conda environment, it just doesn't work.
(pytorch_project) C:\User
torch.cuda.is_available()
False
The problem seems to be different results of torch.version.cuda.
(base) torch.version.cuda = 10.1
(pytorch_project) torch.version.cuda = 10.2
But I don't know why they are different...
How do I make 10.2 down to 10.1 and make is_available() == True ?
Here is my info.
Windows 10 / nvidia-smi=425.31 / CUDA ver=10.1 / pytorch=1.4.0 / torchvision=0.5.0
Upvotes: 1
Views: 3801
Reputation: 21
Thank you for your answers and comments. <3
I've solved the problem.
I use Visual Studio Code as the developer environment tool, but as shown in the picture I uploaded, conda list
pointed at exact the same directory, which means I didn't actually activate my environment.
It should be like (pytorch) C:\User
, but it's (Power Shell) PS C:\User
instead.
To solve this, I went to Settings
→ Terminal > Integrated > Shell Args: Windows
and edited settings.json
with
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "ByPass", "-NoExit","-Command","& 'C:\\Users\\user\\miniconda3\\shell\\condabin\\conda-hook.ps1'" ]
Reference: https://blog.lcarbon.idv.tw/vscode-設定-anaconda-路徑至-visual-studio-code-終端機中windows/
By starting a new terminal I got (pytorch) PS C:\User
correctly, and saw my torch=1.5.0
using conda list
.
Then I run conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
to change the pytorch version.
And Voilà!!
torch.cuda.is_available()
True
Upvotes: 1
Reputation: 7209
Try to uninstall PyTorch and torchvision from pytorch_project
environment and install again in this way:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
Or, if you prefer pip:
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
See https://pytorch.org/get-started/locally/ for details and more options.
Upvotes: 0