vllm.benchmarks.forward.routing
¶
Balanced MoE routing for benchmarks with dummy weights.
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:
-
BalancedRouting–Installs balanced 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 balanced routing if selected.
BalancedRouting
¶
Installs balanced 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
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | |
check_applied()
¶
Fail if a layer bypassed both the gate and the experts hooks.
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 balanced routing if selected.
auto is balanced with dummy weights and real otherwise; it falls back to
real routing when the model doesn't support the fixture.