DEV Community

Cover image for Installing TensorFlow on M1 MacBook Air with GPU (Metal)
milindsoorya
milindsoorya

Posted on • Edited on • Originally published at milindsoorya.co.uk

Installing TensorFlow on M1 MacBook Air with GPU (Metal)

You can now leverage Apple’s tensorflow-metal PluggableDevice in TensorFlow v2.5 for accelerated training on Mac GPUs directly with Metal. Learn more here.

OS Requirements

macOS 12.0+ (latest beta)
Enter fullscreen mode Exit fullscreen mode

Currently Not Supported

Multi-GPU support
Acceleration for Intel GPUs
V1 TensorFlow Networks
Enter fullscreen mode Exit fullscreen mode

Table of contents

  1. What is tensorflow?
  2. What is miniforge?
  3. What is miniconda?
  4. Uninstalling existing anaconda/conda from macOS
    1. Install the Anaconda-Clean package
    2. Remove all Anaconda-related files
    3. Remove entire anaconda installation directory
  5. Step 1: Install Miniforge
    1. Download and install Conda env
    2. Create an anaconda environment
    3. Activate the environment
  6. Step 2: Install TensorFlow
    1. Install TensorFlow dependencies
    2. Install base TensorFlow
    3. Install tensorflow-metal plugin
    4. Install common Data Science packages
  7. References
  8. Related Articles

What is tensorflow?

TensorFlow is open source deep learning framework created by developers at Google and released in 2015. It is actively used at Google both for research and production needs.

Please check references if you would like to read more about TensorFlow and other popular deep learning libraries.

What is miniforge?

Miniforge is the community (conda-forge) driven
minimalistic conda installer. Subsequent package installations come thus from
conda-forge channel.

What is miniconda?

Miniconda is the Anaconda (company) driven minimalistic
conda installer. Subsequent package installations come from the anaconda
channels (default or otherwise).

Note: Uninstall Anaconda/Anaconda Navigator and other related previously installed version of conda-based installations. Anaconda and Miniforge cannot co-exist together.

Uninstalling existing anaconda/conda from macOS

Install the Anaconda-Clean package from Anaconda Prompt

conda install anaconda-clean
Enter fullscreen mode Exit fullscreen mode

Remove all Anaconda-related files and directories without being prompted to delete each one

anaconda-clean --yes
Enter fullscreen mode Exit fullscreen mode

Remove entire anaconda installation directory from macOS

which anaconda
Enter fullscreen mode Exit fullscreen mode

After running above command you should see the directory where anaconda is installed.

now recursively remove that folder

rm -rf YOUR-ANACONDA-DIRECTORY
Enter fullscreen mode Exit fullscreen mode

Step 1: Install Miniforge

Please note that this tutorial is for arm64 : Apple Silicon

Download and install Conda env

chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activate
Enter fullscreen mode Exit fullscreen mode

Create an anaconda environment

conda create -n tf python=3.8
Enter fullscreen mode Exit fullscreen mode

Activate the environment

conda activate tf
Enter fullscreen mode Exit fullscreen mode

Step 2: Install TensorFlow

Install TensorFlow dependencies

conda install -c apple tensorflow-deps
Enter fullscreen mode Exit fullscreen mode

Install base TensorFlow

python -m pip install tensorflow-macos
Enter fullscreen mode Exit fullscreen mode

Install tensorflow-metal plugin

python -m pip install tensorflow-metal
Enter fullscreen mode Exit fullscreen mode

Install common Data Science packages

pip install tensorflow-datasets pandas jupyterlab
Enter fullscreen mode Exit fullscreen mode

References

Related Articles

Top comments (1)

Collapse
 
dvrkdvys profile image
Jordan Harris • Edited

I cannot thank you enough. The genuis bar ppl couldnt even help me get this running properly.

Maybe add a section on command line tools? Apple says gotta download it from the site.