vllm.v1.worker.gpu.model_states.interface
¶
Classes:
-
ModelSpecificAttnMetadata–Base class for model-specific attention metadata.
-
ModelState–
ModelSpecificAttnMetadata
¶
Base class for model-specific attention metadata.
ModelState
¶
Bases: ABC
Methods:
-
capture_inner_cudagraphs–Capture the CUDA graphs this state runs inside the model's forward,
-
compute_sample_logits–Project the sampled hidden states to the logits fed to the sampler.
-
custom_sampler–Wrap or replace the default sampler.
-
dummy_inputs_embeds–Pre-allocated inputs_embeds buffer for dummy runs.
-
dummy_sampler_run–Run a model-specific sampler profiling pass.
-
execute_mm_encoder–Run the multi-modal encoder and cache its outputs by
mm_hash. -
gather_mm_embeddings–Gather cached multimodal embeddings.
-
get_additional_cg_support–Cudagraph support of attention groups this ModelState builds outside
-
get_mrope_position_delta–M-RoPE position delta of the request at
req_index, or None if the -
initialize_kv_cache–Hook run after the KV cache tensors are allocated and bound.
-
prepare_inputs_embeds–Prepare the
inputs_embedstensor for the current forward pass. -
preprocess_state–Hook run on real batches before the forward pass (after block tables
Attributes:
-
num_new_sampled_tokens_per_step(int) –New tokens sampled on each decode step
-
positions_depend_on_encoder(bool) –Whether the positions this state prepares depend on encoder outputs.
-
supports_prompt_embeds(bool) –Whether this state implements user-provided prompt embeddings.
num_new_sampled_tokens_per_step = 1
class-attribute
instance-attribute
¶
New tokens sampled on each decode step (excluding accepted draft tokens, a.k.a num bonus tokens).
positions_depend_on_encoder = False
class-attribute
instance-attribute
¶
Whether the positions this state prepares depend on encoder outputs. Only the first PP stage runs the encoder, so later stages take the positions from it.
supports_prompt_embeds = False
class-attribute
¶
Whether this state implements user-provided prompt embeddings.
capture_inner_cudagraphs(input_buffers, block_tables, attn_groups, kv_cache_config, stream=None)
¶
Capture the CUDA graphs this state runs inside the model's forward,
on stream: the model graphs' capture stream.
compute_sample_logits(hidden_states)
¶
Project the sampled hidden states to the logits fed to the sampler.
custom_sampler(sampler)
¶
Wrap or replace the default sampler.
Called after model loading with the already-constructed base
Sampler. Return None to keep the defaults, or
(sampler, rejection_sampler | None) to override.
dummy_inputs_embeds(num_tokens, input_ids=None)
¶
Pre-allocated inputs_embeds buffer for dummy runs.
Holds the embeddings of input_ids when given; otherwise the contents
are unused.
dummy_sampler_run(sampler, hidden_states)
¶
Run a model-specific sampler profiling pass.
Return True to skip the default dummy sampler run.
execute_mm_encoder(scheduled_encoder_inputs)
¶
Run the multi-modal encoder and cache its outputs by mm_hash.
The encode half of get_mm_embeddings, without the gather, for callers
that run no language model.
gather_mm_embeddings(input_batch, draft_lookahead=0)
¶
Gather cached multimodal embeddings.
get_additional_cg_support()
¶
Cudagraph support of attention groups this ModelState builds outside
init_attn_backend (e.g. encoder-only layers).
Returns the minimum support level and its backend name. The default of
ALWAYS imposes no extra constraint on the runner's cudagraph mode.
get_mrope_position_delta(req_index)
¶
M-RoPE position delta of the request at req_index, or None if the
model does not use M-RoPE.
initialize_kv_cache(kv_cache_config, block_tables)
¶
Hook run after the KV cache tensors are allocated and bound.
prepare_inputs_embeds(scheduled_encoder_inputs, input_batch, req_states)
abstractmethod
¶
Prepare the inputs_embeds tensor for the current forward pass.
preprocess_state(input_batch, block_tables, kv_cache_config, num_computed_tokens)
¶
Hook run on real batches before the forward pass (after block tables are gathered). Used by mamba prefix caching to pre-copy state across block boundaries. No-op by default.