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

相关推荐
天天进步20151 分钟前
InfiniteTalk 源码解析 #12:二次开发路线:做一个可商用的长视频口播生成平台
人工智能
Elastic 中国社区官方博客3 分钟前
谁来评判评判者?在 Elasticsearch Workflows 中使用 LLM-as-a-Judge
大数据·运维·人工智能·elasticsearch·搜索引擎·ai·全文检索
yqd6666 分钟前
OpenCV
人工智能·opencv·计算机视觉
糖糖的AI心得19 分钟前
AI重塑跨境运营效率:产品从精修到上架的全链路实战拆解
图像处理·人工智能·aigc
中微极客24 分钟前
Gemini Omni Flash:对话式AI视频编辑新范式
人工智能·音视频·新人首发
mit6.82424 分钟前
一些从researcher角度的观察和思考
人工智能
牛企老板俱乐部26 分钟前
2026 年合肥专业 GEO 优化服务商深度测评|分行业精准选型指南
大数据·人工智能
kuankeTech27 分钟前
数据驱动替代经验经营,AI外贸ERP从记录工具升级为经营决策助手
大数据·人工智能·开源·软件开发·erp
饼干哥哥28 分钟前
单篇100万阅读文章,如何用AI 做好内容创作?
人工智能·正则表达式·代码规范
易观Analysys32 分钟前
易观AI基础设施系列研究-《2026年中国第三方普惠智算云市场专题报告(华东篇)》
人工智能