vllm.v1.worker.gpu.spec_decode.speculator
¶
Classes:
-
BaseSpeculator–Base class for V2 model runner speculators.
-
DraftModelSpeculator–
BaseSpeculator
¶
Bases: ABC
Base class for V2 model runner speculators.
This is also the interface for custom speculators, named by the
speculator_class of their registered SpeculatorConfig (see
register_speculative_method). Speculators that run a draft model
should subclass DraftModelSpeculator (or TargetDependentARSpeculator if
drafting consumes target model state), which the model runner loads and
allocates draft KV cache for.
Methods:
-
add_request–A new or resumed request was assigned request-state slot
-
on_requests_finished–Requests finished (not preempted), before their request-state slots
-
prepare_watermarking–Prepare draft-side watermarking before
propose. No-op by default. -
reset_state–Forget anything learned across requests, called after the warmup
-
shutdown–Called when the model runner shuts down. Detaches a draft
model's -
update_max_model_len–Apply a reduced max_model_len. Auto-fit can call this after capture,
add_request(req_index, new_req_data)
¶
A new or resumed request was assigned request-state slot
req_index, e.g. to reset per-slot state. No-op by default.
on_requests_finished(finished_req_ids)
¶
Requests finished (not preempted), before their request-state slots are freed so their token history is still readable. No-op by default.
prepare_watermarking(sampler, idx_mapping)
¶
Prepare draft-side watermarking before propose. No-op by default.
reset_state()
¶
Forget anything learned across requests, called after the warmup requests have finished. No-op by default.
shutdown()
¶
Called when the model runner shuts down. Detaches a draft model's
layer KV caches and bytecode hooks, since the model object can outlive
the runner. Overrides must call super().shutdown().
update_max_model_len(max_model_len)
¶
Apply a reduced max_model_len. Auto-fit can call this after capture, when CUDA graphs no longer see Python values. No-op by default.
DraftModelSpeculator
¶
Bases: BaseSpeculator
Methods:
-
draft_logits_spec–Dtype and fill for the cached proposal distribution.
-
free_unused_weights–Free the draft weights this instance never reads. The model runner
-
observe_verification–Fold the target's verdict on the last drafts into the estimator.
-
prepare_propose–Per-step work between verifying the last drafts and the next
-
set_eplb_state–Inject EPLB state after construction.
-
supports_batch_sharded_draft_logits–Whether every draft logits write on this speculator's path honors
Attributes:
-
attn_vllm_config(VllmConfig) –Config for the draft's attention metadata builders. Overridden by
attn_vllm_config
property
¶
Config for the draft's attention metadata builders. Overridden by speculators whose attention mode differs from the target's.
_build_drafter_attn_metadata(input_batch, attn_metadata, slot_mappings, cg_mode=CUDAGraphMode.NONE, for_capture=False)
¶
Attention metadata and slot mappings for draft prefill on the target batch: the target forward's when reusable, else rebuilt on the draft builders from the block tables and slot mappings the target prepared. Must run before draft decode steps overwrite the slot mappings.
_init_draft_logits(target_model)
¶
Allocate the draft logits cache.
Under batch-sharded sampling, the rank that verifies a request is the only one that reads its draft logits, so each TP rank keeps just the rows of the requests it owns. See DraftLogitsCache.
_map_kernel_block_tables()
¶
Refresh the persistent kernel block tables a FULL graph reads.
_prepare_eplb_forward(num_unpadded_tokens)
¶
Call EPLB prepare_forward if EPLB is active for the draft model.
draft_logits_spec(vllm_config)
¶
Dtype and fill for the cached proposal distribution.
Speculators that write only a subset of columns each step override this.
free_unused_weights(target_model)
¶
Free the draft weights this instance never reads. The model runner
calls this after load_model (and its overrides) and EPLB setup.
observe_verification(idx_mapping, num_sampled, num_rejected)
¶
Fold the target's verdict on the last drafts into the estimator.
Must run before the next propose, which overwrites the per-slot
features the verdict grades.
prepare_propose(input_batch, num_sampled, num_rejected, sampler)
¶
Per-step work between verifying the last drafts and the next
propose.
set_eplb_state(eplb_state)
¶
Inject EPLB state after construction.
supports_batch_sharded_draft_logits()
¶
Whether every draft logits write on this speculator's path honors DraftLogitsCache.row_mapping.
_target_feeds_hc_residual(vllm_config)
¶
Whether the target replaces the drafter's input with its HC residual.
Keyed on the same hook the model runner calls to perform that swap. It is resolved from the target model class because speculators are built before the target model is instantiated.