Member-only story
How to Install PyTorch on Apple M1-series
Including M1 Macbook, and some tips for a smoother installation
When Apple announced the release of the new Apple Silicon M1 Macbook, it took the ML community by surprise. The first thing that all data scientists thought is whether or not there was any potential in moving their workspace to MacOS.
Of course, such a move would make sense if at the very least 2 of the most popular data science frameworks, Tensorflow and Pytorch, would be compatible with the new processor. As far as Tensorflow is concerned, a lot of progress has been made, both by the community and Apple. In addition, Apple has released the new Metal plugin, which enables Tensorflow to utilize the GPU via the TensorFlow-metal PluggableDevice.
You can access all the articles in the “Setup Apple M1 for Deep Learning” series from here, including the guide on how to install Tensorflow on Mac M1.
Pytorch was somewhat left behind in terms of compatibility, however, you are now able to install Pytorch natively on M1 MacBooks. Here’s how to do it:
Note: If you have already installed Tensorflow, the first 2 steps can be skipped.
Step 1: Install Xcode
Some of the M1 Macbooks have Xcode preinstalled. If not, it can easily be downloaded from the App Store. Then, install the Xcode Command Line Tools using this command:
$ xcode-select --install
Step 2: Install MiniForge
Essentially, MiniForge is a conda installer, comparable with MiniConda. One of its greatest advantages is its compatibility with MacOS, including the M1 devices. To download it, go to this page, choose the installer for Apple Silicon and execute:
$ bash Miniforge3-MacOSX-arm64.sh
If you already have a pre-existing conda distribution, e.g. Anaconda or MiniConda, there is no need to uninstall it in order to use MiniForge. For those familiar with the conda ecosystem, only one conda distro can be “functional” at a given time. Check this article to learn how to manage effectively many conda distributions simultaneously!