【发布时间】:2021-07-13 23:57:06
【问题描述】:
我已经根据these instructions 在 M1 (ARM) Mac 上安装了TensorFlow。一切正常。
但是,模型训练正在 CPU 上进行。如何将培训切换到GPU?
In: tensorflow.config.list_physical_devices()
Out: [PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]
在Apple's TensorFlow distribution 的文档中,我发现以下paragraph 有点令人困惑:
无需对现有的 TensorFlow 脚本进行任何更改即可将 ML Compute 用作 TensorFlow 和 TensorFlow Addons 的后端。有一个可选的
mlcompute.set_mlc_device(device_name='any')API 用于 ML 计算设备选择。 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.
此时我被卡住了。如何将 GPU 上的 keras 模型训练到我的 MacBook Air?
TensorFlow 版本:2.4.0-rc0
【问题讨论】:
标签: python macos tensorflow deep-learning arm