6

I'm using Tensorflow 2.4.0 on Macbook(arm64, M1 silicon), I get this output after I wanted to check if the GPU in M1 silicon can be used by Tensorflow:

My code:

import tensorflow as tf
print(tf.test.gpu_device_name())
print(tf.config.list_physical_devices('GPU'))

The output:


[]

It looks like my GPU is unavailable. How should I use my GPU on M1 to accelerate trainning?

潘嶓 Bo Pan
  • 383
  • 1
  • 4
  • 7

2 Answers2

3

As of July 2021 Apple provide the following instructions to install Tensorflow 2.5 and the tensorflow-metal plugin:

  1. Create a new conda environment;
  2. Run conda install -c apple tensorflow-deps
  3. Install tensorflow: python -m pip install tensorflow-macos; then
  4. Install the plugin: python -m pip install tensorflow-metal.

This will give you access to the M1 GPU in Tensorflow.

Update as of July 2023

From TensorFlow 2.13 onwards this has been simplified to:

  1. Create a new virtual environment using conda/venv/etc.
  2. Install tensorflow: python -m pip install tensorflow; then
  3. Install the plugin: python -m pip install tensorflow-metal.
tobycoleman
  • 1,664
  • 1
  • 18
  • 34
-2

You may need to install these Tensorflow addons for macOS 11.0+.

GZ0
  • 4,055
  • 1
  • 10
  • 21
  • did't find way to check gpu availability but... I moved my code to Colab and it runs well! thx! – 潘嶓 Bo Pan Jan 18 '21 at 06:10
  • Please add enough information as text for the answer to remain useful even if links contained therein break. Even just changing "these Tensorflow addons" to "Apple's tensorflow_macos library", f/e, would be a substantial help: it would let someone find the new repository if it were renamed, if Apple decided not to use hosting owned by a competitor, &c. – Charles Duffy Jul 13 '23 at 14:57