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

相关推荐
科技侃谈10 分钟前
Windows和Mac日常使用推荐?联想小新 Air 15 给出大屏新答案
macos
PersistJiao1 小时前
针对 Intel Mac 的硬件限制提升faster-whisper字幕识别的方法
macos·whisper
起个破名想半天了1 小时前
Vmware安装MacOS虚拟机方法
macos·vmware·unlocker
新手村领路人17 小时前
在macos python中安装dlib
开发语言·python·macos
love530love19 小时前
根治 PyTorch CUDA `pynvml` 弃用警告:直接修改 `torch/cuda/__init__.py` 的实践记录
人工智能·pytorch·windows·python·深度学习·机器学习·pynvml
万粉变现经纪人1 天前
2026最新Windows11系统CMD安装Claude Code 快速接入DeepSeek V4 Pro在VSCode编程工具中使用保姆级入门教程指南
linux·运维·ide·windows·vscode·macos·编辑器
Kobebryant-Manba1 天前
安装cuda
pytorch·python·深度学习·conda·numpy
少威shaowei1 天前
在 Mac 上搭建 DNS 服务器
运维·服务器·macos
m0_535817551 天前
Mac下Claude Code完整配置指南:API中转+环境变量设置一步到位
gpt·macos·node.js·api·claude·claudecode·88api
鸠摩智首席音效师1 天前
如何在 macOS 上安装 .NET Core ?
macos·.netcore