vllm.benchmarks.forward.routing
¶
Synthetic MoE routing for forward benchmarks.
Dummy gate weights give degenerate routing, which skews MoE and all-to-all cost. The routing still runs; its result is replaced by the fixture at whichever boundary the layer exposes:
- Gate output: fixed logits whose top-k is the fixture. Covers every backend that routes from logits, including monolithic kernels that run top-k internally (e.g. FlashInfer TRTLLM).
- Experts input: models that compute top-k themselves and pass
topk_idsto their experts (e.g. MegaMoE with a fused gate) get the fixture's IDs. The routing weights are kept; they don't affect cost.
Hash-routed layers ignore logits and keep their tables unless their experts
take topk_ids.
Classes:
-
RoutingFixture–Installs synthetic routing for one case;
remove()restores the model.
Functions:
-
balanced_topk_ids–Expert IDs [num_tokens, top_k] giving every EP rank equal load.
-
install_routing–Resolve
--routingand install a synthetic fixture if selected. -
zipf_topk_ids–Sample distinct experts per token with Zipf(alpha=1.25) popularity.
RoutingFixture
¶
Installs synthetic routing for one case; remove() restores the model.
Methods:
-
check_applied–Fail if a layer bypassed both the gate and the experts hooks.
check_applied()
¶
Fail if a layer bypassed both the gate and the experts hooks.
_fixture_rows(fixture, num_tokens)
¶
Select this rank's rows when the model shards tokens across TP ranks.
_moe_layers(model)
¶
(MoE module, gate) per layer, in model order.
_top_k(module)
¶
The MoE layer's top-k, from the module or its experts submodules.
balanced_topk_ids(num_tokens, num_experts, top_k, ep_size, rng)
¶
Expert IDs [num_tokens, top_k] giving every EP rank equal load.
Each token's slots go round-robin over EP ranks, to distinct experts.
install_routing(runner, requested, dummy_weights, num_tokens, seed)
¶
Resolve --routing and install a synthetic fixture if selected.
auto is Zipf with dummy weights and real otherwise; it falls back to
real routing when the model doesn't support the fixture.
zipf_topk_ids(num_tokens, num_experts, top_k, rng)
¶
Sample distinct experts per token with Zipf(alpha=1.25) popularity.