Skip to content

perf(moe): route fused_topk through the in-repo triton router - #319

Merged
jason-fxz merged 1 commit into
mainfrom
perf/default-vendored-topk-router
Sep 1, 2026
Merged

perf(moe): route fused_topk through the in-repo triton router#319
jason-fxz merged 1 commit into
mainfrom
perf/default-vendored-topk-router

Conversation

@jason-fxz

Copy link
Copy Markdown
Collaborator

What

fused_topk now always calls freetoken.kernel.triton.moe_router.fused_topk_softmax. The
triton_kernels.topk branch and the pure-torch fallback dispatch are gone, along with
is_triton_kernels_installed() and its warning.

_torch_fused_topk stays as the reference the router tests compare against; the runtime no
longer reaches it.

Performance

The dispatch order was inverted: the fastest implementation was the fallback branch.

Faster at every shape measured. H100 80GB, torch 2.11+cu130, bf16 logits,
renormalize=True, CUDA-graph replay (GPU time), us/call:

model (E, K) M=1 torch triton triton_kernels M=16384 torch triton triton_kernels
DeepSeek-V4-Flash (256, 6) 17.8 1.9 n/a 250.7 22.1 n/a
Qwen3-30B/235B (128, 8) 16.8 2.2 14.7 136.9 12.4 34.3
Qwen3.6-35B-A3B (256, 8) 17.8 2.2 19.5 254.0 22.5 55.6
GLM-5.3-Flash (288, 8) 18.6 2.8 20.8 292.9 38.1 60.8
Qwen3.8-Flash-Next (512, 10) 20.4 3.6 n/a 457.5 50.6 n/a
The triton_kernels branch is gone: fused_topk_softmax is faster at every shape
measured on H100 (2.4-9.5x vs triton_kernels.topk, 6-17x vs pure torch,
CUDA-graph GPU time), works for any k, and needs no undeclared optional package.
Slot order for power-of-2 k now follows the descending-weight convention instead
of triton_kernels' ascending expert id; downstream expert compute sums over the
k slots, so the routing decision is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant