[Bugfix] Enhance extra_config handling for layer name suffix matching (#48589)
Signed-off-by: Xin He <xin3.he@intel.com> Co-authored-by: Kunshang Ji <kunshang.ji@intel.com>
This commit is contained in:
@@ -243,6 +243,27 @@ def test_inc_config_parser_parallel_lm_head_defaults_to_unquantized() -> None:
|
||||
assert layer_config.bits == 16
|
||||
|
||||
|
||||
def test_inc_config_parser_suffix_match_for_lm_head() -> None:
|
||||
"""Short extra_config key should match fully-qualified lm_head layer name."""
|
||||
layer = object.__new__(ParallelLMHead)
|
||||
config = make_config(
|
||||
extra_config={
|
||||
"lm_head": {
|
||||
"bits": 4,
|
||||
"group_size": 128,
|
||||
"sym": True,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
layer_config = config.config_parser.resolve(layer, "model.language_model.lm_head")
|
||||
|
||||
assert layer_config.quantized is True
|
||||
assert layer_config.bits == 4
|
||||
assert layer_config.group_size == 128
|
||||
assert layer_config.sym is True
|
||||
|
||||
|
||||
def test_inc_config_parser_fused_moe_requires_consistent_configs() -> None:
|
||||
config = make_config(
|
||||
extra_config={
|
||||
@@ -790,6 +811,34 @@ def test_inc_get_quant_method_linear_uses_resolved_scheme(monkeypatch) -> None:
|
||||
assert method is sentinel
|
||||
|
||||
|
||||
def test_inc_get_quant_method_lm_head_uses_suffix_match(monkeypatch) -> None:
|
||||
"""lm_head extra_config should apply to fully-qualified prefix."""
|
||||
config = make_config(
|
||||
extra_config={
|
||||
"lm_head": {
|
||||
"bits": 4,
|
||||
"group_size": 128,
|
||||
"sym": True,
|
||||
}
|
||||
}
|
||||
)
|
||||
layer = object.__new__(ParallelLMHead)
|
||||
sentinel = object()
|
||||
|
||||
class DummyScheme:
|
||||
def get_linear_method(self, _config, _layer, _prefix, _layer_config):
|
||||
return sentinel
|
||||
|
||||
monkeypatch.setattr(
|
||||
"vllm.model_executor.layers.quantization.inc.schemes.factory.resolve_scheme",
|
||||
lambda _layer_config: DummyScheme(),
|
||||
)
|
||||
|
||||
method = config.get_quant_method(layer, "model.language_model.lm_head")
|
||||
|
||||
assert method is sentinel
|
||||
|
||||
|
||||
def test_inc_get_quant_method_moe_uses_resolved_scheme(monkeypatch) -> None:
|
||||
config = make_config()
|
||||
layer = object.__new__(RoutedExperts)
|
||||
|
||||
@@ -142,6 +142,14 @@ class INCConfigParser:
|
||||
if self._config.extra_config and layer_name in self._config.extra_config:
|
||||
return get_config(layer_name)
|
||||
|
||||
# Suffix match: handle cases where extra_config keys use short names
|
||||
# (e.g. "lm_head") but the layer_name is fully qualified
|
||||
# (e.g. "model.language_model.lm_head") due to model nesting.
|
||||
if self._config.extra_config:
|
||||
for cfg_key in self._config.extra_config:
|
||||
if layer_name.endswith(f".{cfg_key}"):
|
||||
return get_config(cfg_key)
|
||||
|
||||
quantized = not isinstance(layer, ParallelLMHead)
|
||||
if self._config.block_name_to_quantize:
|
||||
quantized = any(
|
||||
|
||||
Reference in New Issue
Block a user