PyTorch unable to access CUDA despite following all the right(?) steps

username: MindeKing
cooked: <p>Running Windows 10, I did a fresh install of Anaconda, Python 3.10.6, created a fresh environment using the Anaconda Navigator on Python 3.10.4, I activated the environment in the Anaconda Terminal, and installed PyTorch for my CUDA version 11.7 using the “get-started locally” page. Once finished, I ran the commands <code>python</code>, <code>import torch</code>,<code>torch.cuda.is_available()</code>, which returned <code>False</code>, and <code>torch.version.cuda</code> which returned none. I don’t have cpuonly installed.</p>
<p>I don’t know where to go from here. I’ve looked everywhere I can think of, using every relevant term I know, and I can’t think of anything else to do but ask for help on a public forum now.</p>
<p>Why can’t PyTorch access CUDA? What can I do to remedy this issue?</p>
<p>Sorry if this issue is an extremely easy fix.</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="MindeKing" data-post="1" data-topic="160591">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mindeking/48/52896_2.png" class="avatar"> MindeKing:</div>
<blockquote>
<p>installed PyTorch for my CUDA version 11.7 using the “get-started locally” page. Once finished, I ran the commands <code>python</code>, <code>import torch</code>,<code>torch.cuda.is_available()</code>, which returned <code>False</code>, and <code>torch.version.cuda</code> which returned none. I don’t have cpuonly installed.</p>
</blockquote>
</aside>
<p>Based on the returned <code>None</code> from <code>torch.version.cuda</code> it sounds that you have unfortunately installed the CPU-only binary.</p>

username: MindeKing
cooked: <p><a href="https://imgur.com/2AVqOqD" rel="noopener nofollow ugc">Here</a> is a screenshot of the environment I’m trying to use CUDA, packages from “b” to “f” in the Anaconda Navigator. No CPU-only binary to be found.<br>
And <a href="https://imgur.com/1WEJVHo" rel="noopener nofollow ugc">here</a> is a screenshot of the base (root) environment, packages “co”-“cs” in AN, again with no CPU-only binary to be seen.<br>
I’ve also searched in both environments for anything with “cpu” in it, and come up empty.<br>
(Unless binaries and packages are two separate things within Anaconda/AN, and I’m just barely missing seeing it, in which case I am terribly sorry.)</p>
<p>Also, a point about the <code>torch.version.cuda</code> returning <code>None</code> thing: It doesn’t actually return a line that says <code>None</code>, rather, it just goes to a <a href="https://imgur.com/5xELVPA" rel="noopener nofollow ugc">new line</a> immediately. Sorry if that’s an important distinction to have made that I missed.</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="MindeKing" data-post="3" data-topic="160591">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mindeking/48/52896_2.png" class="avatar"> MindeKing:</div>
<blockquote>
<p><a href="https://imgur.com/2AVqOqD">Here</a> is a screenshot of the environment I’m trying to use CUDA, packages from “b” to “f” in the Anaconda Navigator. No CPU-only binary to be found.</p>
</blockquote>
</aside>
<p>But also no mention of any <code>torch+cuXXX</code> version is mentioned there, so I don’t think this screenshot is sufficient. Check the installed PyTorch binary via <code>pip list</code> or <code>conda list</code>. Additionally, also check the install log as it would show which exact binary was installed.</p>
<aside class="quote no-group" data-username="MindeKing" data-post="3" data-topic="160591">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mindeking/48/52896_2.png" class="avatar"> MindeKing:</div>
<blockquote>
<p>And <a href="https://imgur.com/1WEJVHo">here</a> is a screenshot of the base (root) environment, packages “co”-“cs” in AN, again with no CPU-only binary to be seen.</p>
</blockquote>
</aside>
<p>This screenshot also shows irrelevant packages and no PyTorch binary.</p>

username: MindeKing
cooked: <p>Forgive me if I do not understand your help completely.</p>
<p>Running either command while the environment I set up is active tells me that I have <code>pytorch 1.12.1</code>, <code>pytorch-mutex 1.0</code> (<a href="https://imgur.com/qf1JTEU" rel="noopener nofollow ugc">image</a>), <code>torchaudio 0.12.1</code>, and <code>torchvision 0.13.1</code> (<a href="https://imgur.com/ZNMqijM" rel="noopener nofollow ugc">image</a>). In the same lists, I cannot find <code>cpuonly</code>, nor could I find an item resembling <code>torch+cuXXX</code>.</p>
<p>Additionally, I can either not find the appropriate log files in my computer or through the terminal, or the log which I have found in the Anaconda Navigator app does not provide a list of binaries installed.</p>
<p>Thank you for your continued assistance, apologies for my continued ignorance.</p>

username: ptrblck
cooked: <p>Your screenshot shows the <code>cpu</code> tag on the right in <code>pytorch</code> as well as <code>torchvision</code> and <code>torchaudio</code> so either uninstall these binaries and install the right ones with a CUDA runtime or create a new virtual environment and install the right ones there.</p>

username: MindeKing
cooked: <p>I ran the CUDA Toolkit installer from <a href="https://developer.nvidia.com/cuda-downloads" class="inline-onebox" rel="noopener nofollow ugc">CUDA Toolkit 11.7 Update 1 Downloads | NVIDIA Developer</a>, then I created a new environment with Python 3.10.4, activated the environment, and installed it using Conda with the command <code>conda install cuda -c nvidia</code>.</p>
<p>Again I went to <a href="https://pytorch.org/get-started/locally/" class="inline-onebox" rel="noopener nofollow ugc">Start Locally | PyTorch</a>, and ran the command <code>conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch -c conda-forge</code>, and, again, torch returns <code>False</code> to <code>torch.cuda.is_available()</code>, and nothing at all to <code>torch.version.cuda</code>, and only the cpu build of pytorch can be found when I <code>conda list</code> in the environment.</p>
<p>I figured there might be some problems with trying to install for a CUDA version that technically isn’t actually on that webpage, so I created another new environment with Python 3.10.4, activated it, installed CUDA using the aforementioned command, ran the PyTorch installation for 11.6, etc. etc. <code>torch.cuda.is_available()</code> returns <code>True</code>, and <code>torch.version.cuda</code> returns <code>11.6</code>. Not 100% sure if it was just the 11.7 needing to be 11.6 thing or also the fact that just having an Nvidia card apparently doesn’t also mean having CUDA at the ready on your PC, but regardless, it works now.</p>
<p>Thank you for your assistance, apologies for my incompetence.</p>

username: ptrblck
cooked: <aside class="quote no-group" data-username="MindeKing" data-post="7" data-topic="160591">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mindeking/48/52896_2.png" class="avatar"> MindeKing:</div>
<blockquote>
<p>I ran the CUDA Toolkit installer from <a href="https://developer.nvidia.com/cuda-downloads">CUDA Toolkit 11.7 Update 1 Downloads | NVIDIA Developer</a>, then I created a new environment with Python 3.10.4, activated the environment, and installed it using Conda with the command <code>conda install cuda -c nvidia</code>.</p>
</blockquote>
</aside>
<p>Your local CUDA toolkit won’t be used unless you want to build PyTorch from source or any custom CUDA extension. Installing it via <code>conda install cuda -c nvidia</code> is not supported in the install matrix (it will be for future CUDA 11.7 versions).</p>
<aside class="quote no-group" data-username="MindeKing" data-post="7" data-topic="160591">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mindeking/48/52896_2.png" class="avatar"> MindeKing:</div>
<blockquote>
<p>Again I went to <a href="https://pytorch.org/get-started/locally/">Start Locally | PyTorch</a>, and ran the command <code>conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch -c conda-forge</code>, and, again, torch returns <code>False</code> to <code>torch.cuda.is_available()</code>, and nothing at all to <code>torch.version.cuda</code>, and only the cpu build of pytorch can be found when I <code>conda list</code> in the environment.</p>
</blockquote>
</aside>
<p>That’s expected as you are manually creating this install command which then fails.<br>
Use the supported CUDA runtimes by selecting them in the install matrix. Right now the newest CUDA runtime is CUDA 11.6. Click on the <code>CUDA 11.6</code> button, copy/paste the command, and execute it.</p>
<p>In any case, it’s good to hear you’ve solved the issue and it works now.</p>