Apple mac m1, m2 chips install the GPU version of pytorch and tensorflow

1. Download the anaconda of the M chip and install it

2. Install the GPU version of pytorch

1. Install Xcode

xcode-select --install

2. Create the environment

conda create -n torch-gpu python=3.9

conda activate torch-gpu

3. Open the pytorch official website to copy the command. Note: on mac m, the device is 'mps' instead of 'cuda'. Mac's MPS supports MacOS 12.3+

 4. Test

import torch
import math

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

3. Install the GPU version of tensorflow

1. Install Xcode

xcode-select --install

2. Create the environment

conda create -n tensorflow-gpu python=3.9

conda activate tensorflow-gpu

3. Install 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. Verify

import tensorflow as tf

print(tf.test.is_gpu_available())

7. Finished, attach the picture of my installation of pytorch and tensorflow

Guess you like

Origin blog.csdn.net/xiangfengl/article/details/130940480