Is it required to set-up CUDA on PC before installing CUDA enabled pytorch?

n0obcoder: <p>Can I simply go to pytorch website and use the following link to download a CUDA enabled pytorch library ? Or do i have to set up the CUDA on my device first, before installing the  CUDA enabled pytorch ?<br>
<code>pip3 install torch===1.3.0 torchvision===0.4.1 -f https://download.pytorch.org/whl/torch_stable.html</code></p>

albanD: <p>Hi,</p>
<p>You don’t need to have cuda to <strong>install</strong> the cuda-enabled pytorch package but you need cuda to <strong>use</strong> it.<br>
We do not ship cuda with pytorch as it is a very big library.</p>

n0obcoder: <p>thanks for the reply <a class="mention" href="/u/alband">@albanD</a> !<img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>
<p>so i guess that the point that you are trying to make here is that i can install CUDA enabled pytorch without having to  install CUDA… is just that pytorch wouldnt use the GPU that way. Eventually, for  pytorch to make use of the GPU, i will have to install CUDA.</p>
<p>pls correct me if i am wrong</p>

albanD: <p>That’s the right idea.<br>
You can use a cuda build on cpu even without cuda. But to be able to use the GPU, you will need to install CUDA.</p>

n0obcoder: <p>thanks a lot <a class="mention" href="/u/alband">@albanD</a> for helping me out ! <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=9" title=":smiley:" class="emoji" alt=":smiley:"></p>

n0obcoder: <p>ok so i did install torch using the following command</p>
<pre><code class="lang-auto">conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
</code></pre>
<p>but as expected, I am not able to use the GPU<br>
So i want to know what exactly do i need to do so that<br>
‘torch.cuda.is_available()’<br>
returns me <strong>True</strong> ?</p>

albanD: <p>Do you have your gpu properly installed?<br>
Do you have recent nvidia drivers for it?<br>
What is the exact error message that you get when doing <code>torch.rand(10).cuda()</code> ?</p>

n0obcoder: <p>hi  <a class="mention" href="/u/alband">@albanD</a> !<br>
How do i check if my GPU is properly installed ? Or how do i chekc if i have the NVIDIA drivers for it ? Can you please help me with all this…? Its all a little confusing : o</p>
<p>And I did try runing the code that you wanted me to run… Following is its error message</p>
<pre><code class="lang-auto">The NVIDIA driver on your system is too old (found version 10000).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.
</code></pre>

albanD: <p>In a command line, you can run <code>nvidia-smi</code> that should show you all your GPUs.<br>
For the driver, you can try and run the samples that are given with the CUDA install.<br>
Given the error message, the problems seems to be that the nvidia driver (gpu driver) is too old. You might want to update that.</p>

n0obcoder: <p>i solved it. and yes you were right <a class="mention" href="/u/alband">@albanD</a> ! <img src="https://discuss.pytorch.org/images/emoji/apple/smiley.png?v=9" title=":smiley:" class="emoji" alt=":smiley:"><br>
my nvidia drivers were old. i just updated the nvidia drivers by going to Start&gt;Device Manager&gt;Display adapters&gt; select_ur_gpu &gt;Right Click&gt;Update Driver</p>
<p>Thanks a lot <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

benjiebob: <p>Just curious, is the same true for cuDNN? I.e. does a user need to manually install cuDNN before CUDA enabled PyTorch will work or does the PyTorch installer do this for you?</p>

ptrblck: <p>The conda binaries and pip wheels ship also with the cudnn library so you don’t need to install it (same for NCCL).</p>

khayrulB: <p>Hello, I was following your discussion.  I have updated GPU driver. Installed driver shows CUDA 11.2 .<br>
While installing pytorch<br>
conda install pytorch torchvision cudatoolkit=11.2 -c pytorch, it throws package not found error. Although  i could install cudaroolkit=10.1 without error, I am still NOT able to use GPU with pyrorch. With the suggested [torch.rand(10).cuda()]  I get [AssertionError: Torch not compiled with CUDA enabled]  I donot understand where is the problem .   I am wondering if I need update system path with for the cuda 10.1 ?</p>

khayrulB: <p>Hello albanD,  I have updated GPU driver to the latest one 461.40. It shows  the required CUDA version is 11.2. I am confused with the following.</p>
<ol>
<li>Should I need to install CUDA11.2 and set path accordingly before running conda pytorch torchvision…?</li>
<li>Can I install any lower version of CUDA for the updated GPU driver?</li>
</ol>
<p>thank you.</p>

ptrblck: <p>The conda binaries and pip wheels are not yet built with <code>cudatoolkit=11.2</code> and you would have to use 9.2, 10.1, 10.2, or 11.0 as given in the <a href="https://pytorch.org/get-started/locally/">install instructions</a>.</p>
<p>Since these binaries ship with their own CUDA runtime, you would only need a local NVIDIA driver corresponding to the CUDA runtime you are selecting.<br>
In case you want to build PyTorch from source or any custom CUDA extensions, you should install a matching local CUDA toolkit.</p>

Nikhil_Chhabra: <p>Hi<br>
I am not sure if this discussion is still valid.<br>
I have a confusion whether in 2021 we still need to have CUDA toolkit installed in system before we install pytorch gpu version or does conda installs the toolkit as well by “conda install cudatoolkit=11.1” ?<br>
And if conda installs the toolkit does pip3 also does that? even though toolkit is not explicitly mentioned in the following command:<br>
“pip3 install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f <a href="https://download.pytorch.org/whl/torch_stable.html" rel="noopener nofollow ugc">https://download.pytorch.org/whl/torch_stable.html</a>”</p>

ptrblck: <aside class="quote no-group" data-username="Nikhil_Chhabra" data-post="16" data-topic="60181">
<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/nikhil_chhabra/48/14634_2.png" class="avatar"> Nikhil_Chhabra:</div>
<blockquote>
<p>I have a confusion whether in 2021 we still need to have CUDA toolkit installed in system before we install pytorch gpu version</p>
</blockquote>
</aside>
<p>This wasn’t the case before and you would still only need to install the NVIDIA driver to run GPU workloads using the PyTorch binaries with the appropriately specified <code>cudatoolkit</code> version.<br>
One limitation to this is that you would still need a locally installed CUDA toolkit to build custom CUDA extensions or PyTorch from source.</p>
<aside class="quote no-group" data-username="Nikhil_Chhabra" data-post="16" data-topic="60181">
<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/nikhil_chhabra/48/14634_2.png" class="avatar"> Nikhil_Chhabra:</div>
<blockquote>
<p>And if conda installs the toolkit does pip3 also does that?</p>
</blockquote>
</aside>
<p>Yes, but the pip wheels are statically linking it instead of depending on the conda <code>cudatoolkit</code>.</p>

Nikhil_Chhabra: <p>I understood that we nvidia drivers.<br>
I understood that cudnn and nvcc comes with pytorch installation.<br>
I understood that cuda version that I specify should be supported by the nvidia driver.</p>
<p>What is still not 100% clear is:<br>
Do we need to install Cuda toolkit separately or is it taken care by the pip3/conda ?</p>
<p>Lets ignore the part of building custom cuda extensions and pytorch from source.</p>

ptrblck: <aside class="quote no-group" data-username="Nikhil_Chhabra" data-post="18" data-topic="60181">
<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/nikhil_chhabra/48/14634_2.png" class="avatar"> Nikhil_Chhabra:</div>
<blockquote>
<p>Do we need to install Cuda toolkit separately or is it taken care by the pip3/conda ?</p>
</blockquote>
</aside>
<p>No CUDA <em>toolkit</em> will be installed using the current binaries, but the CUDA <em>runtime</em>, which explains why you could execute GPU workloads, but not build anything from source.</p>

Yuheng_Zhi: <p>Is it still true as of today (Oct 2021)? I am using torch 1.9. It looks like my torch installation using <code>pip install</code> comes with a CUDA version different from the one on nvidia-smi.</p>