vllm.model_executor.layers.fused_moe.routed_experts_capturer
¶
Classes:
-
RoutedExpertsCapturer–Worker-side capturer for routed experts, lives on GPU.
-
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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 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 | |
_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.
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.