让TensorFlow在ARMMac上使用GPU
我已根据这些说明安装TensorFlow在 M1 ( ARM ) Mac 上。一切正常。
但是,模型训练正在CPU. 如何将培训切换到GPU?
In: tensorflow.config.list_physical_devices()
Out: [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]
在Apple 的 TensorFlow 发行版的文档中,我发现以下有点令人困惑的段落:
无需对现有 TensorFlow 脚本进行任何更改即可使用 ML Compute 作为 TensorFlow 和 TensorFlow Addons 的后端。有一个
mlcompute.set_mlc_device(device_name='any')用于 ML Compute 设备选择的可选API。device_name 的默认值为“any”,这意味着 ML Compute 将选择您系统上的最佳可用设备,包括多 GPU 配置上的多个 GPU。其他可用选项是CPU和GPU。请注意,在 Eager 模式下,ML Compute 将使用 CPU。例如,选择 CPU 设备,您可以执行以下操作:
# Import mlcompute module to use the optional set_mlc_device API for device selection with ML Compute.
from tensorflow.python.compiler.mlcompute import mlcompute
# Select CPU device.
mlcompute.set_mlc_device(device_name='cpu') # Available options are 'cpu', 'gpu', and 'any'.
所以我尝试运行:
from tensorflow.python.compiler.mlcompute import mlcompute
mlcompute.set_mlc_device(device_name='gpu')
并得到:
WARNING:tensorflow: Eager mode uses the CPU. Switching to the CPU.
在这一点上,我被卡住了。如何keras将 GPU 上的模型训练到我的 MacBook Air?
TensorFlow 版本: 2.4.0-rc0