TensorFlow Setup on Apple Silicon Mac (M1, M1 Pro, M1 Max)

YASH GUPTA
2 min readJul 17, 2023

--

If you’re looking to get started with TensorFlow on your shiny new M1, M1 Pro, M1 Max, M1 Ultra, or M2 Mac, I’ve got you covered! 🚀 Here’s a simple step-by-step guide to get you up and running in no time(Github):

  1. Download and install Homebrew from https://brew.sh (follow the instructions after installation).
  2. Get Miniforge3, the Conda installer for macOS arm64 chips (M1, M1 Pro, M1 Max). You can download it [here](https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh).
  3. Install Miniforge3 by running the following commands in Terminal:
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate

4. Restart Terminal.
5. Create a directory for your TensorFlow environment:

mkdir tensorflow-test
cd tensorflow-test

6. Set up a Conda environment and activate it:

conda create --prefix ./env python
conda activate ./env

7. Install TensorFlow dependencies from the Apple Conda channel:

conda install -c apple tensorflow-deps

8. Install base TensorFlow (Apple’s fork) and leverage Apple Metal for GPU acceleration:

python -m pip install tensorflow-macos
python -m pip install tensorflow-metal

9. (Optional) Install TensorFlow Datasets for running included benchmarks:

python -m pip install tensorflow-datasets

10. Install common data science packages:

conda install jupyter pandas numpy matplotlib scikit-learn

11. Launch Jupyter Notebook:

jupyter notebook

12. Import dependencies and check TensorFlow version/GPU access in the first cell:

import numpy as np
import pandas as pd
import sklearn
import tensorflow as tf
import matplotlib.pyplot as plt

# Check for TensorFlow GPU access
print(f"TensorFlow has access to the following devices:\n{tf.config.list_physical_devices()}")

# See TensorFlow version
print(f"TensorFlow version: {tf.__version__}")

13. If it all worked, you should see something like (Expected Output):

TensorFlow has access to the following devices:
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU'),
PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
TensorFlow version: 2.5.0

That’s it! You’re all set to dive into the exciting world of TensorFlow on your M1 Mac. Feel free to explore the provided notebooks and compare your results with the benchmarks. Happy coding! 💻🎉

For more detailed checkout this : Github

#TensorFlow #M1Mac #MachineLearning #AppleSilicon

--

--