PyTorch installation with GPU support on Ubuntu

rynczakd: <p>While installing PyTorch with GPU support on Ubuntu (22.04 LTS), I ran into a few unknowns.</p>
<p>First of all, I checked that I have installed NVIDIA drivers using nvidia-smi command.<br>
What I got as a result was a table in which I found: NVIDIA-SMI 535.154.05 / Driver Version: 535.154.05 / CUDA Version 12.2.<br>
It shows that I have installed the drivers for the GPU.</p>
<p>Then, I checked that I have CUDA installed using nvcc --version command and I got: Build cuda_11.5.r11.5/compiler, so it also means that I have CUDA installed.</p>
<p>Now I want to install PyTorch using the instructions on the official site and here is the first question:</p>
<ol>
<li>Which Compute Platform should I choose? On the official PyTorch site I can choose 11.8 and 12.1, but I have CUDA 11.5 installed. What is the relation between CUDA Version (12.2) obtained from nvidia-smi, CUDA 11.5 obtained from nvcc --version and CUDA version given in PyTorch installation website?</li>
</ol>
<p>And I have few question about general PyTorch installation:</p>
<ol start="2">
<li>Installing PyTorch from the command below will make me have PyTorch installed along with the CUDA drivers? Can I use this command without having CUDA drivers installed before?</li>
</ol>
<pre><code class="lang-auto">conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

</code></pre>
<ol start="3">
<li>
<p>Assuming I don’t have NVIDIA and CUDA drivers installed what steps should I follow before installing PyTorch? What are the correct steps to follow in general to install PyTorch correctly? Should I install NVIDIA GPU Drivers, then install cuDNN, then install CUDA Toolkt and then finally install PyTorch?</p>
</li>
<li>
<p>What we need cuDNN and CUDA Toolkit for in terms of using PyTorch?</p>
</li>
<li>
<p>What is the difference between installing PyTorch using conda and pip? Both can install drivers for my local computer?</p>
</li>
<li>
<p>After installing PyTorch I found that I have different version of CUDA in my computer. nvcc --version shows 11.5, but torch.version.cuda shows 12.1. What does this difference come from and what I can do with that issue? Does PyTorch use locally installed CUDA?</p>
</li>
</ol>

ptrblck: <aside class="quote no-group" data-username="rynczakd" data-post="1" data-topic="196350">
<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/rynczakd/48/60208_2.png" class="avatar"> rynczakd:</div>
<blockquote>
<p>Then, I checked that I have CUDA installed using nvcc --version command and I got: Build cuda_11.5.r11.5/compiler, so it also means that I have CUDA installed.</p>
</blockquote>
</aside>
<p>This won’t matter as PyTorch ships with its own CUDA runtime dependencies and your locally installed CUDA toolkit will be used if you are building PyTorch from source or a custom CUDA extension.</p>
<aside class="quote no-group" data-username="rynczakd" data-post="1" data-topic="196350">
<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/rynczakd/48/60208_2.png" class="avatar"> rynczakd:</div>
<blockquote>
<p>Which Compute Platform should I choose?</p>
</blockquote>
</aside>
<p>I would recommend the latest CUDA toolkit (currently 12.1) as long as it’s compatible with your NVIDIA driver. Again, the locally CUDA toolkit doesn’t matter.</p>
<aside class="quote no-group" data-username="rynczakd" data-post="1" data-topic="196350">
<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/rynczakd/48/60208_2.png" class="avatar"> rynczakd:</div>
<blockquote>
<p>Installing PyTorch from the command below will make me have PyTorch installed along with the CUDA drivers?</p>
</blockquote>
</aside>
<p>No, you need to install the NVIDIA driver yourself. The PyTorch binaries ship with CUDA runtime libraries, cuDNN, NCCL, etc.</p>
<aside class="quote no-group" data-username="rynczakd" data-post="1" data-topic="196350">
<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/rynczakd/48/60208_2.png" class="avatar"> rynczakd:</div>
<blockquote>
<p>Can I use this command without having CUDA drivers installed before?</p>
</blockquote>
</aside>
<p>No, you need to install an NVIDIA driver, but don’t need a CUDA toolkit.</p>
<aside class="quote no-group" data-username="rynczakd" data-post="1" data-topic="196350">
<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/rynczakd/48/60208_2.png" class="avatar"> rynczakd:</div>
<blockquote>
<p>Assuming I don’t have NVIDIA and CUDA drivers installed what steps should I follow before installing PyTorch?</p>
</blockquote>
</aside>
<p>Install an NVIDIA driver, then run <code>pip install torch</code>, which is enough to execute PyTorch workloads on your GPU.</p>
<p>I don’t respond to the other questions separately as they mainly target the locally installed CUDA toolkit which won’t be used if you install the binaries.</p>

Mohamed_Mahmoud_Mous: <p>hello rynczakd  i have this problem can you give me your solution</p>