M1 Tensorflow

GPU accelerated TensorFlow on M1

See here for the official documentation.

Table of contents
  1. Install Miniforge
  2. Install TensorFlow dependencies
  3. Install base TensorFlow and tensorflow-metal
  4. To upgrade to a new TensorFlow version

Install Miniforge

Download and install Miniforge3 conda:

curl -L -O https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh

chmod +x Miniforge3-MacOSX-arm64.sh
sh Miniforge3-MacOSX-arm64.sh

# Optional
conda config --set auto_activate_base false

For information on conda see here.

Installing Miniconda3 macOS Apple M1 64-bit bash (Py38 conda 4.10.1 2021-11-08) did not work. Miniforge’s arm64 was the only thing that worked.


Install TensorFlow dependencies

Create a new environment:

conda create -n tf-m1 python=3.9

You can use either Python 3.8 or 3.9.

Install tensorflow-deps:

conda install -c apple tensorflow-deps

Install base TensorFlow and tensorflow-metal

Making sure the environment is activated:

Check environment is indeed activated by which pip.
Especially if you’re doing it in a VSCode terminal.

pip install tensorflow-macos
pip install tensorflow-metal

To upgrade to a new TensorFlow version

From the official doc, the recommended way is:

# uninstall existing tensorflow-macos and tensorflow-metal
python -m pip uninstall tensorflow-macos
python -m pip uninstall tensorflow-metal
# Upgrade tensorflow-deps
conda install -c apple tensorflow-deps --force-reinstall
# or point to specific conda environment
conda install -c apple tensorflow-deps --force-reinstall -n my_env