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

相关推荐
GawynKing4 分钟前
Neo4j 社区版 Mac 安装教程
macos·neo4j
神奇大叔9 分钟前
mac 技巧
macos
舒一笑16 分钟前
企业AI落地不顺问题可能出在你没搞懂知识库
人工智能
涛思数据(TDengine)31 分钟前
可信数据库大会现场,TDengine 时序数据库展示核电场景下的高性能与 AI 创新
大数据·运维·数据库·人工智能·时序数据库·tdengine·涛思数据
不剪发的Tony老师37 分钟前
NeoBase:一款开源、基于AI的数据库管理助手
数据库·人工智能·neobase
一碗白开水一42 分钟前
【YOLO系列】YOLOv12详解:模型结构、损失函数、训练方法及代码实现
人工智能·深度学习·yolo·计算机视觉
努力一点9481 小时前
ubuntu22.04系统实践 linux基础入门命令(三) 用户管理命令
linux·运维·服务器·人工智能·ubuntu·gpu算力
iFlyCai1 小时前
Flutter兼容的iOS的最低版本号
macos·objective-c·cocoa
zzywxc7871 小时前
PyTorch分布式训练:从入门到精通
前端·javascript·人工智能·深度学习·react.js·技术栈深潜计划