Check if pytorch is using metal on macbook

sojohan: <p>Hi Experts</p>
<p>Saw the news regarding pytorch to use Metal as backend:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/">
  <header class="source">
      <img src="https://pytorch.org/favicon.ico?" class="site-icon" width="32" height="32">

      <a href="https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/" target="_blank" rel="noopener nofollow ugc">pytorch.org</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/388;"><img src="https://pytorch.org//assets/images/METAPT-002-BarGraph-02-static.png" class="thumbnail" width="690" height="388"></div>

<h3><a href="https://pytorch.org/blog/introducing-accelerated-pytorch-training-on-mac/" target="_blank" rel="noopener nofollow ugc">Introducing Accelerated PyTorch Training on Mac</a></h3>

  <p>In collaboration with the Metal engineering team at Apple, we are excited to announce support for GPU-accelerated PyTorch training on Mac. Until now, PyTorch training on Mac only leveraged the CPU, but with the upcoming  PyTorch v1.12 release,...</p>


  </article>

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

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

<p>My question is if there is a way (command), so can check that pytorch is using the new backend?</p>
<p>Thanks<br>
sojohan</p>

psobolewskiPhD: <p>You need to install a nightly, it’s not released yet.<br>
Then you can try this simple example:<br>
<a href="https://pytorch.org/docs/master/notes/mps.html" class="onebox" target="_blank" rel="noopener nofollow ugc">https://pytorch.org/docs/master/notes/mps.html</a></p>
<p>Be aware that many ops are not implemented yet, it’s definitely alpha status!</p>

sojohan: <p>Thanks Peter for quick reply.</p>
<p>I did install the preview (nightly) build and then I tried your script and got:</p>
<p>print(torch.backends.mps.is_built())<br>
FALSE</p>
<p>print(torch.backends.mps.is_available())<br>
FALSE</p>
<p>My macbook is new and runs mac os 12.3.1 and I can see that metal is installed.</p>
<p>Do you know how solve this?<br>
Thanks Sojohan</p>

psobolewskiPhD: <p>Are you in an arm64 native python environment? or emulated x86?<br>
You need to ensure you’re using an arm64 (apple silicon m1) native python environment.<br>
The easiest IMO is to use conda-forge to get setup:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://github.com/conda-forge/miniforge">
  <header class="source">
      <img src="https://github.githubassets.com/favicons/favicon.svg" class="site-icon" width="16" height="16">

      <a href="https://github.com/conda-forge/miniforge" target="_blank" rel="noopener nofollow ugc">GitHub</a>
  </header>

  <article class="onebox-body">
    <div class="aspect-image" style="--aspect-ratio:690/345;"><img src="https://opengraph.githubassets.com/2f6835903ae673efb32826e5ce5f2d22a0da363f9516a899362a0ee8fafee6c7/conda-forge/miniforge" class="thumbnail" width="690" height="345"></div>

<h3><a href="https://github.com/conda-forge/miniforge" target="_blank" rel="noopener nofollow ugc">GitHub - conda-forge/miniforge: A conda-forge distribution.</a></h3>

  <p>A conda-forge distribution. Contribute to conda-forge/miniforge development by creating an account on GitHub.</p>


  </article>

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

  <div style="clear: both"></div>
</aside>
<p>
(this is also encouraged by Apple for getting tensorflow-metal working).</p>