PyTorch for Cuda 12

Valugar: <p>Hello,</p>
<p>Since the new CUDA 12 is out, was wondering if PyTorch is compatible with the newest CUDA version or should I install the 11.8.<br>
Thank you</p>

ptrblck: <p>You should be able to build PyTorch from source using CUDA 12.0, but the binaries are not ready yet (and the nightlies with CUDA 11.8 were just added ~2 weeks ago).<br>
If you decide to build from source, note that a few fixes still need to land which are tracked <a href="https://github.com/pytorch/pytorch/issues/91122">here</a>.</p>

Dorra: <p>Hi</p>
<p>still, PyTorch doesn’t work with cuda12, and even downgraded the cuda it is not working too.<br>
my driver version is 525. how can I deal with that?</p>
<p>I appreciate your help</p>

ptrblck: <p>PyTorch does work with CUDA 12 and we are already supporting it via the <a href="https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch">NGC containers</a>.<br>
You would need to post more information about issues you are seeing.</p>

Dorra: <p>RuntimeError: CUDA error: no kernel image is available for execution on the device<br>
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.<br>
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.</p>
<p>my graphic card is RTX 3080 16 GB</p>

ptrblck: <p>This error is raised if your build wasn’t compiled for the right GPU architecture (sm_86 in your case).<br>
Check what <code>torch.cuda.get_arch_list()</code> returns and also check your build logs to see which compute capability was selected.</p>

Dorra: <p>i’ve checked the architectures list and i got the following output<br>
[‘sm_37’, ‘sm_50’, ‘sm_60’, ‘sm_70’]</p>

ptrblck: <p>In case you’ve build PyTorch from source, use <code>TORCH_CUDA_ARCH_LIST=8.6 python setup.py install</code> to build for compute capability 8.6.</p>

Dorra: <p>i did what you mentioned above  i’ve cloned pytroch and then I modified the setup file to add the line specifying the architecture then i ran the python setup.py install in a conda environment with python 3.6 but i faced the same error.<br>
RuntimeError: CUDA error: no kernel image is available for execution on the device<br>
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.<br>
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.</p>
<p>I appreciate your help</p>

ptrblck: <p>Your install log should show if the environment variable was properly detected or not.<br>
Also, you don’t need to modify anything in the <code>setup.py</code> script and could execute my posted command as it is.<br>
If you are still having trouble building from source, you could use the 11.8 binaries (which support your GPU), use the linked NGC container, or wait for the PyTorch binaries to support CUDA 12.</p>

Dorra: <p>now I tried again to execute the command as it is and I think there’s an error at the end of the<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/a/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac.png" data-download-href="https://discuss.pytorch.org/uploads/default/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac" title="Screenshot from 2023-02-17 09-59-22"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/a/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac_2_690x177.png" alt="Screenshot from 2023-02-17 09-59-22" data-base62-sha1="hpzuyH18ZWPU2eGGBaoy9ihZn0E" width="690" height="177" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/a/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac_2_690x177.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/a/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac_2_1035x265.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/7/a/7a08fb1ca225f17fb9a923e2d8b7d61b84f2d6ac_2_1380x354.png 2x" data-dominant-color="371F33"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot from 2023-02-17 09-59-22</span><span class="informations">1398×360 103 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
building : gmake: *** [Makefile:146: all] Error 2</p>

ptrblck: <p>It seems your build now fails to compile <code>protobuf</code>. Was this working before?</p>

Dorra: <p>this is my first use of my computer, I just bought it that’s why I m trying to install all the framework.  but everything was working perfectly on my previous computer because already has an older GPU and CUDA.</p>

barry1: <p>I’m also having an issue with CUDA 12 and PyTorch where I’m getting the following trace:<br>
Traceback (most recent call last):<br>
File “/home/barry/code/test.py”, line 5, in <br>
import torchvision<br>
File “/home/barry/miniconda3/envs/tf/lib/python3.9/site-packages/torchvision/<strong>init</strong>.py”, line 4, in <br>
import torch<br>
File “/home/barry/miniconda3/envs/tf/lib/python3.9/site-packages/torch/<strong>init</strong>.py”, line 229, in <br>
from torch._C import *  # noqa: F403<br>
ImportError: libcusparse.so.11: cannot open shared object file: No such file or directory</p>
<p>I tried running ldconfig and I’m also seeing when running ldconfig -p | grep cuda   , I see<br>
libcusparse.so.12 (libc6,x86-64) =&gt; /usr/local/cuda/targets/x86_64-linux/lib/libcusparse.so.12<br>
libcusparse.so (libc6,x86-64) =&gt; /usr/local/cuda/targets/x86_64-linux/lib/libcusparse.so<br>
nvidia-smi shows NVIDIA-SMI 525.65       Driver Version: 527.37       CUDA Version: 12.0</p>

ptrblck: <p>Assuming you’ve built PyTorch from source using CUDA 12.x, since the binaries are not available yet, I would recommend to make sure no CUDA 11.x (math) library can be found.</p>

Ben_Unsworth: <p>I’m having related problems trying to build pytorch from source – I cloned the repo and followed the windows build from source directions – but it complains that it can’t find nvToolsExt</p>
<p>The location of nvToolsExt used to be installed to C:\Program Files\NVIDIA GPU Computing Toolkit\nvToolsExt   but that seems to be no longet the case.  I am currently opting to install everything that comes with the 12.1 Cuda Toolkit installer.  I have also searched my entire computer for nvToolsExt but can’t seem to find that folder anywhere.  Does it get installed somewhere else under a different name now?  And if so does that mean it also will need to be set with the NVTOOLSEXT_PATH environment variable?  Here is the error that occurs during the install script:</p>
<pre><code class="lang-auto">(diff3d) C:\Dev\pytorch&gt;python setup.py install
Building wheel torch-2.1.0a0+git461f088
-- Building version 2.1.0a0+git461f088
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=C:\Dev\pytorch\torch -DCMAKE_PREFIX_PATH=C:\Users\Owner\mambaforge\envs\diff3d\Lib\site-packages -DJAVA_HOME=C:\Program Files\Android\Android Studio\jre -DNUMPY_INCLUDE_DIR=C:\Users\Owner\mambaforge\envs\diff3d\lib\site-packages\numpy\core\include -DPYTHON_EXECUTABLE=C:\Users\Owner\mambaforge\envs\diff3d\python.exe -DPYTHON_INCLUDE_DIR=C:\Users\Owner\mambaforge\envs\diff3d\Include -DPYTHON_LIBRARY=C:\Users\Owner\mambaforge\envs\diff3d/libs/python39.lib -DTORCH_BUILD_VERSION=2.1.0a0+git461f088 -DUSE_NUMPY=True C:\Dev\pytorch
CMake Warning at CMakeLists.txt:367 (message):
  TensorPipe cannot be used on Windows.  Set it to OFF


-- Current compiler supports avx2 extension. Will build perfkernels.
-- Current compiler supports avx512f extension. Will build fbgemm.
CMake Error at cmake/public/cuda.cmake:69 (message):
  Failed to find nvToolsExt
Call Stack (most recent call first):
  cmake/Dependencies.cmake:43 (include)
  CMakeLists.txt:709 (include)
</code></pre>

Dorra: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a> I’ve solved the Cuda issue right now by using cuda12+pytorch2.0. however, I got another issue related to the optimizer scheduler, where I would like to use CYclicLR as a scheduler but I faced the following error could u please explain how I can solve it<br>
<strong>raise ValueError(f’The provided lr scheduler “{scheduler}” is invalid’)</strong><br>
<strong>ValueError: The provided lr scheduler “&lt;torch.optim.lr_scheduler.CyclicLR object at 0x7f7f6457f0a0&gt;” is invalid</strong></p>

ptrblck: <p>It seems the error is raised by Lightning from <a href="https://github.com/Lightning-AI/lightning/blob/e5dfdf34f958d2eddccb205558763ae7aeedc0cc/pytorch_lightning/trainer/optimizers.py#L189-L192">here</a> and I don’t know why it’s raised as I’m not familiar enough with this lib.</p>

sri_ram: <p>I am facing the following error while using pytorch with cuda 11.7 version. I installed the first Cuda toolkit 12.1 from Nvidia. but it throws a run time error: No Cuda GPUs are available. Then I installed cuda toolkit 11.7 and ran the code again I am facing the same error. How to clear this error?</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6aaa2f8fe47fedb02c09eeaebce58891bec81641.png" data-download-href="https://discuss.pytorch.org/uploads/default/6aaa2f8fe47fedb02c09eeaebce58891bec81641" title="Picture1"><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6aaa2f8fe47fedb02c09eeaebce58891bec81641.png" alt="Picture1" data-base62-sha1="fdBeszyvXsjXnuzMCFdTTUMyRhv" width="690" height="454" data-dominant-color="191919"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Picture1</span><span class="informations">884×582 70.2 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

ptrblck: <p>Your locally installed CUDA toolkit won’t be used as the PyTorch binaries ship with their own CUDA dependencies unless you build PyTorch from source or a custom extension.<br>
Check the output of <code>python -m torch.utils.collect_env</code> and make sure a PyTorch version with a CUDA runtime is installed.</p>