Repository navigation
[Engine] Metal: moe_gu decodes gate then up rows for 3-4 token groups (MOE_SEQ); Q2_0/IQ2_XXS/IQ3_XXS only - #4377
Open
joseedson18jc wants to merge 1 commit into
Open
joseedson18jc wants to merge 1 commit into
joseedson18jc wants to merge 1 commit into
Conversation
… groups (MOE_SEQ) Function constant 25 (MOE_SEQ) adds gu_body_seq: for the 3- and 4-entry groups of a speculative window, an expert's gate units are decoded and accumulated first, then its up units, in one pass over the weights with the same math order. The host sets it only for windows of 3+ tokens, gr 1 and Q2_0, IQ2_XXS or IQ3_XXS gate/up; 1- and 2-token pipelines are built without the path. expert_parity takes MOE_SEQ and PARITY_SHARE from the environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 57e4d4d on main 5e8a4cc.
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