Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vllm/config/speculative.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing_extensions import Self

from vllm.config import LoadConfig
from vllm.config.cache import CacheDType
from vllm.config.kernel import MoEBackend
from vllm.config.model import HfOverrides, ModelConfig
from vllm.config.parallel import ParallelConfig
Expand Down Expand Up @@ -118,6 +119,9 @@ class SpeculativeConfig:
"""Attention backend to use for the draft model. When `None`, the backend is
automatically selected. Useful when the drafter requires a different attention
backend (e.g. DFlash needs a non-causal-capable backend like FLASH_ATTN)."""
kv_cache_dtype: CacheDType | None = None
"""KV cache dtype for the draft model. When `None`, the draft inherits the
target model's `--kv-cache-dtype`."""
max_model_len: int | None = Field(default=None, ge=1)
"""The maximum model length of the draft model. Used when testing the
ability to skip speculation for some sequences."""
Expand Down
4 changes: 4 additions & 0 deletions vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,10 @@ def create_speculative_config(
if self.speculative_config is None:
return None

self.speculative_config = {
k.replace("-", "_"): v for k, v in self.speculative_config.items()
}

# Note(Shangming): These parameters are not obtained from the cli arg
# '--speculative-config' and must be passed in when creating the engine
# config.
Expand Down
9 changes: 9 additions & 0 deletions vllm/v1/spec_decode/llm_base_proposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,15 @@ def _create_draft_vllm_config(self) -> VllmConfig:
),
)

if spec_cfg.kv_cache_dtype is not None:
base = replace(
base,
cache_config=replace(
base.cache_config,
cache_dtype=spec_cfg.kv_cache_dtype,
),
)

return base

def _get_model(self) -> nn.Module:
Expand Down
8 changes: 8 additions & 0 deletions vllm/v1/worker/gpu/spec_decode/dflash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def load_dflash_model(target_model: nn.Module, vllm_config: VllmConfig) -> nn.Mo
use_non_causal=dflash_has_any_non_causal(draft_model_config.hf_config),
backend=speculative_config.attention_backend,
),
cache_config=(
replace(
vllm_config.cache_config,
cache_dtype=speculative_config.kv_cache_dtype,
)
if speculative_config.kv_cache_dtype is not None
else vllm_config.cache_config
),
)
with set_model_tag("dflash_head"):
dflash_model = get_model(
Expand Down
8 changes: 8 additions & 0 deletions vllm/v1/worker/gpu/spec_decode/dspark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ def load_dspark_model(target_model: nn.Module, vllm_config: VllmConfig) -> nn.Mo
use_non_causal=dflash_has_any_non_causal(draft_model_config.hf_config),
backend=speculative_config.attention_backend,
),
cache_config=(
replace(
vllm_config.cache_config,
cache_dtype=speculative_config.kv_cache_dtype,
)
if speculative_config.kv_cache_dtype is not None
else vllm_config.cache_config
),
)

with set_model_tag("dspark_head"):
Expand Down
10 changes: 9 additions & 1 deletion vllm/v1/worker/gpu/spec_decode/eagle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch
import torch.nn as nn

from vllm.config import VllmConfig
from vllm.config import VllmConfig, replace
from vllm.distributed.parallel_state import get_pp_group
from vllm.lora.layers.base import BaseLayerWithLoRA
from vllm.model_executor.model_loader import get_model
Expand Down Expand Up @@ -39,6 +39,14 @@ def load_eagle_model(target_model: nn.Module, vllm_config: VllmConfig) -> nn.Mod
speculative_config = vllm_config.speculative_config
assert speculative_config is not None
draft_model_config = speculative_config.draft_model_config
if speculative_config.kv_cache_dtype is not None:
vllm_config = replace(
vllm_config,
cache_config=replace(
vllm_config.cache_config,
cache_dtype=speculative_config.kv_cache_dtype,
),
)
with set_model_tag("eagle_head"):
eagle_model = get_model(
vllm_config=vllm_config, model_config=draft_model_config
Expand Down
Loading