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 上跑深度学习了.

相关推荐
百度Geek说3 分钟前
DeepSeek Harness:重新设计 Agent 运行时
人工智能
Ming_studying6 分钟前
近期AI热点010|ChatGPT Images 2.5 加入 Sketch:图像生成从文字提示走向草图交互
人工智能·chatgpt·openai·ai绘图·sketch
tachibana210 分钟前
什么是 Function Calling ?
数据库·人工智能·ai·llm·agent
全栈弄潮儿²⁰²⁴10 分钟前
AI Agent 开发实战(7):如何接入搜索和数据库工具?
数据库·人工智能·ai·chatgpt·oracle·agent·ai编程
prog_610321 分钟前
【笔记】用cursor手搓cursor(十)
人工智能·笔记·大语言模型·agent
沙淘金数据服务25 分钟前
电商订单数据整合难题拆解:多源异构数据如何实现自动化治理?
大数据·人工智能·数据治理·数据清洗·电商·外贸
万岳科技系统开发26 分钟前
AI数字人直播系统源码搭建指南:数字人、语音与直播如何实现
人工智能
论文复现现场28 分钟前
本地 PyTorch 训练 OOM,第一次租 RTX 4090 云 GPU 怎么迁移项目?从环境检查到 100 Step 跑通
人工智能·pytorch·python·深度学习·cuda
云雀衔光30 分钟前
MCP 协议全景:为什么它是 AI 连接工具的「USB-C」
java·开发语言·数据库·人工智能·ai编程
kyle~31 分钟前
ISP--- RAW 图像 从传感器噪声模型到快门时序与频闪效应
人工智能·计算机视觉·接口隔离原则