How to test if installed torch is supported with CUDA

keanudicap: <p>I am using windows and pycharm, Pytorch is installed by annaconda3 (conda install -c perterjc123 pytorch). My python is 3.6.2 and pytorch installed is pytorch 0.3.0.</p>
<p>I am trying to rerun this repository (<a href="https://github.com/vvanirudh/srnn-pytorch" rel="nofollow noopener">https://github.com/vvanirudh/srnn-pytorch</a>) but found the error “Torch not compiled with CUDA enabled”</p>
<p>I have no idea is my pytorch is not supported with CUDA or there is something I should change in the code.</p>

antspy: <p>Do you have an NVIDIA GPU? Have you installed cuda on this NVIDIA GPU? If not, then pytorch will not find cuda. It is not mandatory, you can use your cpu instead. Every time you see in the code something like <code>tensor = tensor.cuda()</code>, simply remove that line and the tensor will reside on the CPU. The problem is that it will be incredibly slow to the point of being unusable.</p>
<p>You can also explicitly check by doing<br>
<code>torch.cuda.is_available()</code><br>
If it returns False, it means that CUDA is not available on your machine</p>

keanudicap: <p>Great thanks to your reply. I had GTX 1070 graphic card and it has GPU.</p>
<p>I followed the link to install cudatoolkit in python (<a href="https://developer.nvidia.com/how-to-cuda-python" rel="nofollow noopener">https://developer.nvidia.com/how-to-cuda-python</a>) and run the sample test successfully. However, torch.cuda.is_available() still shows False. It will be appreciated If you could tell me how to make CUDA work with torch.</p>

antspy: <p>Which OS are you using?</p>
<p>Why did you use that command to install torch? On the website it’s written you should use</p>
<p><code>conda install pytorch torchvision cuda90 -c pytorch</code></p>
<p>for CUDA 9.0, otherwise<br>
<code>conda install pytorch torchvision -c pytorch</code></p>
<p>Try removing it and installing it with these two commands. Otherwise you can try installing from source, check out the instructions on the pytorch github page.</p>

Royi: <p>Does PyTorch uses it own CUDA or uses the system installed CUDA?</p>

keanudicap: <p>As I said in the post, I use Windows with Annaconda3. Thanks for the two command lines. However, the package is not for Windows (package missing in current channels).</p>

antspy: <p>Ah, I see. Then have you tried installing it from source? Where did you find the windows package? Maybe you can ask the author to see if there is CUDA support</p>

keanudicap: <p>I just made it work now! I checked the developed post (<a href="https://github.com/pytorch/pytorch/issues/494" rel="nofollow noopener">https://github.com/pytorch/pytorch/issues/494</a>), and some guy made it work and I installed it from his source. Only cuda80 works in my desktop. And also thanks for your reply!</p>

Royi: <p>When installing PyTorch on Windows, should I install CUDA for nVidia site or it will be installed by <code>pip</code> installer?</p>
<p>I’m using Windows 10 (Installing PyTorch 0.4.1 on Windows 10 [WinPython]).</p>

jmandivarapu1: <pre><code class="lang-auto">pip install http://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl 
pip install torchvision
</code></pre>
<p>just pip will do the job</p>

Royi: <p>I’m not sure you’re right.<br>
If the user didn’t install system wide CUDA it seems it won’t work.</p>
<p>I couldn’t get official answer whether the <code>pip</code> install should take care of the CUDA or not.</p>

peterjc123: <p>Yes, you should install at least one system-wide CUDA installation on Windows when you use the GPU package. It’s recommended that you install the same version of CUDA that PyTorch compiles with. It will work even when the two versions mismatch. But you’ll then have to pay attention to the version of the GPU drivers.</p>
<p>Does PyTorch uses it own CUDA or uses the system installed CUDA?<br>
Well, it uses both the local and the system-wide CUDA library on Windows, the system part is <code>nvcuda.dll</code> and <code>nvfatbinaryloader.dll</code>. They are located in the <code>%systemroot%</code>, so I’m afraid we could not put them in the package due to some potential permission issues. The reason why we use the local CUDA installation is to prevent dll load failure. e.g. Some users don’t have CUDNN installed. I don’t think the missing of any optional CUDA dependency should be a barrier to use our package on Windows.</p>
<p>Should <code>pip</code>  install s take care of the CUDA or not?<br>
No, at least the answer is no on Windows. We don’t use pip to install CUDA on Windows. We just use <code>pip</code> to select the package you want. For most users, it may be no differences using cuda80/cuda90. But if you are using some new or legacy cards, then you can only use specific CUDA distributions.</p>

Royi: <p>I’m not sure I understood all.<br>
Could we get away with installing the CUDA Toolkit on Windows and have all installed by <code>pip</code> only for PyTorch?</p>
<p>I don’t need CUDA on my computer besides for PyTorch so I’d be happy if PyTorch could be independent and self sustained (All its dependencies supplied in the <code>pip</code> downloaded).</p>

dhpollack: <p>Once you install cuda, a quick way to test if CUDA is available is using the line below</p>
<pre><code class="lang-auto">python -c 'import torch; print(torch.cuda.is_available())'
</code></pre>

peterjc123: <p>That’s nearly an impossible task. Did you read my post? Some DLLs are installed to the system directory. <code>pip</code> or any python package cannot do this. Because there are permission issues.</p>

Royi: <p><a class="mention" href="/u/peterjc123">@peterjc123</a>, couldn’t we put the DLL’s in other folders on the path?<br>
Like those dedicated to Python?</p>

peterjc123: <p>Well, I don’t know exactly the answer. Because I have never tried this before. But according to some posts, these two files will get updated with the Graphics driver. So the problem will become a little bit complex. For users that don’t have CUDA installed, I just don’t know if the DLLs will still work when drivers get updated. But we could try your suggestion because it doesn’t affect the users that have CUDA installed. See <a href="https://docs.microsoft.com/en-us/windows/desktop/dlls/dynamic-link-library-search-order" rel="nofollow noopener">document</a> from MSDN. Anyway, thanks for your suggestion.</p>

Royi: <p>Yep,<br>
I think it is the right policy to take.<br>
First try to make it work out of the box independent of anything.<br>
If it works, you reduced the the level of frustration for new users.</p>
<p>In case of any issue with CUDA still the first step would be - Install the latest CUDA drivers.</p>
<p>Thank You.</p>

Torch_tracker: <p>I tried everything to only the following steps works: The cuda 10 is too new for my graphic card.</p>
<p>(1)go to previous version of cuda &amp; pytorch here:<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://pytorch.org/favicon.ico?" class="site-icon" width="16" height="16">
      <a href="https://pytorch.org/get-started/previous-versions/" target="_blank" rel="nofollow noopener">pytorch.org</a>
  </header>
  <article class="onebox-body">
    <img src="https://pytorch.org/assets/images/pytorch-logo.png" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://pytorch.org/get-started/previous-versions/" target="_blank" rel="nofollow noopener">PyTorch</a></h3>

<p>An open source deep learning platform that provides a seamless path from research prototyping to production deployment.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
(2)following the page instruction and download *.whl file suitable for my python version and platform. for me it’s python 3.6 , windows<br>
(3)install *.whl file<br>
(4)test if torch.cuda.is_available()  returns True</p>
<p>I am running windows 10 with Nvidia GTX 1070</p>

ptrblck: <p>CUDA10 supports the GTX1070. Which CUDA version did you install in the end?</p>