AstroNN + TensorFlow on Apple Silicon: A Setup That Works
Getting deep-learning astronomy tooling running on an M-series Mac.
I wanted to run deep-learning astronomy tools on a laptop and not pay for a cloud GPU. AstroNN applies neural networks to stellar spectra and to data from the Gaia mission. Getting it and TensorFlow running on an M-series Mac took fiddling. This post records the recipe I used in March, the reason each step is there, and what I would check before you copy it today. The title says “a setup that works”, and the March recipe did for me. Software versions move, so read the section on what changed before you start.
My earlier notes on the TensorFlow half are in Getting TensorFlow install on Apple M1. The two posts overlap, and I point between them where they do.
The problem
Stock TensorFlow wheels from pip do not target the M-series GPU. A plain pip install tensorflow failed to build for me, or it ran on the CPU only, with no error to tell me. Training works either way, so the symptom is a job that takes far longer than it should.
The March recipe
The fix was Apple’s tensorflow-metal plugin on top of tensorflow-macos. The steps I ran:
conda create -n astronn python=3.10
conda activate astronn
pip install tensorflow-macos tensorflow-metal
pip install astroNNI kept Python at 3.10 on purpose. Newer Python versions outran the plugin’s support matrix at the time, so a newer interpreter meant packages with no matching build.
Then I checked that TensorFlow could see the GPU:
import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))With the plugin working, that list names one GPU device and models train on it. Expected value on an M-series Mac: one device, for example [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]. I have not captured a run for this rewrite.
What changed since March
Check three things before you reuse the recipe.
The tensorflow-metal package has a newer release. Version 1.2.0 came out on 2025-01-31. It supports CPython 3.9 to 3.12 on macOS 12 or later and on ARM64, so Python 3.10 is still inside its range, and so are 3.11 and 3.12. The plugin’s page now tells you to install the base tensorflow package together with tensorflow-metal. Its compatibility table lists TensorFlow 2.14 to 2.18 against plugin versions up to 1.1.0.
The tensorflow-macos package may be the wrong choice now. The last release on PyPI is 2.16.2, from 2024-06-28, so it no longer follows current TensorFlow. The March recipe pins that older line, while the plugin’s table lists TensorFlow 2.14 to 2.18.
Current TensorFlow uses Keras 3, and astroNN says it is compatible with Keras v3. Whether tensorflow-metal 1.2.0 works with Keras 3 is not confirmed, and I have not tested it. The astroNN project page reads that it runs on TensorFlow or PyTorch, which gives you a fallback if the plugin gives you trouble.
The route I would test today
I have not run this, so treat it as a plan with an expected result and not a recipe:
python3.11 -m venv tfm
source tfm/bin/activate
pip install tensorflow tensorflow-metal astroNN
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"Expected value: one GPU device on an M-series Mac. If the list is empty, the plugin did not load. If pip reports a conflict, the versions of TensorFlow and the plugin do not match its table. Pin both to a pair the table lists, then try again.
I changed three things from the March recipe. The interpreter is 3.11 and not 3.10. TensorFlow comes from the base package and not tensorflow-macos. The environment is a plain venv, so no conda is needed. If you prefer conda, the Miniforge steps are in the earlier post, including a correction to the command that turns off the base environment.
What AstroNN is
AstroNN is a collection of Keras-driven neural networks for astronomy data. According to its GitHub page it is released under the MIT license, it works with Keras v3, and it runs on TensorFlow or PyTorch. It ships the Galaxy10 dataset as a toy example, which is what I would load first to prove the install. The latest astroNN on PyPI is 1.1.0, released 2023-04-26.
The stellar spectra and Gaia work is what drew me in. That kind of model has a lot of input values per star, and a GPU shortens the time between trying an idea and seeing it fail or work.
Why a laptop is enough
For experimenting with pretrained models, a laptop GPU is sufficient. You load a model, run it on a batch and look at the output. The cloud bill I avoid is real money for an experiment that might last an afternoon. For training from scratch on a large dataset you will want more hardware, and I have not tested that case.
A short checklist
Before you start a long job, confirm four things in this order.
Run python --version and confirm it lies in the plugin’s 3.9 to 3.12 range. Run pip list and confirm that both tensorflow and tensorflow-metal are present in the environment you are using. Run the GPU check and confirm it names a device. Then train on a tiny batch and watch the activity monitor’s GPU history for load, which tells you the GPU is doing the work and not the CPU.
If any step fails, stop there. The cause is almost always a version mismatch between Python, TensorFlow and the plugin, and a job started on a wrong install fails slowly.
Where this connects
The object queries I run in SpaceDB: Querying a Million Space Objects feed the same experiments. A fast local table of objects and a local GPU make a short loop between a question and a result.
Sources: the tensorflow-metal page on PyPI, the astroNN repository on GitHub, and Apple’s page on the Metal plugin for TensorFlow.