Fix Quark mxfp4 quantized model loading issue under mtp (#46757)
Signed-off-by: Xiao Yu <xiao.yu.dc@outlook.com> Co-authored-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
co-authored by
Andreas Karatzas
parent
f61163e6c7
commit
02bf9c7907
@@ -9,7 +9,10 @@ from transformers import PretrainedConfig
|
|||||||
|
|
||||||
from vllm.logger import init_logger
|
from vllm.logger import init_logger
|
||||||
from vllm.model_executor.layers.attention import Attention
|
from vllm.model_executor.layers.attention import Attention
|
||||||
from vllm.model_executor.layers.fused_moe import RoutedExperts
|
from vllm.model_executor.layers.fused_moe import (
|
||||||
|
RoutedExperts,
|
||||||
|
UnquantizedFusedMoEMethod,
|
||||||
|
)
|
||||||
from vllm.model_executor.layers.linear import (
|
from vllm.model_executor.layers.linear import (
|
||||||
LinearBase,
|
LinearBase,
|
||||||
LinearMethodBase,
|
LinearMethodBase,
|
||||||
@@ -146,8 +149,13 @@ class QuarkConfig(QuantizationConfig):
|
|||||||
# Check if the layer is skipped for quantization.
|
# Check if the layer is skipped for quantization.
|
||||||
exclude_layers = cast(list[str], self.quant_config.get("exclude"))
|
exclude_layers = cast(list[str], self.quant_config.get("exclude"))
|
||||||
if should_ignore_layer(
|
if should_ignore_layer(
|
||||||
prefix, ignore=exclude_layers, fused_mapping=self.packed_modules_mapping
|
prefix,
|
||||||
|
ignore=exclude_layers,
|
||||||
|
fused_mapping=self.packed_modules_mapping,
|
||||||
|
check_children=isinstance(layer, RoutedExperts),
|
||||||
):
|
):
|
||||||
|
if isinstance(layer, RoutedExperts):
|
||||||
|
return UnquantizedFusedMoEMethod(layer.moe_config)
|
||||||
if (
|
if (
|
||||||
"self_attn" not in prefix # only quantize attention projections
|
"self_attn" not in prefix # only quantize attention projections
|
||||||
or not getattr(self, "dynamic_mxfp4_quant", False)
|
or not getattr(self, "dynamic_mxfp4_quant", False)
|
||||||
|
|||||||
@@ -27,10 +27,26 @@ def should_ignore_layer(
|
|||||||
layer_name: str | None,
|
layer_name: str | None,
|
||||||
ignore: Iterable[str],
|
ignore: Iterable[str],
|
||||||
fused_mapping: Mapping[str, list[str]] = MappingProxyType({}),
|
fused_mapping: Mapping[str, list[str]] = MappingProxyType({}),
|
||||||
|
*,
|
||||||
|
check_children: bool = False,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if layer_name is None:
|
if layer_name is None:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# MoE layers are currently all-or-nothing: if any child is ignored,
|
||||||
|
# the parent layer must be ignored as well. For example, the
|
||||||
|
# amd/GLM-5.2-MXFP4 config ignores children like
|
||||||
|
# model.layers.78.mlp.experts.*.down_proj, while the layer checked
|
||||||
|
# here is the parent model.layers.N.mlp.experts.
|
||||||
|
# See:
|
||||||
|
# https://huggingface.co/amd/GLM-5.2-MXFP4/blob/main/config.json#L793-L795
|
||||||
|
if check_children and any(
|
||||||
|
target == layer_name or target.startswith(layer_name + ".")
|
||||||
|
for target in ignore
|
||||||
|
if not target.startswith("re:")
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
|
||||||
# layer_name = model.layers.0.self_attn.qkv_proj
|
# layer_name = model.layers.0.self_attn.qkv_proj
|
||||||
# proj_name = qkv_proj
|
# proj_name = qkv_proj
|
||||||
proj_name = layer_name.split(".")[-1]
|
proj_name = layer_name.split(".")[-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user