Getting TensorFlow install on Apple M1
I am getting started into Astroomy datasets. One of the first things I wanted to do is get adjusted and acquainted with TensorFlow. Since I have an Apple M1, I wanted to get tensorflow installed and using the integrated libraries so when the datasets are written, they are more native using the Apple Metal framework.
Here are the scratch notes.
- Install Xcode Command Line Tools
- Install Miniforge
- Install Tensorflow 2.5 and its dependencies
- Install Jupyter Notebook, Pandas
- Run a Benchmark by training the MNIST dataset
Step 1: I have already installed Xcode Command Line Tools on my mac. If it’s not already installed in your system, you can install it by running the following command below in your terminal.
xcode-select --install
Step 2. Install Miniforge
Install miniforge for arm64 (Apple Silicon) from miniforge GitHub.
Miniforge enables installing python packages natively compiled for Apple Silicon.
After the installation of miniforge, by default, it gives us one base environment. You can turn off the default base env by running
conda config --set auto_activate_base true
Step 3. Installing Tensorflow-MacOS
Install the Tensorflow dependencies:
conda install -c apple tensorflow-deps
Install base TensorFlow:
pip install tensorflow-macos
Install metal plugin:
pip install tensorflow-metal
Step 4. Install Jupyter Notebook & Pandas
conda install -c conda-forge -y pandas jupyter
Step 5. Run a Benchmark by training the MNIST dataset
Let’s install Tensorflow Datasets
pip install tensorflow_datasets
Make sure conda environment is activated.
In your terminal run
jupyter notebook
It will open a browser window
Create a new python3 notebook
Let’s first import TensorFlow and check
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
Let’s run a benchmark
I got the code snippet from TensorFlow Issues
Copy and paste code below in the new notebook
Examine the results.





