How to run torch with AMD gpu?

Asya: <p>I usually run my models on Nvidia GPU and I had no problem with torch detecting it.<br>
Now I have this GPU:</p>
<pre><code class="lang-auto">lspci | grep VGA
75eb:00:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Vega 10 [Radeon Instinct MI25 MxGPU]
</code></pre>
<p>and I’m trying to understand how to make it visible for torch?</p>
<pre><code class="lang-auto">import torch
torch.cuda.is_available()
False
</code></pre>
<p>how can I use it with torch?</p>

JuanFMontesinos: <p>I’d say it’s a bad decision as DL is dominated by Nvidia.</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://pytorch.org/blog/pytorch-for-amd-rocm-platform-now-available-as-python-package/">
  <header class="source">
      <img src="https://pytorch.org/favicon.ico?" class="site-icon" width="32" height="32">

      <a href="https://pytorch.org/blog/pytorch-for-amd-rocm-platform-now-available-as-python-package/" target="_blank" rel="noopener nofollow ugc">pytorch.org</a>
  </header>

  <article class="onebox-body">
    <img src="https://pytorch.org/assets/images/pytorch-logo.png" class="thumbnail onebox-avatar" width="500" height="500">

<h3><a href="https://pytorch.org/blog/pytorch-for-amd-rocm-platform-now-available-as-python-package/" target="_blank" rel="noopener nofollow ugc">PyTorch</a></h3>

  <p>An open source machine learning framework that accelerates the path from research prototyping to production deployment.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Here there is some info. Good luck!</p>

AlphaBetaGamma96: <p>CUDA is only available for NVIDIA devices. However, you can get GPU support via using ROCm. Just go to <a href="https://pytorch.org/get-started/locally/" rel="noopener nofollow ugc">getting started</a> and select the <code>ROCm</code> option rather than NVIDIA.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981.png" data-download-href="https://discuss.pytorch.org/uploads/default/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981_2_690x268.png" alt="image" data-base62-sha1="6CbtJJkuYZCqkEd2HHje13lxzbz" width="690" height="268" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/2/e/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981_2_690x268.png, https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/2/e/2e5e0e9195b2e2c7f6c29ad662d14f0c6087f981.png 2x" data-dominant-color="F4DAD6"><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">image</span><span class="informations">811×315 24.1 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>

Asya: <p>I tried rocm docker but what I can’t understand is how can I check that I am using gpu? with cuda I can do <code>torch.cuda.device_count()</code> but how can I do the same with ROCm?</p>

Asya: <p>and I also get this error when trying to check devices:</p>
<pre><code class="lang-auto">python -c 'import torch; print(torch.cuda.is_available());'
/opt/conda/lib/python3.7/site-packages/torch/cuda/__init__.py:82: 
UserWarning: HIP initialization: Unexpected error from hipGetDeviceCount(). 
Did you run some cuda functions before calling NumHipDevices() that might have already set an error? 
Error 101: hipErrorInvalidDevice (Triggered internally at  /var/lib/jenkins/pytorch/c10/hip/HIPFunctions.cpp:110.)
  return torch._C._cuda_getDeviceCount() &gt; 0
False
</code></pre>

AlphaBetaGamma96: <p>So it seems you should just be able to use the cuda equivalent commands and pytorch should know it’s using ROCm instead (see <a href="https://github.com/pytorch/pytorch/issues/10670" rel="noopener nofollow ugc">here</a>). You also might want to check if your AMD GPU is supported <a href="https://github.com/pytorch/pytorch/issues/55223" rel="noopener nofollow ugc">here</a>.</p>
<p>But it seems that PyTorch can’t see your AMD GPU.</p>

OCFormula: <p>Did you install ROCm?<br>
If ROCm is installed, torch.cuda.is_available() will return True.</p>