vllm.forward_context ¶
BatchDescriptor dataclass ¶
Batch descriptor for cudagraph dispatching. We should keep the num of items as minimal as possible to properly and uniquely describe the padded batch for cudagraph.
Source code in vllm/forward_context.py
has_lora class-attribute instance-attribute ¶
has_lora: bool = False
Whether this batch has active LoRA adapters.
num_active_loras class-attribute instance-attribute ¶
num_active_loras: int = 0
Number of distinct active LoRA adapters in this batch. When cudagraph_specialize_lora_count is enabled, separate CUDA graphs are captured for each num_active_loras value. This allows kernels (like fused_moe_lora) whose grid size depends on num_active_loras to be properly captured.
DPMetadata dataclass ¶
Source code in vllm/forward_context.py
sp_local_sizes ¶
sp_local_sizes(sequence_parallel_size: int)
Context manager for setting self.local_sizes. Same as self.chunked_sizes but without any chunking.
Source code in vllm/forward_context.py
ForwardContext dataclass ¶
Source code in vllm/forward_context.py
slot_mapping instance-attribute ¶
Type Dict[str, AttentionMetadata] for v1, map from layer_name of each attention layer to its attention metadata Type List[Dict[str, AttentionMetadata]] for DBO. List of size two, one for each microbatch. Set dynamically for each forward pass
get_forward_context ¶
get_forward_context() -> ForwardContext
Get the current forward context.
Source code in vllm/forward_context.py
override_forward_context ¶
override_forward_context(
forward_context: ForwardContext | None,
)
A context manager that overrides the current forward context. This is used to override the forward context for a specific forward pass.
Source code in vllm/forward_context.py
set_forward_context ¶
set_forward_context(
attn_metadata: Any,
vllm_config: VllmConfig,
num_tokens: int | None = None,
num_tokens_across_dp: Tensor | None = None,
cudagraph_runtime_mode: CUDAGraphMode = NONE,
batch_descriptor: BatchDescriptor | None = None,
ubatch_slices: UBatchSlices | None = None,
slot_mapping: dict[str, Tensor]
| list[dict[str, Tensor]]
| None = None,
skip_compiled: bool = False,
)
A context manager that stores the current forward context, can be attention metadata, etc. Here we can inject common logic for every model forward pass.
Source code in vllm/forward_context.py
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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |