[Model] Support DeepSeek-V4.1-Flash (#56214)

Signed-off-by: Yongye Zhu <zyy1102000@gmail.com>
Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai>
Signed-off-by: andyluo7 <andy.luo@amd.com>
Signed-off-by: zjy0516 <riverclouds.zhu@qq.com>
Co-authored-by: Jee Jee Li <jeejeelee@inferact.ai>
Co-authored-by: andyluo7 <andy.luo@amd.com>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: zjy0516 <riverclouds.zhu@qq.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yongye Zhu
2026-09-11 02:11:19 -07:00
committed by GitHub
co-authored by Jee Jee Li andyluo7 OpenAI Codex zjy0516 Claude Opus 5
parent e6821ceac9
commit e77daef89e
49 changed files with 3996 additions and 138 deletions
+76
View File
@@ -186,3 +186,79 @@ def test_context_kv_weights_are_loaded_as_merged_linear_shards():
assert [weight.shard_id for _, weight in mapped] == [1, 0, 1, 1]
assert mapped[0][1].data_ptr() == mapped[1][1].data_ptr()
assert mapped[2][1].data_ptr() == mapped[3][1].data_ptr()
@pytest.mark.cpu_test
@pytest.mark.parametrize(
"scale_dtype", [torch.uint8, torch.float8_e8m0fnu, torch.float32]
)
@pytest.mark.parametrize(
("checkpoint_name", "runtime_module", "shard_id"),
[
("mtp.0.attn.wq_a.scale", "model.layers.0.attn.fused_wqa_wkv", 0),
("mtp.0.attn.wkv.scale", "model.layers.0.attn.fused_wqa_wkv", 1),
("mtp.0.main_proj.scale", "model.main_proj", None),
(
"mtp.0.ffn.shared_experts.w1.scale",
"model.layers.0.ffn.shared_experts.gate_up_proj",
0,
),
(
"mtp.0.ffn.shared_experts.w2.scale",
"model.layers.0.ffn.shared_experts.down_proj",
None,
),
],
)
def test_v41_dspark_loads_linear_scales(
monkeypatch, scale_dtype, checkpoint_name, runtime_module, shard_id
):
"""Checkpoint ``.scale`` maps to the quant method's scale parameter and
loads untouched. MXFP8 block-scale expansion lives in the KMxfp8Static
loader (see tests/quantization/test_modelopt.py), not in load_weights."""
from vllm.models.deepseek_v4_1.nvidia import dspark
mxfp8 = scale_dtype != torch.float32
scale_name = "weight_scale" if mxfp8 else "weight_scale_inv"
runtime_name = f"{runtime_module}.{scale_name}"
raw = torch.tensor([[120, 127], [128, 130]], dtype=torch.uint8)
checkpoint_scale = raw.view(scale_dtype) if mxfp8 else raw.float()
param = nn.Parameter(torch.empty_like(checkpoint_scale), requires_grad=False)
shards = []
def load_scale(param, weight, *args):
shards.append(args)
assert weight.dtype == checkpoint_scale.dtype
param.copy_(weight)
param.weight_loader = load_scale
draft = SimpleNamespace(
config=SimpleNamespace(num_attention_heads=4, n_routed_experts=1),
quant_config=SimpleNamespace(
weight_block_size=[32, 32] if mxfp8 else [128, 128]
),
linear_scale_name=scale_name,
pad_shared_expert=False,
model=SimpleNamespace(
layers=[SimpleNamespace(ffn=SimpleNamespace(use_mega_moe=False))],
confidence_head=None,
),
named_parameters=lambda: [(runtime_name, param)],
process_weights_after_loading=lambda: None,
)
draft._remap_dspark_name = lambda name: (
dspark.DSparkDeepseekV4ForCausalLM._remap_dspark_name(draft, name)
)
monkeypatch.setattr(dspark, "get_tensor_model_parallel_world_size", lambda: 4)
monkeypatch.setattr(dspark, "get_tensor_model_parallel_rank", lambda: 0)
monkeypatch.setattr(
dspark, "fused_moe_make_expert_params_mapping", lambda *a, **kw: []
)
loaded = dspark.DSparkDeepseekV4ForCausalLM.load_weights(
draft, [(checkpoint_name, checkpoint_scale)]
)
assert loaded == {runtime_name}
assert shards == [() if shard_id is None else (shard_id,)]
torch.testing.assert_close(param, checkpoint_scale)