Running PyTorch, TensorFlow, and JAX on Mac with Apple Silicon: A How-To Guide

Posted by

How to run PyTorch, TensorFlow, and JAX on your Mac (Apple Silicon)

Running PyTorch, TensorFlow, and JAX on Mac (Apple Silicon)

If you have a Mac with Apple Silicon (M1 chip) and want to run machine learning libraries like PyTorch, TensorFlow, and JAX, you’ll need to follow a few steps to set up your environment.

1. Install Homebrew

Homebrew is a package manager for macOS that allows you to easily install and manage software packages. Open Terminal and run the following command to install Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

2. Install Miniforge

Miniforge is a distribution of Anaconda that is optimized for Apple Silicon. You can install Miniforge by running the following commands in Terminal:

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

3. Create a new conda environment

Once Miniforge is installed, create a new conda environment for running PyTorch, TensorFlow, and JAX:

conda create -n ml-env python
conda activate ml-env

4. Install PyTorch, TensorFlow, and JAX

Now you can install the machine learning libraries in your conda environment:

conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c pytorch
pip install tensorflow jax

5. Test your setup

Finally, you can test your setup by importing PyTorch, TensorFlow, and JAX in a Python script and running some basic examples to make sure everything is working correctly.

With these steps, you should be able to run PyTorch, TensorFlow, and JAX on your Mac with Apple Silicon. Happy coding!

0 0 votes
Article Rating

Leave a Reply

15 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@yuzaR-Data-Science
14 days ago

amazing stuff! you saved me a lot of frustration! thanks you soo much!

@ziweiyang2673
14 days ago

jax.random.PRNGKey generator seems does not compile properly on my M1 mac. My config is: jax-metal==0.0.3, jaxlib=0.4.10, jax==0.4.11, which is the suggested version from Apple. Did you face similar issue on M3?

@1sefirot9
14 days ago

TensorFlow won't work for most folks. Its support on mac metal is notoriously bad and outdated, there are plenty posts on StackOverflow and Reddit about this. You will have to manually match the versions of python and main libraries to have it work. Naive video…

@swapwarick
14 days ago

Wow now my office's M1 ultra will be useful to train LLM. Thanks

@cherdak_turista
14 days ago

Thank you for this video! For those, who wonder – on M1 Max 32gb RAM and 32 GPU cores – timings on CPU were 18ms (instead 14.4ms in video on M3 Max), but on GPU – 3.3ms – even slightly better.

@3a146
14 days ago

In fact Metal 3 runs on AMD GPU Intel Macs as well

@nexuslux
14 days ago

This is exactly the kind of thing I’m struggling with. For example, pyannote.audio for speaker segmentation and identification. It’s blazing fast using an Nvidia GPU… 1 min for 1 hour of audio. On Mac though? Horrendous. Basically 1 hour of audio takes 1 hour give or take to process. I’ve tried specifying MPS with PyTorch, and also looking at specialized models with MLX from Apple/hugging face. Any thoughts on this issue?

@geekyprogrammer4831
14 days ago

My Mac is M1 got it in 2021.

@adesojialu1051
14 days ago

Will this work on MacBook 2017?

@dmitrykomarov6152
14 days ago

Dear sir, may I kindly ask you which model of Mac are you using? in terms of chip specs 🙂
Thanks a lot for the video!

@kannansingaravelu
14 days ago

Nvidia RTX or Apple Silicon, which of these two is preferred for LLM applications?

@mike110111
14 days ago

I'm getting an error when trying to following your instructions: No matching distribution found for tensorflow-metal

@rivaldi7286
14 days ago

hey can u make tutorial how to install opencv library on mac? ive been trying and always failed.

@modoulaminceesay9211
14 days ago

This channel is underrated

@justinhj1
14 days ago

Thank you for the specific install instructions. Python dependencies can be so tricky, and as you pointed out official docs are often incomplete

15
0
Would love your thoughts, please comment.x
()
x