diff --git a/vllm/transformers_utils/configs/speculators/algos.py b/vllm/transformers_utils/configs/speculators/algos.py index e034cec974..fbd2c45181 100644 --- a/vllm/transformers_utils/configs/speculators/algos.py +++ b/vllm/transformers_utils/configs/speculators/algos.py @@ -106,6 +106,9 @@ def update_dflash(config_dict: dict, pre_trained_config: dict) -> None: DFlash drafter. Mapped to both eagle_aux_hidden_state_layer_ids (for gpu_model_runner) and dflash_config.target_layer_ids (for the DFlash model). + - sample_from_anchor: Whether to sample from the anchor position. Default + False (anchor is a bonus token, only mask tokens predict, yielding + block_size - 1 speculative tokens). """ pre_trained_config["architectures"] = ["DFlashDraftModel"] pre_trained_config["draft_vocab_size"] = config_dict.get("draft_vocab_size") @@ -119,6 +122,7 @@ def update_dflash(config_dict: dict, pre_trained_config: dict) -> None: pre_trained_config["dflash_config"] = { "mask_token_id": config_dict["mask_token_id"], "target_layer_ids": [i - 1 for i in aux_layer_ids], + "sample_from_anchor": config_dict.get("sample_from_anchor", False), } # Enable causal masking in SWA for vllm-project/speculators models pre_trained_config["dflash_config"]["causal"] = not config_dict.get( @@ -146,10 +150,14 @@ def update_dspark(config_dict: dict, pre_trained_config: dict) -> None: - aux_hidden_state_layer_ids (required): target layer indices feeding the drafter. Mapped to both eagle_aux_hidden_state_layer_ids and target_layer_ids (DSpark's i-1 layer semantics). + - sample_from_anchor: Whether to sample from the anchor position. Default + False (anchor is a bonus token, only mask tokens predict, yielding + block_size - 1 speculative tokens). """ pre_trained_config["architectures"] = ["Qwen3DSparkModel"] - # Speculators DSpark uses the 1+N fill-in block (anchor is a bonus token). - pre_trained_config["dspark_bonus_anchor"] = True + pre_trained_config["sample_from_anchor"] = config_dict.get( + "sample_from_anchor", False + ) aux_layer_ids = config_dict["aux_hidden_state_layer_ids"] pre_trained_config["eagle_aux_hidden_state_layer_ids"] = aux_layer_ids diff --git a/vllm/v1/worker/gpu/spec_decode/dflash/speculator.py b/vllm/v1/worker/gpu/spec_decode/dflash/speculator.py index 9b39c6572f..645469e611 100644 --- a/vllm/v1/worker/gpu/spec_decode/dflash/speculator.py +++ b/vllm/v1/worker/gpu/spec_decode/dflash/speculator.py @@ -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 diff --git a/vllm/v1/worker/gpu/spec_decode/dspark/speculator.py b/vllm/v1/worker/gpu/spec_decode/dspark/speculator.py index 9000ae878a..45dedde3d7 100644 --- a/vllm/v1/worker/gpu/spec_decode/dspark/speculator.py +++ b/vllm/v1/worker/gpu/spec_decode/dspark/speculator.py @@ -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