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

相关推荐
FL16238631291 分钟前
自动驾驶场景驾驶员注意力安全行为睡驾分心驾驶疲劳驾驶检测数据集VOC+YOLO格式5370张6类别
人工智能·yolo·自动驾驶
Java中文社群3 分钟前
找到漏洞了!抓紧薅~N8N调用即梦全免费
人工智能
培根芝士6 分钟前
使用llm-compressor 对 Qwen3-14B 做 AWQ + INT4 量化
人工智能·python
da_vinci_x13 分钟前
Sampler AI + 滤波算法:解决 AIGC 贴图“噪点过剩”,构建风格化 PBR 工业管线
人工智能·算法·aigc·材质·贴图·技术美术·游戏美术
AI人工智能+16 分钟前
表格识别技术:完整还原银行对账单表格结构、逻辑关系及视觉布局,大幅提升使处理速度提升
人工智能·深度学习·ocr·表格识别
珠海西格电力17 分钟前
零碳园区基础架构协同规划:能源-建筑-交通-数字系统的衔接逻辑
大数据·人工智能·智慧城市·能源
chao18984421 分钟前
MATLAB 实现声纹识别特征提取
人工智能·算法·matlab
zhishidi23 分钟前
推荐算法之:GBDT、GBDT LR、XGBoost详细解读与案例实现
人工智能·算法·推荐算法
yiersansiwu123d25 分钟前
AI伦理治理:在创新与规范之间寻找平衡
人工智能
weixin_5372170625 分钟前
AI 智能体如何利用文件系统进行上下文工程
大数据·人工智能