Skip to content

perf(moe): add an opt-in router fold and shared expert ninth route on decode - #934

Draft
RaunakGengiti2725 wants to merge 1 commit into
FlashML-org:mainfrom
RaunakGengiti2725:pr/router-fold-ninth-route
Draft

RaunakGengiti2725 wants to merge 1 commit into
FlashML-org:mainfrom
RaunakGengiti2725:pr/router-fold-ninth-route

Conversation

@RaunakGengiti2725

@RaunakGengiti2725 RaunakGengiti2725 commented Nov 20, 2026 •

Copy link
Copy Markdown

Related: #921. Opt-in and off by default, so it is not part of the default measured there.

Two opt-in switches for Qwen3_5MoE decode steps of 1-6 rows: FREETOKEN_ROUTER_FOLD=1 fuses 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" adds FREETOKEN_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.

main PR, unset PR, on
math tok/s 464.9 470.4 496.3 (+6.76%)
code tok/s 420.6 421.0 456.6 (+8.54%)
steps/s, math/code 141.9/146.0 143.7/146.0 154.9/157.9 (+9.18%/+8.16%)
tok/step 3.268/2.878 3.268/2.878 3.194/2.882

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; Qwen4ExpMoE builds and logs no route with both switches on (red without its prepare_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 in models/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.py and tests/moe/test_fused_moe.py.

Tested on real hardware by me.

… 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.
@github-actions github-actions Bot added the perf label Nov 20, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant