vllm.forward_context Âķ
Classes:
-
BatchDescriptorâBatch descriptor for cudagraph dispatching. We should keep the num of
-
DPMetadataâ -
ForwardContextâ
Functions:
-
get_forward_contextâGet the current forward context.
-
override_forward_contextâA context manager that overrides the current forward context.
-
set_forward_contextâA context manager that stores the current 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.
Attributes:
-
has_lora(bool) âWhether this batch has active LoRA adapters.
-
num_active_loras(int) âNumber of distinct active LoRA adapters in this batch.
-
num_reqs(int | None) âNumber of requests in the batch. Can be None for PIECEWISE cudagraphs where
-
uniform(bool) âTrue if all the requests in the batch have the same number of tokens.
Source code in vllm/forward_context.py
has_lora = False class-attribute instance-attribute Âķ
Whether this batch has active LoRA adapters.
num_active_loras = 0 class-attribute instance-attribute Âķ
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.
num_reqs = None class-attribute instance-attribute Âķ
Number of requests in the batch. Can be None for PIECEWISE cudagraphs where the cudagraphs can handle any number of requests.
uniform = False class-attribute instance-attribute Âķ
True if all the requests in the batch have the same number of tokens.
DPMetadata dataclass Âķ
Methods:
-
sp_local_sizesâContext manager for setting self.local_sizes. Same as self.chunked_sizes
Source code in vllm/forward_context.py
sp_local_sizes(sequence_parallel_size) Âķ
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 Âķ
Attributes:
-
slot_mapping(dict[str, Tensor] | list[dict[str, Tensor]]) âType Dict[str, AttentionMetadata] for v1, map from layer_name of each
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 the current forward context.
Source code in vllm/forward_context.py
override_forward_context(forward_context) Âķ
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(attn_metadata, vllm_config, num_tokens=None, num_tokens_across_dp=None, cudagraph_runtime_mode=CUDAGraphMode.NONE, batch_descriptor=None, ubatch_slices=None, slot_mapping=None, skip_compiled=False, is_padding=None) Âķ
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
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 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |