Repository navigation
perf(moe): add an opt-in router fold and shared expert ninth route on decode - #934
Draft
RaunakGengiti2725 wants to merge 1 commit into
Draft
RaunakGengiti2725 wants to merge 1 commit into
RaunakGengiti2725 wants to merge 1 commit into
Conversation
… decode FREETOKEN_ROUTER_FOLD=1 computes the router's logits inside its top-k launch on decode steps of up to 6 rows, summing the softmax picks in selection order. FREETOKEN_SHARED_EXPERT_ROUTE=1, with the fold on, runs the shared expert as a ninth route of the routed experts' NVFP4 decode kernels; its bank copy is made before the KV pool is sized. Both are off by default and log once when set.
This branch has not been deployed
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.
Related: #921. Opt-in and off by default, so it is not part of the default measured there.
Two opt-in switches for
Qwen3_5MoEdecode steps of 1-6 rows:FREETOKEN_ROUTER_FOLD=1fuses router linear and top-k in Triton;FREETOKEN_SHARED_EXPERT_ROUTE=1(needs the fold, tp=1) makes the shared expert a ninth NVFP4 route, copied before KV sizing.A/B against main 2fb371e. RTX 5090 (400 W), AMD EPYC 7402 CPU, driver 595.112.07. All arms:
ft serve --model nvidia/Qwen3.6-35B-A3B-NVFP4 --enable-timings-report --moe-strategy fused --max-running-requests 1 --speculative-algorithm mtp --speculative-num-steps 3; "on" addsFREETOKEN_ROUTER_FOLD=1 FREETOKEN_SHARED_EXPERT_ROUTE=1. One math, one code prompt, 5 passes, 1,024 warm-up + 2,048 timed tokens, checkpoint sampling, server timings; 2 interleaved rounds, the second reversed.Unset: 20/20 timed texts equal main's. On: 0/20; both rounds positive (tok/s +5.19/+8.31% math, +7.84/+9.23% code); ninth route logged at 4 rows. No A/A: main's rounds differ 1.2% (math).
My fork's stack C (
a1b8dc9, an earlier default-on revision with other changes, on 6d53c36), MTP-5, not rerun on main: forced-segment KL against 6d53c36 0.001636 nats (line 0.00268); hard math 27/30, as 6d53c36. Gate: running, no verdict yet.Not included: a guard for #923's wide decode GEMM, needed if both merge.
Tests (no GPU;
tests/moe/test_fused_moe.py,tests/models/test_qwen3_5_moe_shared_route.py): unset is silent; no route without the fold; 6-row cap;Qwen4ExpMoEbuilds and logs no route with both switches on (red without itsprepare_decode_weights). The route's CUDA tests have not run on a GPU in this form; only the A/B has.How to review. About 650 of the 1,372 added lines are code; the rest are tests. The router fold kernel is in
kernel/triton/moe_router.py(+331). The ninth-route wiring is inmodels/qwen3_5_moe/moe.py(+229). The NVFP4 MoE path gets small hooks, about 80 lines across 8 files. Tests:tests/models/test_qwen3_5_moe_shared_route.pyandtests/moe/test_fused_moe.py.Tested on real hardware by me.