Support loading sample_from_anchor flag from speculators config (#48639)

Signed-off-by: Fynn Schmitt-Ulms <fschmitt@redhat.com>
Co-authored-by: Michael Goin <mgoin64@gmail.com>
This commit is contained in:
Fynn Schmitt-Ulms
2026-07-20 14:52:43 -07:00
committed by GitHub
co-authored by Michael Goin
parent 5feb3950e5
commit 642076d26c
3 changed files with 24 additions and 6 deletions
@@ -57,6 +57,15 @@ class DFlashSpeculator(DraftModelSpeculator):
# Whether the anchor query position is itself a prediction. DFlash default uses
# the anchor as the bonus token (only mask tokens predict); DSpark samples from
# the anchor and the N-1 mask token positions. See _prepare_dflash_inputs_kernel
dflash_config = (
getattr(self.draft_model_config.hf_config, "dflash_config", None) or {}
)
if dflash_config.get("sample_from_anchor", False):
raise ValueError(
"sample_from_anchor=True is not supported for DFlash. "
"DFlash uses a fixed 1+N query layout where the anchor "
"is the bonus token."
)
self.sample_from_anchor = False
# Context positions for the K/V precompute. Populated by
@@ -40,10 +40,11 @@ class DSparkSpeculator(DFlashSpeculator):
def __init__(self, vllm_config: VllmConfig, device: torch.device):
super().__init__(vllm_config, device)
# Anchor-as-first (N slots) unless the checkpoint uses the 1+N fill-in
# block, where the anchor is a separate bonus token.
self.sample_from_anchor = not getattr(
self.draft_model_config.hf_config, "dspark_bonus_anchor", False
# Whether to sample from the anchor position. When True, uses anchor-as-first
# (N slots, each position predicts the next token). When False, uses 1+N
# fill-in block (anchor is a bonus token).
self.sample_from_anchor = getattr(
self.draft_model_config.hf_config, "sample_from_anchor", True
)
if self.sample_from_anchor:
self.num_query_per_req = self.num_speculative_steps