MPS: RoPE and RMSNorm in fp32 take 30-46% of Mel-RoFormer attention time
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning, performance
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.5k
- Fork
- 216
- Merge trung bình
- 1 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của nomadkaraoke/python-audio-separator
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
nomadkaraoke/python-audio-separator#292 · 2 bình luận ·
-
Confusing info in READMECó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
nomadkaraoke/python-audio-separator#246 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Tất cả issue của nomadkaraoke/python-audio-separator
Issue tương tự
-
enhancement good first issue help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
jirikuncar/sqlty#1454 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
approved-direction help wanted kind/bug stage/010-actionable triage/accepted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
projectbluefin/testsuite#1329 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tests: tests/mcp/server.test.ts fails on Windows when Microsoft Store python3 alias is presentĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày