mac中pytorch使用

只有nvidia才需要cuda和cudnn
python 3.6以上才支持新torch
在这里插入图片描述

conda 创建环境失败

设置清华源

可能一:外网网速太慢造成的,换源

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

可能二:先放弃下载python,只创建环境

平常常用指令conda create -n 名字 python=版本号
在这里我们用conda create -n 名字
在成功创建环境后在下载python conda install -c conda-forge python

可能三:报错PackagesNotFoundError: The following packages are not available from current channels

将conda-forge添加到搜索路径上conda config --append channels conda-forge

torch安装

Pytorch 1.12版别现已支撑对Mac的M1 GPU支撑
(官网)查找指令

# MPS acceleration is available on MacOS 12.3+
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
# MPS acceleration is available on MacOS 12.3+
conda install pytorch torchvision torchaudio -c pytorch-nightly

使用

device = torch.device("mps")
model = model.to(device)