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

相关推荐
盼小辉丶14 小时前
PyTorch强化学习实战(27)——进化策略在强化学习中的应用
人工智能·pytorch·深度学习·强化学习
weixin_4471952914 小时前
【无标题】
pytorch·python
bigdata-余建新16 小时前
week2
人工智能·pytorch·深度学习
HwJack2021 小时前
【共创稿事节】HarmonyOS 7材质与光照:真实感的营造与性能的平衡
pytorch·harmonyos·材质
yqj2341 天前
ESP32-S3中小智项目优化内容
ide·macos·xcode
头发够用的程序员2 天前
TensorRT 自定义算子插件实战(一):从零手写 customScaledTanh
c++·人工智能·pytorch·python·深度学习·边缘计算·jetson
论文复现现场2 天前
RTX 5090 32GB 适合科研计算吗?单卡训练、推理、论文复现与 OOM 判断方法
pytorch·深度学习·cuda·rtx5090
论文复现现场2 天前
论文复现看到“RTX 3090 or higher”:显存、CUDA、batch size 与 OOM 怎么判断?
开发语言·pytorch·batch·cuda·rtx3090
Mininglamp_27182 天前
Cider量化配置与性能调优:在M系列Mac上压榨Mano-P的每一点推理性能
macos
zh路西法2 天前
【ResNet18】从图像到视觉特征:卷积神经网络如何理解图像
pytorch·python·神经网络·cnn·resnet·resnet18