mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4807] [CLOSED] [Engine] Mac: opt-in fp16 GEMVs and Q2_0 experts in decode windows (STRATA_METAL_F16=1) #5193
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#5193
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/4807
Author: @rasa04
Created: 10/31/2026
Status: ❌ Closed
Base:
main← Head:metal-f16-decode📝 Commits (2)
46dc3f6[Engine] Mac: STRATA_METAL_F16=1 - the decode windows' GEMVs and routed experts in fp16 (opt-in)28c2a7f[Engine] Mac: STRATA_METAL_F16 - only the decode windows of one resident sequence; the tests' fp16 buffers only in fp16 mode📊 Changes
12 files changed (+611 additions, -27 deletions)
View changed files
📝
docs/MAC.md(+1 -0)📝
metal/kernels/gdn.metal(+16 -0)📝
metal/kernels/gemv.metal(+63 -0)📝
metal/kernels/glue.metal(+1 -0)📝
metal/kernels/gr.metal(+1 -0)📝
metal/kernels/moe.metal(+132 -0)📝
metal/kernels/qsa.metal(+16 -0)📝
metal/kernels/quant.metal(+15 -0)📝
metal/kernels/units.metal(+226 -0)📝
metal/src/engine/window.cpp(+68 -17)📝
metal/tests/expert_parity.cpp(+23 -6)📝
metal/tests/gemv_parity.cpp(+49 -4)📄 Description
Problem and result. On an M1 Max (24-core GPU) the decode window's low-bit GEMVs are not bound by memory: a Q3_K 2560→10240 2-token GEMV reads 11.3 MB in 177 µs (64 GB/s;
rt_bench bwreads 327 GB/s), andalu_benchgives fp16 FMA 2.24-2.39 Tops against 1.20-1.43 for fp32. WithSTRATA_METAL_F16=1a 2-token window's GPU time drops from 56-60 ms to 40-41 ms. Unset, the output is byte-identical toc62d5e3a.Related discussion: #4025 (the same M1 Max decode gap; no maintainer reply yet). Overlaps #4019 in
window.cpp: its calibration must skip the fp16 dispatches; I will rebase whichever lands second.Change (opt-in; unset, the fp16 kernels are not compiled and the buffers and dispatches are unchanged):
gemv16for Q2_0, Q3_K, Q4_K, Q5_K, Q6_K, IQ4_XS, andmoe_gu16/moe_down16for the Q2_0 routed experts without the Hadamard rotation. Weights decoded into half; each half unit's products (16, or 8 for Q2_0) summed in half; the scales and the sum over units in float.xprep,gr_up,gdn_step,qsa_merge,swiglu_prep) also write three half planes after the float ones (function constant 25).Result (Qwen3.8-Flash-Next Q2_0 resident, M1 Max 24-core GPU, 64 GB, macOS 27, MTP
--spec 2, default tiles;28c2a7ffonc62d5e3a; runs in the order unset, set, set, unset; the first unset run was the engine's first start after the build):STRATA_METAL_F16=1STRATA_METAL_KPROF=2)fp16 changes 2.6% of the top-1 tokens, so the text and the drafts' acceptance differ: the window's GPU time is the like-for-like number.
GEMVs alone, 2 tokens, each side's best tile (
gemv_parity --one,GEMV_F16=1; the same kernels, measured on7dd5cf18): Q3_K 2560→10240 177.0 → 112.7 µs, Q2_0 2560→10240 96.9 → 63.1, Q6_K 6144→2560 99.6 → 67.6, IQ4_XS 2560→10240 90.2 → 68.8, Q5_K 6144→2560 98.6 → 77.4, Q4_K 2560→10240 125.7 → 104.8, the Q5_K LM head 2881 → 2371.Quality (
tools/quant_quality.py, 4995 positions, againstc62d5e3a): same top token 97.38%, mean KL 0.0091 (p99 0.126), perplexity 4.439 → 4.415. For scale: changing only the GEMV tiles (the order of a sum, #4019) gives KL 0.003.Validation (
28c2a7ffonc62d5e3a, M1 Max, macOS 27; commands below):gemv_parityALL PASS;gr_parityALL PASS;expert_parity507/507; output byte-identical toc62d5e3a(quant_quality,cmp: 4995/4995 rows); a cold compile of the kernels 9.6-10.4 s against 9.7-10.1 s (on the previous base5e8a4cca, another GPU job running).GEMV_F16=1 gemv_parity --one12/12 (6 formats × ntok 1, 2; worst rel L2 against fp32 1.06e-3, limit 4e-3);EXPERT_F16=1 expert_parity405/405 (worst rel L2 against double: h 1.31e-3, y 3.9e-4; limit 4e-3).fuse_parityrouter_route(8 cases, unset), the same withc62d5e3a's kernels (STRATA_METAL_ROUTEon an M1 Max, docs/MAC.md).gr_up,gdn_step,qsa_merge,swiglu_prep(covered end to end byquant_quality; a throwaway kernel test found them bit-equal to half(x · scale) at ntok 1, 3, 8; not in the PR); CUDA / HIP / SYCL (not touched).Limits.
gemv_parityon7dd5cf18, same kernels): 5-29% faster, a Q2_0 one 3% slower; one-token decode end to end not measured.5e8a4cca, another GPU job running); a later start reuses Metal's cache (0.01 s, measured on7dd5cf18).Commands
KPROF
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.