Best practices for setting up Fastai on Mackbook Pro with M1 Max Chip

Hi,

I recently got the MacBook Pro with M1 Max chip :star_struck:. I’d like to have local Fastai installed on the system for quick prototyping. What is the best practice of setting up the Fastai.

Shall I install Fastai directly on the Mac OS or use virtual platforms like docker? Any ideas, hints or links to get Fastai configured on the MacBook Pro with apple chip from the past experience will be much appreciated.

Thanks in advance

Kind regards,
Bilal

4 Likes

Hi, I just installed fastai on macbook with M1 Pro by running

mamba create -n fastai
mamba activate fastai
mamba install -c fastchan fastai

Now in Python I see that torch.backends.mps.is_available() is True and I can set models to device like .to('cpu') or .to('mps')

Let me know if you are using M1 GPU in your training

1 Like

Hi Kasiannenko,

It worked for me as you said so no need for additional configs. I tried running a model using mps and it is training faster than cpu. Cool.

Thanks.

1 Like

For those using pip, pip install fastai also works.

1 Like

I’ve spent A LOT of time trying to get my M1 Mac working with the fast.ai course using mps…

Had different breakages at Lesson 1, 2 and 4 sadly.

Issues with versions mostly around protobuf, pytorch, python etc.

My solution for the time being is to resign and say that Macbook’s aren’t currently the ideal machine for the fast.ai course (and tbh probably DL) → currently using VSCode with remote environment in Paperspace. Seems to work pretty well now not dealing with setup issues and hoping I can focus now on learning vs. installing dependencies haha.

For anyone else who is interested, it’s super easy - just go here: Remote Jupyter Kernel | Paperspace

2 Likes

Hello,

I am also using a MacBook Pro with Apple M1 Pro Chip, and I still cannot find out a solution to make that working properly. Every time I am trying to change the device to mps, I get no error but whenever I run a cell after having changed the device, I get the following message from Jupyterlab: "Kernel Restarting: The kernel for <jupyter_notebook_name> appears to have died. It will restart automatically.
".

Do you have any information about that? Any link to share that could be useful? I tried to gather as much information as possible until now but still unable to make things working.

Hello, everyone, my first post here :wave:. I got the course setup to work quite nicely on my M1, let me summarize what worked for me as of October 2023 (this setup is pip only, no conda / no mamba):

  • install Python from the official website
  • use pip and virtualenv to create a hermetic environment for the project
  • install pytorch from the official website using pip, then the rest of the packages needed

This seems to work pretty much out of the box and with GPU acceleration (which was added in pytorch ~1 year ago), save for the need to set PYTORCH_ENABLE_MPS_FALLBACK=1 when starting jupyter.

I wrote down full notes on this setup on my blog, check them out if anyone wants more detail.

PS This course is fantastic, thank you to Jeremy and the entire fastai community :clap: !