Fastai on Apple M1

Hi all,
I’m new to fastai and managed to get Lesson 1 working in a Jupyter Notebook locally on my M1 Max. I thought I’d post the exact steps I took for other new folks like myself. Big thanks to @iTapAndroid for his post (would not have succeeded without it). Lesson 1 ran/trained locally in less than 8 seconds for me.

Versions:
macOS Monterey 12.6
32 G RAM
32 GPU
python 3.10.4
pytorch 1.12.1
fastai 2.7.9

  • Install Anaconda for M1 Anaconda Installer

  • (default install is $HOME/opt/anaconda3)

  • (Be sure to restart your terminal after installing)

  • Anaconda updates .bashrc so it may just work, however if you want…
    export PATH=$HOME/opt/anaconda3/bin:$PATH in my .profile

  • conda update -n base -c defaults conda

  • conda create -n fastai python=3.10.4

  • conda activate fastai

  • conda install -c fastchan fastai fastbook jupyterlab sentencepiece

  • (fastchan installs pytorch 1.10 by default so you’ll need to upgrade it)

  • conda install pytorch torchvision torchaudio -c pytorch

Make sure that you now have pytorch 1.12.1

You can use grep for this:


conda list | grep pytorch

After this I took the exact first lesson in Kaggle and replicated it in my local Jupyter Notebook.

Per @iTapAndroid
You must add the following at the top of your notebook:


import os

os.environ["OMP_NUM_THREADS"] = "1"

6 Likes