[Bugfix] Forward callable hf_overrides to the draft model config (#45352)

Signed-off-by: HumphreySun98 <humphreysun98@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Cyrus Leung <tlleungac@connect.ust.hk>
This commit is contained in:
Humphrey
2026-07-06 21:12:38 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Cyrus Leung
parent 2f71b2bd9f
commit cbe9c40f99
3 changed files with 148 additions and 3 deletions
+42 -1
View File
@@ -2,6 +2,8 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import copy
import functools
from collections.abc import Callable
from typing import TYPE_CHECKING, Any, Literal, get_args
from pydantic import Field, SkipValidation, field_validator, model_validator
@@ -588,6 +590,40 @@ class SpeculativeConfig:
return hf_config
@staticmethod
def _apply_composed_hf_override(
target_hf_overrides: Callable[[PretrainedConfig], PretrainedConfig],
hf_config: PretrainedConfig,
) -> PretrainedConfig:
hf_config = SpeculativeConfig.hf_config_override(hf_config)
return target_hf_overrides(hf_config)
@staticmethod
def compose_draft_hf_overrides(
target_hf_overrides: HfOverrides | None,
) -> Callable[[PretrainedConfig], PretrainedConfig]:
"""Build the ``hf_overrides`` for the draft ``ModelConfig``.
Callable overrides on the target are config-to-config transforms
(e.g. test harnesses shrinking ``num_hidden_layers``) and must also
reach the draft config — otherwise a draft belonging to a large
target is instantiated at full size even when the target is shrunk.
Dict overrides are target-specific key patches and are not applied
to the draft.
The composed override must stay picklable: the draft ``ModelConfig``
is sent to spawned engine-core processes, so a local closure would
fail with ``Can't get local object`` during pickling. Bind the
target via ``functools.partial`` over a module-referenceable static
method instead.
"""
if not callable(target_hf_overrides):
return SpeculativeConfig.hf_config_override
return functools.partial(
SpeculativeConfig._apply_composed_hf_override, target_hf_overrides
)
def __post_init__(self):
# Note: "method" is a new parameter that helps to extend the
# configuration of non-model-based proposers, and the "model" parameter
@@ -752,7 +788,12 @@ class SpeculativeConfig:
if self.method == "medusa":
draft_hf_overrides = {"model_type": "medusa"}
else:
draft_hf_overrides = SpeculativeConfig.hf_config_override
# Compose any callable hf_overrides set on the target so the
# draft config receives the same transform (e.g. the test
# shrink). Dict overrides stay target-only.
draft_hf_overrides = SpeculativeConfig.compose_draft_hf_overrides(
self.target_model_config.hf_overrides
)
self.draft_model_config = ModelConfig(
model=self.model,
runner="draft",