Skip to content

Instantly share code, notes, and snippets.

@kadereub
Last active February 4, 2022 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadereub/53923bd99c81a1a019450386126593e6 to your computer and use it in GitHub Desktop.
Save kadereub/53923bd99c81a1a019450386126593e6 to your computer and use it in GitHub Desktop.
This is a guide to setup & install `miniforge` and `PyTorch` on a Mac M1 Pro for some deep learning tasks

Installing Miniconda and PyTorch the Hard Way

This guide ensures the installation of Python (miniconda) and PyTorch runs using the Apple silicon on a M1 Pro (I know the M1 Max probably has no issues) - os specs:

    System Software Overview:

      System Version: macOS 12.1
      Kernel Version: Darwin 21.2.0
      Boot Volume: Macintosh HD
      Secure Virtual Memory: Enabled

Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: MacBookPro18,3
      Chip: Apple M1 Pro
      Total Number of Cores: 10 (8 performance and 2 efficiency)

Unfortunately this guide or this one did not work form me as homebrew kept on installing the Intel based miniconda, sure this will change soon!

Minconda setup

A lot of the steps is taken from here, which was very helpful!

  1. Don't use homebrew as currently it installs for the Intel platofrm, rather download the miniforge installation file for M1 architecture (below is the link).

https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh

  1. Make the downloaded miniforge installation file executable

chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh

  1. Install miniforge

sh ~/Downloads/Miniforge3-MacOSX-arm64.sh

  1. Close & open the terminal once installed - then check the platfrom by running conda info in the terminal you need to see osx-arm64
          conda version : 4.11.0
    conda-build version : not installed
         python version : 3.9.7.final.0
               platform : osx-arm64

PyTorch Setup

  1. Create a conda environment

conda create --name pytorch_env python=3.9

  1. Activate this environment and install pytorch and for my pursposes torchvision
conda activate pytorch_env
conda install -c pytorch pytorch torchvision
  1. Save this main.py file in a directory and run it locally

python main.py

If it works should see the Kind field in Activity monitor show Apple and not Intel

image

Common Errors Experienced

  • Intel MKL FATAL ERROR: Cannot load libmkl_core.dylib

This means you've installed an Intel based miniconda / miniforge - ensure that the installation .sh file from miniforge here has the arm64 extension.

  • from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION ImportError: cannot import name 'PILLOW_VERSION' from 'PIL

This is a strange torchvision issue, if you run conda list you will see your torch vision version is old

tk                        8.6.11               he1e0b03_1    conda-forge
torchvision               0.2.2                      py_3    pytorch

To fix this I needed to install version 0.11.2 to match my pytorch version of 1.10.2 so ran,

conda install torchvision==0.11.2 -c pytorch

see the torchvision repo for which version to match your pytorch installation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment