MPS: RoPE and RMSNorm in fp32 take 30-46% of Mel-RoFormer attention time
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
调研方向
Start by reading uvr_lib_v5/roformer/rotary.py and inspect the RoPE and RMSNorm paths used with native fp16 on MPS. Compare the supplied monkeypatch and its benchmark results, then determine how to preserve the fp32 autocast path while applying the optimization. Done means the change improves performance and maintains output quality across more than the single reported model and device.
由索引模型根据 Issue 内容生成。
描述
On Apple Silicon, most of the attention time for Mel-Band RoFormer goes to RoPE and RMSNorm instead of the attention itself. I profiled vocals_mel_band_roformer.ckpt with --use_native_fp16 on an M3 MacBook Air (8 GB, audio-separator 0.47.0, torch 2.14.1, MPS):
| op in one attention block | time block (60 x 1101) | freq block (1101 x 60) |
|---|---|---|
| whole block | 442 ms | 366 ms |
| RoPE on q and k | 131 ms (30%) | 170 ms (46%) |
| SDPA | 148 ms | 11 ms |
| RMSNorm | 33 ms | 41 ms |
The cause is rotate_queries_or_keys in uvr_lib_v5/roformer/rotary.py. It upcasts q and k to fp32 and computes cos/sin on every call. RMSNorm also goes through fp32 F.normalize.
What I tried, and what it gave:
- build the cos/sin tables once per sequence length in fp32, cast them to the model dtype, and rotate in that dtype
- permute the q/k weight rows to the split-half layout so the rotation is two slices and a cat (q·k doesn't change because both get the same permutation)
F.rms_normin the model dtype- fold
to_gatesinto the qkv matmul
On a 3 minute clip that took fp16 from 1.35x to 2.19x real time. The output stayed at 66.7 dB SDR against the fp32 output (stock fp16 is 65.9 dB). The code is a small monkeypatch: https://github.com/aipdv/fast-melroformer/blob/main/fastmbr/patch.py
I know the fp32 RoPE path exists for precision under autocast, so maybe keep it for autocast and use precomputed tables for native fp16. I've only tested this one model on one machine. I'm not planning to open a PR, but the patch is MIT, so take whatever is useful.
- 主要语言
- Python
- 星标
- 1.5k
- 派生
- 216
- 平均合并
- 1 小时
- 30 天内合并 PR
- 2
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
nomadkaraoke/python-audio-separator 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
-
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 68/100
nomadkaraoke/python-audio-separator#292 · 2 条评论 ·
-
Confusing info in README可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 1/5 1 小时以内 新手友好度 65/100
nomadkaraoke/python-audio-separator#246 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 48/100
查看 nomadkaraoke/python-audio-separator 的全部 Issue
相似的 Issue
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
jirikuncar/sqlty#1454 ·
维护者通常 1 天内回复
-
approved-direction help wanted kind/bug stage/010-actionable triage/accepted
难度 2/5 1-3 小时 新手友好度 90/100
projectbluefin/testsuite#1329 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复