Tool · 2026-10-20

MPS in PyTorch 2.15

MPS in PyTorch 2.15

Hugging Face Blog2026-10-20About 3 min readWorth tracking

Marked as a signal by the editors; worth tracking.

On-device AIQuantisation & speculative decodingInference & deployment
On this page11 sections

The full write-up and the editors' notes are in Chinese; the summary above is from the original announcement.

Record

The signal

#

发生了什么

Hugging Face 的 PyTorch 团队发布博文,介绍 PyTorch 2.15 在 MPS(Metal Performance Shaders)后端上的改动。该团队表示,他们的做法是在 Hugging Face Hub 上用语言、图像和视频的真实模型做测试,找出 MPS 的短板,再回到 PyTorch 上游修复,其中不少工作是绕开 MPSGraph、改写为专用 Metal kernel。

具体内容

FP8 进 Mac。 2.15 在 MPS 上支持 torch.float8_e4m3fn 张量,每个值占一个字节,存储是 FP16 或 BF16 的一半;配套的 F.scaled_mm 支持按张量和按行两种缩放方式,可直接在 GPU 上做量化矩阵乘。

MoE 与 LLM 解码加速。 解码阶段每个新 token 以单行走过模型,大矩阵乘退化为矩阵向量乘。2.14 已有 torch.mm 的 GEMV kernel,但 F.linear 仍走 MPSGraph;2.15 把两者接通,96 个来自真实模型的 BF16 层形状上几何平均提速 1.23 倍,收益集中在 MoE 门控这类小投影上。MoE 层则获得了原生 grouped matmul:偏移量不再拷回 CPU 循环,小分组(解码时的常见情况)有独立 kernel。

数字。 在 M3 Ultra 上配合 torch.compile:

  • Qwen3.6-35B-A3B:9.4 → 61.3 tokens/s
  • LFM2.5-8B-A1B:23.6 → 123.6 tokens/s

Softmax 与内存。 词表 softmax 改走专用 Metal kernel,对 [1, 128256] 的 FP32 logits 从 57 µs 降到 7 µs,约 8 倍。Wan2.2 的 tiled VAE 解码一次完整流程有 8,764 次 padding 调用,改用 Metal padding 后,驱动内存峰值从约 270 GiB 降到 8 GiB。

其他。 新增 torch.mps.Stream 与 torch.mps.stream 上下文管理器,可从 Python 选择 MPS 流;complex64 的 LU 分解与求解、三角形求解、小矩阵求逆、QR 分解等线性代数操作也得到支持或加速;conv1d 前向、反射/复制 padding、dropout、上采样反向等训练相关操作有新的 Metal 路径。

要求变化。 MPS 现在要求 macOS 15 或更高版本,PyTorch 2.15 要求 Python 3.11 或更高版本。

对读者意味着什么

  1. 在 Apple silicon 上跑本地 LLM 或 MoE 模型的团队,值得用 2.15 重新测一遍解码吞吐,尤其是小投影密集的 MoE 结构。
  2. 做本地视频生成的用户,padding 修复可能直接决定模型能否在机器上跑完,而不只是快慢问题。
  3. 依赖 MPS 的旧环境要先确认 macOS 与 Python 版本是否满足新门槛,再谈升级收益。

Why now

Why it matters

#

Mac 一直是本地推理的可用但不够快选项,这次 MoE 解码 5–6.5 倍的提升和视频 VAE 内存从 270 GiB 降到 8 GiB,属于会改变「能不能跑、值不值得跑」判断的量级变化。FP8 与 scaled_mm 进入 MPS,也意味着量化权重在 Apple 平台有了官方路径,而不必依赖第三方补丁。

Background

Technical context

#

MPS 是 PyTorch 面向 Apple Metal GPU 的后端,长期依赖 MPSGraph 图执行,部分算子缺失或性能不佳。MoE 模型在解码时每个 token 被路由到不同专家,形成大小不一的矩阵乘分组,需要 grouped matmul;此前的实现要把分组偏移拷回 CPU,成为瓶颈。FP8 指 float8_e4m3fn 这类 8 位浮点格式,配合缩放因子做矩阵乘,可在几乎不损失精度的情况下把权重显存减半。

At your level

Have AI explain this signal at your level

Pick your level of experience and AI writes an explanation for it on the spot.

Audience

Who should care

#
在 Mac 上本地运行 LLM 或 MoE 模型的开发者用 ComfyUI、diffusers 做本地图像与视频生成的用户维护 PyTorch 跨平台兼容层的工程团队评估 Apple silicon 作为推理硬件的技术选型人员
Areas it may affect
本地推理量化视频生成线性代数

Next

Learning path

#
  1. 先读 PyTorch 2.15 的兼容性矩阵,确认自己的 macOS 与 Python 版本满足 MPS 的新要求。
  2. 在自己的 Mac 上用同一模型分别跑 2.14 与 2.15,记录解码 tokens/s,验证博文中的提速是否出现在自己的负载上。
  3. 弄懂 MoE 解码中 grouped matmul 与小分组 kernel 的关系,判断自己的模型结构是否落在收益区间。
  4. 尝试 FP8 加 F.scaled_mm 的量化路径,对比 BF16 下的显存占用与输出质量。

Getting started

Have AI draft a learning path

From the related knowledge and skills on this page, AI drafts a path from the basics to applying it.

Network

Where it sits in the network

#

How this signal connects to neighbouring technologies, skills and background knowledge. Follow any link to keep exploring.

Comparison

Compare with another technology

Pick another published technology and AI writes a comparison of what they share, how they differ and when to use each.

Further thought

Follow-up questions

#
  • 博文中的吞吐数字均在 M3 Ultra 上测得,在 M1/M2 或更低内存配置的机器上,加速比还剩多少?
  • FP8 的 F.scaled_mm 在真实模型权重上的精度损失如何,是否有官方推荐的缩放策略?
  • Wan2.2 内存从 270 GiB 降到 8 GiB 后,实际生成速度与画质是否同步改善?

Publication record

Featured in

#

The briefings that carried this signal, newest first; the last row is the weekly review of its week. The tag is the section it ran in.

Sources

Hugging Face Blog

PyTorchOpen-source community2026-10-20
Open original sourcehttps://huggingface.co/blog/mps-pytorch-2-15