MacOS Apple M1上安装tensorflow2使用其原生GPU

MacOS Apple M1上安装tensorflow2使用其原生GPU,第1张

MacOS Apple M1上安装tensorflow2使用其原生GPU 安装Mambaforge

首选推荐安装Mambaforge, 也可以安装miniforge3。
项目链接:https://github.com/conda-forge/miniforge/

创建conda虚拟环境
conda create -n tf270 -c apple tensorflow-deps
conda activate tf270
pip install tensorflow-macos tensorflow-metal
测试安装是否成功
import tensorflow as tf
print(tf.__version__)
print(tf.version.VERSION)

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

结果如下GPU即为安装成功:

(tf270) hzw@bogon ~ % python                                        
Python 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02) 
[Clang 11.1.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow.python.client import device_lib
>>> print(device_lib.list_local_devices())
metal device set to: Apple M1

systemMemory: 8.00 GB
maxCacheSize: 2.67 GB

2021-12-15 16:38:14.922342: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2021-12-15 16:38:14.923134: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: metaL, pci bus id: )
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 16585735293412376744
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
locality {
  bus_id: 1
}
incarnation: 17634086545751551048
physical_device_desc: "device: 0, name: metaL, pci bus id: "
xla_global_id: -1
]
>>> 
参考链接

https://developer.apple.com/metal/tensorflow-plugin/

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5670618.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存