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.
Source code in vllm/benchmarks/forward/routing.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | |
check_applied()
¶
Fail if a layer bypassed both the gate and the experts hooks.
Source code in vllm/benchmarks/forward/routing.py
_fixture_rows(fixture, num_tokens)
¶
Select this rank's rows when the model shards tokens across TP ranks.
Source code in vllm/benchmarks/forward/routing.py
_moe_layers(model)
¶
(MoE module, gate) per layer, in model order.
Source code in vllm/benchmarks/forward/routing.py
_top_k(module)
¶
The MoE layer's top-k, from the module or its experts submodules.
Source code in vllm/benchmarks/forward/routing.py
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.
Source code in vllm/benchmarks/forward/routing.py
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.
Source code in vllm/benchmarks/forward/routing.py
zipf_topk_ids(num_tokens, num_experts, top_k, rng)
¶
Sample distinct experts per token with Zipf(alpha=1.25) popularity.