macos安装metal 加速版 pytorch


categories: [Python]

tags: Python MacOS

写在前面

试试 m3 的 metal 加速效果如何

  • Mac computers with Apple silicon or AMD GPUs
  • macOS 12.3 or later
  • Python 3.7 or later
  • Xcode command-line tools: xcode-select --install

安装 Python: conda-forge

bash 复制代码
brew install miniforge

镜像

yaml 复制代码
channels:
  - defaults
show_channel_urls: true
auto_activate_base: false
ssl-verify: false
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/

安装

开一个新的虚拟环境, 这个是重点, 如果不开的话, 原有的环境会污染 C 库的链接, 所以这一步是必须的

On Mac OS X, import numpy complaining about "Library not loaded: @rpath/libgfortran.3.dylib" · Issue #12970 · numpy/numpy;

这个方案不彻底, 直接卸载 numpy 然后重装不能解决问题...

bash 复制代码
conda create -n py3xi python=3.11
conda activate py3xi
# conda update --all -c conda-forge # optional
# 重点: 
conda install pytorch torchvision torchaudio -c pytorch-nightly 

然后测试

Accelerated PyTorch training on Mac - Metal - Apple Developer;

python 复制代码
import torch
if torch.backends.mps.is_available():
    mps_device = torch.device("mps")
    x = torch.ones(1, device=mps_device)
    print (x)
else:
    print ("MPS device not found.")
'''
tensor([1.], device='mps:0')
'''

可以在 MacOS 上跑深度学习了.

相关推荐
甜辣uu2 分钟前
基于深度学习的CT图像肺结节分割与检测系统
人工智能·深度学习
赵域Phoenix3 分钟前
混沌系统是什么?
人工智能·算法·机器学习
ASKED_20197 分钟前
Claude Code:架构、治理与工程实践
人工智能·架构
xcbrand8 分钟前
文旅行业品牌策划公司找哪家
大数据·运维·人工智能·python
芯智工坊15 分钟前
第19章 Mosquitto完整项目实战
网络·人工智能·mqtt·开源
moers21 分钟前
从自建模型迁移到调API,省了480万,但踩了这些坑
人工智能
skilllite作者30 分钟前
Spec + Task 作为「开发协议层」:Rust 大模型辅助的标准化、harness 化与可回滚
开发语言·人工智能·后端·安全·架构·rust·rust沙箱
何陋轩36 分钟前
GitHub Copilot深度使用指南:手把手教你在IDEA中榨干AI生产力
人工智能·后端
oioihoii38 分钟前
当AI开始“思考”:我们是否真的准备好了?
人工智能
QC777LX38 分钟前
传统物流专员效率瓶颈明显,AI物流调度师正在替代
人工智能