[Bugfix][Spec Decode] Separate DSpark width from MTP stage validation (#54631)
Signed-off-by: Luca Motz <luca.motz@icloud.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
44bf011f44
commit
ee2f3cdf12
@@ -47,6 +47,91 @@ def test_none_overrides_fall_back_to_arch_mapping():
|
||||
assert composed is SpeculativeConfig.hf_config_override
|
||||
|
||||
|
||||
def _make_speculative_config(
|
||||
hf_kwargs: dict, architecture: str, **speculative_kwargs
|
||||
) -> SpeculativeConfig:
|
||||
hf_config = SpeculativeConfig.hf_config_override(_make_hf_config(**hf_kwargs))
|
||||
draft = MagicMock(
|
||||
hf_config=hf_config, architectures=hf_config.architectures, max_model_len=128
|
||||
)
|
||||
draft.registry.inspect_model_cls.return_value = (None, architecture)
|
||||
target = MagicMock(max_model_len=128, quantization=None, hf_overrides={})
|
||||
target.hf_config.model_type = hf_kwargs["model_type"]
|
||||
|
||||
with patch("vllm.config.speculative.ModelConfig", return_value=draft):
|
||||
return SpeculativeConfig(
|
||||
model="draft",
|
||||
**speculative_kwargs,
|
||||
target_model_config=target,
|
||||
target_parallel_config=ParallelConfig(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.cpu_test
|
||||
@pytest.mark.parametrize(
|
||||
("hf_kwargs", "n_predict", "architecture"),
|
||||
[
|
||||
(
|
||||
dict(
|
||||
model_type="deepseek_v4",
|
||||
num_nextn_predict_layers=3,
|
||||
dspark_block_size=5,
|
||||
),
|
||||
3,
|
||||
"DSparkDraftModel",
|
||||
),
|
||||
(
|
||||
dict(
|
||||
model_type="deepseek_v41",
|
||||
num_nextn_predict_layers=3,
|
||||
dspark_block_size=5,
|
||||
),
|
||||
3,
|
||||
"DSparkV41DraftModel",
|
||||
),
|
||||
(
|
||||
dict(
|
||||
model_type="gemma4_text",
|
||||
architectures=["Gemma4DSparkModel"],
|
||||
block_size=5,
|
||||
),
|
||||
None,
|
||||
"Gemma4DSparkModel",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize("speculative_kwargs", [{"num_speculative_tokens": 5}, {}])
|
||||
def test_dspark_width_is_independent_of_mtp_stages(
|
||||
hf_kwargs, n_predict, architecture, speculative_kwargs
|
||||
):
|
||||
config = _make_speculative_config(
|
||||
hf_kwargs, architecture, method="dspark", **speculative_kwargs
|
||||
)
|
||||
|
||||
assert config.num_speculative_tokens == 5
|
||||
assert getattr(config.draft_model_config.hf_config, "n_predict", None) == n_predict
|
||||
assert config.draft_model_config.hf_config.architectures == [architecture]
|
||||
|
||||
|
||||
@pytest.mark.cpu_test
|
||||
def test_mtp_stages_are_independent_of_dspark_width():
|
||||
hf_kwargs = dict(
|
||||
model_type="deepseek_v4", num_nextn_predict_layers=3, dspark_block_size=5
|
||||
)
|
||||
config = _make_speculative_config(
|
||||
hf_kwargs, "DeepSeekV4MTPModel", method="mtp", num_speculative_tokens=6
|
||||
)
|
||||
|
||||
assert config.num_speculative_tokens == 6
|
||||
assert config.draft_model_config.hf_config.n_predict == 3
|
||||
assert config.draft_model_config.hf_config.architectures == ["DeepSeekV4MTPModel"]
|
||||
|
||||
with pytest.raises(ValueError, match="must be divisible by n_predict=3"):
|
||||
_make_speculative_config(
|
||||
hf_kwargs, "DeepSeekV4MTPModel", method="mtp", num_speculative_tokens=5
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.cpu_test
|
||||
def test_callable_overrides_reach_the_draft_config():
|
||||
"""A callable override (config-to-config transform) composes with the
|
||||
|
||||
+11
-16
@@ -694,8 +694,8 @@ class SpeculativeConfig:
|
||||
if hf_config.model_type in ("deepseek_v4", "deepseek_v41"):
|
||||
# V4.1 has no classic-MTP draft: its checkpoints ship DSpark stages
|
||||
# under ``mtp.*``, so only V4 gets an MTP architecture here. The
|
||||
# DSpark path rewrites ``architectures`` itself and needs only
|
||||
# ``n_predict``; ``method="mtp"`` on V4.1 is rejected below.
|
||||
# DSpark path rewrites ``architectures`` itself;
|
||||
# ``method="mtp"`` on V4.1 is rejected below.
|
||||
is_v41 = hf_config.model_type == "deepseek_v41"
|
||||
hf_config.model_type = "deepseek_mtp"
|
||||
n_predict = getattr(hf_config, "num_nextn_predict_layers", None)
|
||||
@@ -1440,14 +1440,6 @@ class SpeculativeConfig:
|
||||
draft_hf_config.architectures = [
|
||||
"DSparkV41DraftModel" if is_v41 else "DSparkDraftModel"
|
||||
]
|
||||
if is_v41:
|
||||
# hf_config_override set n_predict to the number of
|
||||
# MTP stages (3), but one DSpark round drafts
|
||||
# dspark_block_size tokens; num_speculative_tokens
|
||||
# divisibility is checked against n_predict below.
|
||||
draft_hf_config.n_predict = getattr(
|
||||
draft_hf_config, "dspark_block_size", None
|
||||
) or getattr(draft_hf_config, "n_predict", None)
|
||||
self.draft_model_config.quantization = (
|
||||
self.target_model_config.quantization
|
||||
)
|
||||
@@ -1464,11 +1456,6 @@ class SpeculativeConfig:
|
||||
and getattr(hf, "target_layer_ids", None) is not None
|
||||
):
|
||||
hf.dspark_target_layer_ids = hf.target_layer_ids
|
||||
if (
|
||||
getattr(hf, "n_predict", None) is None
|
||||
and getattr(hf, "block_size", None) is not None
|
||||
):
|
||||
hf.n_predict = hf.block_size
|
||||
|
||||
if self.method in ("dflash", "dspark"):
|
||||
self.parallel_drafting = True
|
||||
@@ -1483,7 +1470,15 @@ class SpeculativeConfig:
|
||||
n_predict = getattr(
|
||||
self.draft_model_config.hf_config, "n_predict", None
|
||||
)
|
||||
if n_predict is not None:
|
||||
if self.use_dspark():
|
||||
if self.num_speculative_tokens is None:
|
||||
# DSpark's parallel width is independent of MTP stages.
|
||||
hf_config = self.draft_model_config.hf_config
|
||||
block_size = getattr(hf_config, "block_size", None)
|
||||
if block_size is None:
|
||||
block_size = getattr(hf_config, "dspark_block_size", None)
|
||||
self.num_speculative_tokens = block_size
|
||||
elif n_predict is not None:
|
||||
if self.num_speculative_tokens is None:
|
||||
# Default to max value defined in draft model config.
|
||||
self.num_speculative_tokens = n_predict
|
||||
|
||||
Reference in New Issue
Block a user