Pytorch GPU via conda not working

janko: <p>I want to run pytorch on GPU (within conda) with the following settings but all attempts failed.</p>
<ul>
<li>Ubuntu 24</li>
<li>GPU: RTX 4090</li>
<li>Driver Version: 550.120 (checked via nvidia-smi)</li>
<li>No system-wide cuda installation</li>
<li>pytorch install commands I tried:<br>
conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia<br>
conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch-nightly -c nvidia</li>
</ul>
<p>What would you recommend?</p>

ptrblck: <p>Check if the right binary was installed via <code>print(torch.version.cuda)</code>. If it’s showing <code>12.4</code>, the binary might have trouble communicating with the NVIDIA driver.</p>

janko: <p>Thank you but this returns None.<br>
I further checked:</p>
<ul>
<li>gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0</li>
<li>torch.<strong>version</strong> is ‘2.4.1’</li>
<li>conda list:<br>
cuda-cudart               12.4.127                      0    nvidia<br>
cuda-cupti                12.4.127                      0    nvidia<br>
cuda-libraries            12.4.1                        0    nvidia<br>
cuda-nvrtc                12.4.127                      0    nvidia<br>
cuda-nvtx                 12.4.127                      0    nvidia<br>
cuda-opencl               12.6.77                       0    nvidia<br>
cuda-runtime              12.4.1                        0    nvidia<br>
cuda-version              12.6                          3    nvidia<br>
where I guess the 12.6 version might be causing the issue?</li>
</ul>

ptrblck: <p>No, I don’t think so as the install command works for me in a new and empty conda environment:</p>
<pre data-code-wrap="python"><code class="lang-python">conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia
...
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    blas-1.0                   |              mkl           6 KB
    brotli-python-1.0.9        |  py310h6a678d5_8         356 KB
    certifi-2024.8.30          |  py310h06a4308_0         162 KB
    cuda-cudart-12.4.127       |                0         198 KB  nvidia
    cuda-cupti-12.4.127        |                0        16.4 MB  nvidia
    cuda-libraries-12.4.1      |                0           2 KB  nvidia
    cuda-nvrtc-12.4.127        |                0        21.0 MB  nvidia
    cuda-nvtx-12.4.127         |                0          58 KB  nvidia
    cuda-opencl-12.6.77        |                0          25 KB  nvidia
    cuda-runtime-12.4.1        |                0           2 KB  nvidia
    cuda-version-12.6          |                3          16 KB  nvidia
...
    pytorch-2.5.1              |py3.10_cuda12.4_cudnn9.1.0_0        1.46 GB  pytorch
    pytorch-cuda-12.4          |       hc786d27_7           7 KB  pytorch
    pytorch-mutex-1.0          |             cuda           3 KB  pytorch
...
</code></pre>
<pre data-code-wrap="python"><code class="lang-python">python -c "import torch; print(torch.__version__); print(torch.version.cuda); print(torch.cuda.is_available()); print(torch.randn(1).cuda())"
2.5.1                                                                                                                                                                                                                                                                             
12.4                                                                                                                                                                                                                                                                              
True                                                                                                                                                                                                                                                                              
tensor([0.3827], device='cuda:0')        
</code></pre>
<p>However, you could also try to use the pip wheels if you are seeing issues with conda as conda binaries will be deprecated as mentioned <a href="https://github.com/pytorch/pytorch/issues/138506">here</a>.</p>

janko: <p>Thank you.<br>
Resolved: creating a new (and empty!) conda env helped so the original<br>
<code>conda install pytorch torchvision torchaudio pytorch-cuda=12.4 -c pytorch -c nvidia</code><br>
works now.</p>