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.
-
in_piecewise_cudagraph–Whether the current forward runs in piecewise cudagraph mode (graph
-
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:
-
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.
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
sp_local_sizes(sequence_parallel_size, pcp_size=1, use_ep=False)
¶
Context manager for setting self.local_sizes. Same as self.chunked_sizes but without any chunking.
ForwardContext
dataclass
¶
Attributes:
-
slot_mapping(dict[str, Tensor] | list[dict[str, Tensor]]) –Type Dict[str, AttentionMetadata] for v1, map from layer_name of each
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.
in_piecewise_cudagraph()
¶
Whether the current forward runs in piecewise cudagraph mode (graph segments separated by eager breaks), at capture or replay time.
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.
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.