[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
|
||||
|
||||
Reference in New Issue
Block a user