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(二)

相关推荐
FungLeo8 小时前
Swift macOS 游戏开发实战|空当接龙 07|使用 Swift 计算稳定牌桌布局与命中区域
macos·swift·游戏开发·界面布局·命中检测
FungLeo8 小时前
Swift macOS 游戏开发实战|空当接龙 06|使用 SVG 与 Node.js 制作 macOS 游戏牌面
macos·node.js·svg·swift·游戏素材
Ceelog13 小时前
2026 年 Mac 磁盘清理工具怎么选:App Store 沙盒版、开源命令行和老牌软件对比
macos
默 语1 天前
HarmonyOS7 鼠标画板实战:onMouse、onTouch 与 Canvas 实现手绘画板(附完整案例)
pytorch·深度学习·计算机外设
会飞锦鲤1 天前
基于Mask R-CNN 手机屏幕缺陷检测
pytorch·深度学习·计算机视觉·缺陷检测·实例分割·工业视觉·mask r-cnn
aifannihao1 天前
AI 学习第 29 课:loss 不动先查梯度,177 的范数不是爆炸是累积
pytorch·深度学习·梯度·学习路线·训练监控
FungLeo1 天前
Swift macOS 游戏开发实战|空当接龙 03|使用 Swift 实现可复现的洗牌算法
macos·swift·随机数·fisher-yates·洗牌算法
Name_NaN_None1 天前
Mac局域网/公网远程控制另一台Mac方法(屏幕共享+远程看看) —— 「小白教程」
macos·屏幕共享·投屏·远程控制电脑·远程控制软件·mac远程控制mac
FungLeo2 天前
Swift macOS 开发实战 01|用 Swift 开发空当接龙,如何定义范围与验收
macos·项目管理·需求分析·swift·游戏开发
港城嘟嘟2 天前
Mac mini 当 24 小时下载机:yt-dlp 实战部署与实测数据
macos