【Mac】M1安装Pytorch、TensorFlow GPU步骤

【Mac】M1安装Pytorch、TensorFlow GPU步骤

这篇博文主要介绍在Apple M1 Max平台上配置深度学习环境Pytorch和TensorFlow GPU的教程。

TensorFlow

  1. 进入miniconda下载Miniforge3-MacOSX-arm64
  2. 安装Miniconda
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activat
  1. 创造conda虚拟环境
conda create -n TensorFlowmac python==3.9
conda activate TensorFlowmac

(TensorFlow 3.8/3.9 都可以,Pytorch需要3.9, 3.8会报错找不到)

  1. 安装TensorFlow dependencies
conda install -c apple tensorflow-deps
  1. 安装Mac版本TensorFlow
pip install tensorflow-macos
  1. 安装TensorFlow-mental插件
pip install tensorflow-metal
  1. 验证
python
import tensorflow as tf
print(tf.test.is_gpu_available())
exit()
  1. 使用
device = torch.device("mps")

Pytorch

pytorch官网
(已经下载miniconda跳过1、2步骤

  1. 进入miniconda下载Miniforge3-MacOSX-arm64
  2. 安装Miniconda
chmod +x ~/Downloads/Miniforge3-MacOSX-arm64.sh
sh ~/Downloads/Miniforge3-MacOSX-arm64.sh
source ~/miniforge3/bin/activat
  1. 创造conda虚拟环境
conda create -n Pytorchmac python==3.9
conda activate Pytorchmac

(TensorFlow 3.8/3.9 都可以,Pytorch需要3.9版本, 3.8会报错找不到)

  1. 去官网pytorch官网获取命令
    【Mac】M1安装Pytorch、TensorFlow GPU步骤_第1张图片
conda install pytorch torchvision torchaudio -c pytorch
  1. 验证
python
import torch
torch.__version__
torch.device("mps") #输出device(type="mps")
exit()

参考文献

Tensorflow

https://blog.csdn.net/xiangfengl/article/details/126802340
https://zhuanlan.zhihu.com/p/527512729
https://zhuanlan.zhihu.com/p/474212619

Pytorch

https://zhuanlan.zhihu.com/p/548685817
https://zhuanlan.zhihu.com/p/541651316

你可能感兴趣的:(tensorflow,pytorch,macos)