[Bugfix][ROCm] AMD-Quark mixed-precision DeepSeek-V4.1 support (#57071)
Signed-off-by: Xiao Yu <xiao.yu.dc@outlook.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -228,6 +228,85 @@ def test_deepseek_v41_vl_mapper_routes_linear_scales(
|
||||
]
|
||||
|
||||
|
||||
def test_deepseek_v41_vl_exposes_quant_mappings_on_class():
|
||||
"""``configure_quant_config`` reads both mappings off the class, before
|
||||
``__init__`` builds the instance mapper. Without them a Quark config's
|
||||
per-layer keys never match this wrapper's ``language_model.``-rooted
|
||||
prefixes and every attention shard falls back to the global spec."""
|
||||
from vllm.models.deepseek_v41.amd.vl_model import DeepseekV41ForCausalLM
|
||||
|
||||
assert "fused_wqa_wkv" in DeepseekV41ForCausalLM.packed_modules_mapping
|
||||
mapper = DeepseekV41ForCausalLM.hf_to_vllm_mapper.get_rename_mapper()
|
||||
assert mapper.apply_list(["layers.0.attn.wq_a"]) == [
|
||||
"language_model.model.layers.0.attn.wq_a"
|
||||
]
|
||||
|
||||
|
||||
def test_deepseek_v41_engram_scale_accepts_quark_name():
|
||||
"""Quark exports name the engram scale ``embed.weight_scale``; the
|
||||
``\\.scale$`` rules only match a literal ``.scale`` suffix, so without an
|
||||
explicit rule the tensor is never routed and loading fails."""
|
||||
from vllm.models.deepseek_v41.amd import model as model_module
|
||||
|
||||
mapper = model_module._make_deepseek_v4_weights_mapper("fp4", "weight_scale")
|
||||
weight = torch.empty(0)
|
||||
mapped = [
|
||||
name
|
||||
for name, _ in mapper.apply(
|
||||
[
|
||||
("layers.1.engram.embed.weight_scale", weight),
|
||||
("layers.1.engram.embed.scale", weight),
|
||||
]
|
||||
)
|
||||
]
|
||||
assert mapped == [
|
||||
"model.layers.1.engram.embed_tokens.weight_scale_inv",
|
||||
"model.layers.1.engram.embed_tokens.weight_scale_inv",
|
||||
]
|
||||
|
||||
|
||||
def test_deepseek_v41_declines_quark_configs():
|
||||
"""``from_config`` rewrites a Quark config into a single global FP8 scheme,
|
||||
which would discard the per-layer specs of a mixed-precision export (MXFP4
|
||||
experts + 2-D block MXFP8 attention in DeepSeek-V4.1-Flash). QuarkConfig
|
||||
knows how to dispatch each scheme, so it must handle every Quark export."""
|
||||
from vllm.models.deepseek_v41.quant_config import DeepseekV4FP8Config
|
||||
|
||||
hf_config = SimpleNamespace(model_type="deepseek_v41")
|
||||
mxfp4_global = {
|
||||
"global_quant_config": {
|
||||
"weight": {"dtype": "fp4", "qscheme": "per_group", "group_size": 32}
|
||||
},
|
||||
"quant_method": "quark",
|
||||
}
|
||||
|
||||
assert (
|
||||
DeepseekV4FP8Config.override_quantization_method(
|
||||
mxfp4_global, None, hf_config=hf_config
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
mixed = {
|
||||
**mxfp4_global,
|
||||
"layer_quant_config": {
|
||||
"layers.0.attn.wkv": {
|
||||
"weight": {
|
||||
"dtype": "fp8_e4m3",
|
||||
"qscheme": "per_block",
|
||||
"block_size": [32, 32],
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
assert (
|
||||
DeepseekV4FP8Config.override_quantization_method(
|
||||
mixed, None, hf_config=hf_config
|
||||
)
|
||||
is None
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not current_platform.is_cuda(), reason="DeepGEMM requires CUDA")
|
||||
@pytest.mark.parametrize("scale_dtype", [torch.uint8, torch.float8_e8m0fnu])
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user