Installing Pytorch on M1 Macbook?

Sam_Lerman: <p>I haven’t been able to install Pytorch. When I try using pip3, I get this error due to building wheel for Numpy:</p>
<p><code>ERROR: Could not build wheels for numpy which use PEP 517 and cannot be installed directly</code></p>
<p>When I use the Apple version of NumPy that Tensorflow released, I need to use a virtual env. So I activate that env and run the pip3 install command and get this error:</p>
<p><code>ERROR: Command errored out with exit status 1:</code></p>

albanD: <p>Hi,</p>
<p>Is there more information with this error?<br>
I don’t think we have M1 binaries yet but building from source should work on master from what I can see. And if not, please report that so we can make sure to fix it.</p>

Sam_Lerman: <p>Yes ,installing from source worked. Is there a way I can also install torchvision?</p>

albanD: <p>Since there is no binary, I guess you can also install it from source the same way.<br>
If you encounter any issues with that, do report an issue on the torchvision repo!</p>

Sam_Lerman: <p>Sorry, this isn’t my forte. How do I install torchvision from source?<br>
Edit: Never mind, found the repo. Thanks for the help!</p>

Sam_Lerman: <p>Ah, it seems Pytorch didn’t install fully from source. I have the arm64 NumPy, but when I run Pytorch code that includes <code>torch.from_numpy()</code>, I get the following error:</p>
<p><code>RuntimeError: PyTorch was compiled without NumPy support</code></p>

albanD: <p>Are you sure that your numpy version was properly detected when torch was compiling?</p>

Sam_Lerman: <p>I’m not sure. I installed the numpy into the base Conda env and had that activated</p>

Suvarna_Kadam: <p>You may install tensorflow first by following instructions <a href="https://github.com/apple/tensorflow_macos" class="inline-onebox" rel="noopener nofollow ugc">GitHub - apple/tensorflow_macos: TensorFlow for macOS 11.0+ accelerated using Apple's ML Compute framework.</a>. This step should solve the NumPy issue.<br>
I followed instructions from <a href="https://www.youtube.com/watch?v=6W8pjnW65Q8" class="inline-onebox" rel="noopener nofollow ugc">How to install TensorFlow and NumPy on Apple Silicon (M1) - YouTube</a> and could get tensorflow installed.<br>
To install Pytorch with pip3, I enabled the terminal to run with Rosetta 2. For that, you need to right-click on the terminal app in Applications, then select ‘Get Info’ and select the option ‘Open using Rosetta’.<br>
After enabling the option,  launching terminal would automatically run all subsequent commands in Rosetta 2  and therefore commands that work for Intel-based Macs would work for M1 Mac. So you can simply install pytorch with <code>pip3 install torch</code> .<br>
I believe running it in Rosetta would not get you the optimum performance for the platform but it may help you to get started with at least using your M1 before PyTorch is compiled for apple chip.</p>

pannous: <p>Two months later: does it work now?</p>

111474: <p>I’m also waiting for the solution <img src="https://discuss.pytorch.org/images/emoji/apple/innocent.png?v=9" title=":innocent:" class="emoji" alt=":innocent:"></p>

111474: <aside class="onebox githubcommit">
  <header class="source">
      <a href="https://github.com/numpy/numpy/commit/0a8dca0632185058a4438f792cebf04321212da2" target="_blank" rel="noopener nofollow ugc">github.com/numpy/numpy</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Commit">
    <svg width="60" height="60" class="github-icon" viewbox="0 0 14 16" aria-hidden="true"><path d="M10.86 7c-.45-1.72-2-3-3.86-3-1.86 0-3.41 1.28-3.86 3H0v2h3.14c.45 1.72 2 3 3.86 3 1.86 0 3.41-1.28 3.86-3H14V7h-3.14zM7 10.2c-1.22 0-2.2-.98-2.2-2.2 0-1.22.98-2.2 2.2-2.2 1.22 0 2.2.98 2.2 2.2 0 1.22-.98 2.2-2.2 2.2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/numpy/numpy/commit/0a8dca0632185058a4438f792cebf04321212da2" target="_blank" rel="noopener nofollow ugc">18532: Fix the numpy Apple M1 build.</a>
    </h4>

    <div class="github-info">
      <div class="date">
        committed <span class="discourse-local-date" data-format="ll" data-date="2021-03-03" data-time="22:57:05" data-timezone="UTC">10:57PM - 03 Mar 21 UTC</span>
      </div>

      <div class="user">
        <a href="https://github.com/kulinseth" target="_blank" rel="noopener nofollow ugc">
          <img alt="kulinseth" src="https://avatars.githubusercontent.com/u/453004?v=4" class="onebox-avatar-inline" width="20" height="20">
          kulinseth
        </a>
        
      </div>

      <div class="lines" title="changed 1 files with 1 additions and 0 deletions">
        <a href="https://github.com/numpy/numpy/commit/0a8dca0632185058a4438f792cebf04321212da2" target="_blank" rel="noopener nofollow ugc">
          <span class="added">+1</span>
          <span class="removed">-0</span>
        </a>
      </div>
    </div>

  </div>
</div>


  <div class="github-row">
    <pre class="github-content" style="white-space: normal;">There was a build issue on numpy with M1:
AssertionError: would build wheel with unsupported tag ('cp39', 'cp39', 'macosx_11_0_universal2')
The issue was fixed...</pre>
  </div>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>