mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4377] [Engine] Metal: moe_gu decodes gate then up rows for 3-4 token groups (MOE_SEQ); Q2_0/IQ2_XXS/IQ3_XXS only #5028
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#5028
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/4377
Author: @joseedson18jc
Created: 10/27/2026
Status: 🔄 Open
Base:
main← Head:metal-moe-gu-seq📝 Commits (1)
57e4d4dperf: metal: moe_gu decodes gate rows then up rows for 3- and 4-token groups (MOE_SEQ)📊 Changes
3 files changed (+65 additions, -6 deletions)
View changed files
📝
metal/kernels/moe.metal(+56 -3)📝
metal/src/engine/window.cpp(+7 -1)📝
metal/tests/expert_parity.cpp(+2 -2)📄 Description
Problem and result
In a speculative window of 3 or 4 tokens,
moe_gu's 3- and 4-entry expert groups interleave gate and up rows. This addsgu_body_seqbehind function constant 25 (MOE_SEQ). It decodes an expert's gate units and accumulates them, then its up units: one pass over the weights, same math order. The host sets it only when all of these hold:gr == 1;1- and 2-token pipelines are built without the path. With it in the same pipeline, the M1 Max ran 1 and 2 tokens 8-10% slower.
Gate/up kernel time, µs a layer,
expert_parity --bench --dn Q2_0 --share 0.9, M1 Max, single runs, without seq → with seq:On main's 32,1,4 tile the gains are small. The 1-2% ones are within noise. The large gains need the 8,1,2 or 16,1,4 tiles, which are not on main. They come from the opt-in
STRATA_METAL_MOE_GUin #4272.Why the gate is narrow: the same path on M1 Max was 10-43% slower for Q4_K, Q5_K, Q6_K, Q8_0, IQ4_XS and IQ2_XS at 32,1,4, and for Q2_0 at 32,2,4 (189 → 270 µs at 3 tokens).
Related discussion
Builds on the tiles of #4272. Each PR stands alone: with only this one, seq runs at 32,1,4.
gr == 1keeps it off any 2-row tile.Approach
metal/kernels/moe.metal:gu_body_seq<F,LPR,NR,NE>andMOE_SEQ(function constant 25);moe_gucases 3 and 4, and the chunk loop'sm == 3/m == 4, take it when set.metal/src/engine/window.cpp: the decode site sets constant 25 under the gate above, with a#seqpipeline cache key.metal/tests/expert_parity.cpp: readsMOE_SEQandPARITY_SHARE(default 0.3) from the environment.Validation
Environment: M1 Max, macOS 27.0, revision
57e4d4daon main5e8a4cca.cmake flags:
-G Ninja -DCMAKE_BUILD_TYPE=Release, Apple clang, metal-cpp fromthird_party.Passed
MOE_SEQ=1 expert_parity --gu {Q2_0,IQ2_XXS,IQ3_XXS} --dn Q2_0 --gucfg 32,1,4 --ntok {3,4,6,8}. All 12 PASS; h and y rel L2 ~1e-7. ntok 6 and 8 cover the chunk loop.Failed
expert_paritycrashes (rc 138) when gate/up and down are both a K- or i-quant. This also happens on the unpatched build, which is why the runs above use--dn Q2_0.Not run
--spec 2showed no tok/s gain (43.0 vs 42.1 sampled, 43.2 vs 43.9 greedy).--spec 3was slower there for other reasons.--spec 4and other Apple chips were not measured.Limits
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.