苹果mac m1,m2芯片安装 pytorch和tensorflow的GPU版本

一、下载M芯片的anaconda,并安装

二 、安装GPU版本的pytorch

1.安装 Xcode

xcode-select --install

2.创建环境

conda create -n torch-gpu python=3.9

conda activate torch-gpu

3.打开pytorch官网复制命令, 注意:在mac m上,device是’mps’ 而不是’cuda’, mac的MPS支持MacOS 12.3+

 4.测试

import torch
import math

print(torch.backends.mps.is_available())
# True
print(torch.backends.mps.is_built())
# True

三、安装GPU版本的tensorflow

1.安装 Xcode

xcode-select --install

2.创建环境

conda create -n tensorflow-gpu python=3.9

conda activate tensorflow-gpu

3. 安装conda install -c apple tensorflow-deps

conda install -c apple tensorflow-deps

 4.Install base TensorFlow

python -m pip install tensorflow-macos==2.9

5.  Install tensorflow-metal plug-in

python -m pip install tensorflow-metal==0.6

 6.验证

import tensorflow as tf

print(tf.test.is_gpu_available())

7.完成,附上我安装完pytorch和tensorflow的图

猜你喜欢

转载自blog.csdn.net/xiangfengl/article/details/130940480