M2 installation

elcolie: <p>I am using OSX 13.2 on M2 chip, Python 3.11.0.<br>
I have followed the rosetta.</p><aside class="onebox stackexchange" data-onebox-src="https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in-executable">
  <header class="source">

      <a href="https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in-executable" target="_blank" rel="noopener nofollow ugc">apple.stackexchange.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://apple.stackexchange.com/users/990/jonas" target="_blank" rel="noopener nofollow ugc">
    <img alt="Jonas" src="https://www.gravatar.com/avatar/894e4c1f3bc33e5f9a5008d355287830?s=256&amp;d=identicon&amp;r=PG" class="thumbnail onebox-avatar" width="256" height="256">
  </a>

<h4>
  <a href="https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in-executable" target="_blank" rel="noopener nofollow ugc">zsh: bad CPU type in executable</a>
</h4>

<div class="tags">
  <strong>terminal, zsh, m1, apple-silicon</strong>
</div>

<div class="date">
  asked by
  
  <a href="https://apple.stackexchange.com/users/990/jonas" target="_blank" rel="noopener nofollow ugc">
    Jonas
  </a>
  on <a href="https://apple.stackexchange.com/questions/408375/zsh-bad-cpu-type-in-executable" target="_blank" rel="noopener nofollow ugc">06:43PM - 08 Dec 20 UTC</a>
</div>

  </article>

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

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

<p>In the official website it says I can use <code>pip install torch torchvision torchaudio</code><br>
But it does not work. It return error as follow.</p>
<pre><code class="lang-bash">ERROR: Could not find a version that satisfies the requirement torch (from versions: none)
ERROR: No matching distribution found for torch
</code></pre>
<p>When I try <code>nightly</code></p>
<pre><code class="lang-bash">❯ pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
Looking in indexes: https://pypi.org/simple, https://download.pytorch.org/whl/nightly/cpu
Collecting torch
  Using cached https://download.pytorch.org/whl/nightly/cpu/torch-2.0.0.dev20230205-cp311-none-macosx_10_9_x86_64.whl (139.0 MB)
ERROR: Could not find a version that satisfies the requirement torchvision (from versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3)
ERROR: No matching distribution found for torchvision
</code></pre>
<p>Branch: <code>nigthly</code><br>
cmd: <code>python setup.py develop</code></p>
<pre><code class="lang-bash">/Users/sarit/packages/pytorch/aten/src/ATen/native/metal/MetalDevice.h:40:2: error: "Metal is not available on the current platform."
#error "Metal is not available on the current platform."
 ^
1 error generated.
[14/876] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/autograd/engine.cpp.o
ninja: build stopped: subcommand failed.
</code></pre>
<p>How to install PyTorch with MPS enable?</p>

elcolie: <p>I must configure the <code>arch</code> when install the <code>Python</code>. In this case I am using <code>pyenv</code>.</p>
<ol>
<li><code>arch -arm64 pyenv install 3.11.1</code></li>
<li><code>pyenv virtualenv 3.11.1 artifact</code></li>
<li><code>pyenv local artifact</code></li>
<li><strong>pip install --pre torch torchvision torchaudio --index-url <a href="https://download.pytorch.org/whl/nightly/cpu" rel="noopener nofollow ugc">https://download.pytorch.org/whl/nightly/cpu</a></strong></li>
<li>Check in the shell</li>
</ol>
<pre><code class="lang-python">❯ python

Python 3.11.1 (main, Feb 6 2023, 14:02:26) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

&gt;&gt;&gt; import torch

&gt;&gt;&gt; torch.backends.mps.is_available()

True
</code></pre>