vllm.model_executor.layers.fused_moe.routed_experts_capturer
¶
Classes:
-
RoutedExpertsCapturer–Worker-side capturer for routed experts, lives on GPU.
-
RoutedExpertsRowRestorer– -
RoutedExpertsSink–Layer-owned buffer and callback for the expert ids a monolithic kernel
Functions:
-
bind_routed_experts_capturer–Attach capture callbacks to the target model's MoE routers.
RoutedExpertsCapturer
¶
Worker-side capturer for routed experts, lives on GPU.
Layer-level hooks call :meth:capture inside the forward pass. Routing
rows owned by this DP rank are written into a preallocated device buffer.
The device buffer uses int32. Stable snapshots use the narrowest dtype
that can represent every logical expert ID.
Invariants
- One instance per worker; shape is fixed at init and covers the
worst-case step (
max_num_batched_tokenstokens). - Every routed layer overwrites the current step's token rows.
Methods:
-
snapshot_routing_data–Return a stable snapshot of the current routing data.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 | |
_restore_local_topk_ids(topk_ids, ctx)
¶
Restore this DP rank's token rows, trimming trailing SP padding.
Layout priority: cross-DP batch, local batch, gathered DP/TP shards, then a local TP shard. Gathered rows are DP-major/TP-minor; preserve this priority when layout sizes coincide. PCP is unsupported.
Without DP metadata, use the pre-SP batch descriptor. Unknown counts pass through; known counts must match a full, sharded or padded batch. A full local batch avoids gathering, including zero/one-token batches where only the publishing TP0 rank needs the real rows.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
snapshot_routing_data(num_tokens)
¶
Return a stable snapshot of the current routing data.
RoutedExpertsRowRestorer
¶
Bases: Protocol
Methods:
-
restore_routed_experts_rows–Restore local token-ordered logical IDs for all captured MoE layers.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
restore_routed_experts_rows(topk_ids, ctx)
¶
Restore local token-ordered logical IDs for all captured MoE layers.
Binding selects the first provider. Read current metadata from ctx;
do not depend on the provider's layer-specific state or modify input.
Return a 2-D tensor with the input device, dtype and top-k width.
Collectives must be rank-consistent and graph-replay safe.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
RoutedExpertsSink
¶
Layer-owned buffer and callback for the expert ids a monolithic kernel routes to; it outlives kernel rebuilds on weight reload.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
bind_routed_experts_capturer(model, capturer)
¶
Attach capture callbacks to the target model's MoE routers.