MPS 后端

本文来自:
https://pytorch.org/docs/stable/notes/mps.html
https://pytorch.ac.cn/docs/stable/notes/mps.html


MPS 后端

mps 设备支持 在使用 Metal 编程框架的 MacOS 设备上,进行高性能 GPU 训练。

它引入了新的设备,将机器学习计算图和原语映射到 Metal Performance Shaders 图框架和 Metal Performance Shaders 框架提供的经过优化的内核上。

新的 MPS 后端扩展了 PyTorch 生态系统,并为现有脚本提供在 GPU 上设置和运行操作的功能。

要开始使用,只需将您的张量和模块移动到 mps 设备。

python 复制代码
# Check that MPS is available
if not torch.backends.mps.is_available():
    if not torch.backends.mps.is_built():
        print("MPS not available because the current PyTorch install was not "
              "built with MPS enabled.")
    else:
        print("MPS not available because the current MacOS version is not 12.3+ "
              "and/or you do not have an MPS-enabled device on this machine.")

else:
    mps_device = torch.device("mps")

    # Create a Tensor directly on the mps device
    x = torch.ones(5, device=mps_device)
    # Or
    x = torch.ones(5, device="mps")

    # Any operation happens on the GPU
    y = x * 2

    # Move your model to mps just like any other device
    model = YourFavoriteNet()
    model.to(mps_device)

    # Now every call runs on the GPU
    pred = model(x)

2024-07-16(二)

相关推荐
开开心心_Every1 天前
免费窗口置顶小工具:支持多窗口置顶操作
服务器·前端·学习·macos·edge·powerpoint·phpstorm
猫天意1 天前
【深度学习小课堂】| torch | 升维打击还是原位拼接?深度解码 PyTorch 中 stack 与 cat 的几何奥义
开发语言·人工智能·pytorch·深度学习·神经网络·yolo·机器学习
囊中之锥.1 天前
《从零到实战:基于 PyTorch 的手写数字识别完整流程解析》
人工智能·pytorch·python
蜜汁小强1 天前
macOS 上卸载并重新安装HomeBrew
macos
新手村领路人1 天前
macOS 原生自带的缩放功能设置
macos
小胖燕1 天前
macOS 系统本地部署 CVAT 进行数据标注
macos·cvat
海棠AI实验室1 天前
第 3 篇:服务编排与自启动——把 Mac 变成“稳定可运维”的家庭 AI 机房
运维·人工智能·macos
不如语冰1 天前
AI大模型入门1.3-python基础-类
人工智能·pytorch·python·类和方法
蜜汁小强1 天前
macOS 上管理不同版本的python
开发语言·python·macos
Edward.W1 天前
iOS 17+真机命令行操作对照表
macos·ios·cocoa