This is a step-by-step guide for people who want to install Tensorflow modules on M1 Mac. You can now leverage Apple’s tensorflow-metal PluggableDevice in TensorFlow v2.5 for accelerated training on Mac GPUs directly with Metal
Reference Articles: How To Install TensorFlow on M1 Mac (The Easy Way) | by Prabhat Kumar Sahu | Medium Tensorflow Plugin - Metal - Apple Developer
Go to the website The Missing Package Manager for macOS (or Linux) — Homebrew, copy the following into terminal:
xcode-select --install
Download “Conda env” from the link, drag it to your download folder Tensorflow Plugin - Metal - Apple Developer
Follow the instructions on the web: copy the codes into terminal:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
Keep pressing yes/return to proceed with the installation, until it ask you “Do you wish the installer to initialize Miniforge3?” I typed no as I don’t want it to initialize every time.
source ~/miniforge3/bin/activate
conda install -c apple tensorflow-deps
python -m pip install tensorflow-macos
python -m pip install tensorflow-metal
conda install -c conda-forge -y pandas jupyter
conda install numpy
(At a later stage it may complain not having NumPy so we can install it beforehand)
jupyter notebook
In the notebook, try the following:
import tensorflow as tf
print(“Num GPUs Available: “, len(tf.config.experimental.list_physical_devices(‘GPU’)))
It should not return any error ✅✅✅
Remember to activate this environment everytime you wanted to use tensorflow, Using the default one with Anaconda will always return me a dead kernel once I started to import tensorflow in Jupiter notebook
source ~/miniforge3/bin/activate jupiter notebook
You can always check the python and see which direcotry it's pointing. I have Anaconda3 to initialize everytime and it's required to activate miniforge3 to get tensorflow working