如何在 Apple M1 芯片的 Mac 上使用 Tensorflow 检查 GPU 可访问性?

问题描述

我在 Macbook(arm64,M1 硅)上使用 Tensorflow 2.4.0,在我想检查 M1 硅中的 GPU 是否可以被 Tensorflow 使用后,我得到了这个输出

我的代码

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

输出


[]

我的 GPU 似乎不可用。我应该如何在 M1 上使用我的 GPU 来加速训练?

解决方法

自 2021 年 7 月起,Apple provide the following instructions 将安装 Tensorflow 2.5 和 tensorflow-metal 插件:

  1. 创建一个新的 conda 环境;
  2. 运行conda install -c apple tensorflow-deps
  3. 安装tensorflow:python -m pip install tensorflow-macos;然后
  4. 安装插件:python -m pip install tensorflow-metal

这将使您能够访问 Tensorflow 中的 M1 GPU。

,

您可能需要为 macOS 11.0+ 安装 these Tensorflow addons