vllm.model_executor.layers.fused_moe.routed_experts_capturer ¶
_global_experts_capturer module-attribute ¶
_global_experts_capturer: RoutedExpertsCapturer | None = (
None
)
RoutedExpertsCapturer ¶
Capturer for routed experts with device and optional shared memory buffer.
This class captures expert routing decisions during model forward passes and optionally stores them in shared memory for cross-process access.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
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 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 | |
__del__ ¶
__init__ ¶
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
capture ¶
Capture expert routing decisions for a specific layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_id | int | The layer index. | required |
topk_ids | Tensor | Tensor of shape (batch_size, num_routed_experts). | required |
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
cleanup ¶
Explicitly clean up shared memory resources.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
clear_buffer ¶
create classmethod ¶
create() -> RoutedExpertsCapturer
Create a global singleton instance.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
get_instance staticmethod ¶
get_instance() -> RoutedExpertsCapturer | None
init_buffer ¶
init_buffer(
max_num_batched_tokens: int,
max_num_kv_tokens: int,
model_config: ModelConfig,
instance_id: str,
) -> None
Initialize the device buffer and optionally shared memory buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_num_batched_tokens | int | Maximum number of tokens in a batch. | required |
max_num_kv_tokens | int | Maximum number of KV tokens for shared memory. | required |
model_config | ModelConfig | Model configuration containing layer and expert info. | required |
instance_id | str | Unique identifier for the shared memory buffer. | required |
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
save_captured_experts ¶
save_captured_experts(indices: ndarray) -> None
Save captured experts from device buffer to shared memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices | ndarray | Array of indices indicating where to store the data. | required |
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
RoutedExpertsReader ¶
Reader for routed experts from shared memory.
This class attaches to shared memory created by RoutedExpertsCapturer and reads expert routing decisions.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | |
__del__ ¶
__init__ ¶
attach_buffer ¶
attach_buffer(
max_num_kv_tokens: int,
model_config: ModelConfig,
instance_id: str,
) -> None
Attach to an existing shared memory buffer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_num_kv_tokens | int | Maximum number of KV tokens. | required |
model_config | ModelConfig | Model configuration. | required |
instance_id | str | Unique identifier for the shared memory buffer. | required |
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
cleanup ¶
Explicitly clean up resources (close without unlink).
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
create classmethod ¶
create() -> RoutedExpertsReader
Create a global singleton instance.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
get_instance staticmethod ¶
get_instance() -> RoutedExpertsReader | None
Get the global singleton instance.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
get_routed_experts ¶
Read routed expert data from shared memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices | ndarray | Array of indices to read. | required |
Returns:
| Type | Description |
|---|---|
ndarray | Copy of the expert routing data for the given indices. |
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
_create_or_attach_shared_memory ¶
_create_or_attach_shared_memory(
name: str, size: int, lock_file: str
) -> SharedMemory
Create or attach to shared memory with proper locking.
Source code in vllm/model_executor/layers/fused_moe/routed_experts_capturer.py
_file_lock ¶
Context manager for file-based locking.