[Bugfix] Fix DeepSeek V4 mHC broadcast buffer for dummy load (#51368)

Signed-off-by: Hollow Man <hollowman@opensuse.org>
This commit is contained in:
ℍ𝕠𝕝𝕝𝕠𝕨 𝕄𝕒𝕟
2026-08-18 17:02:18 -07:00
committed by GitHub
parent ef47a897e2
commit a9f4afb66f
4 changed files with 46 additions and 7 deletions
+4 -1
View File
@@ -504,9 +504,9 @@ class DSparkDeepseekV4ForCausalLM(nn.Module):
weight_loader(param, loaded_weight)
loaded_params.add(name)
self._finalize_moe()
if self.model.confidence_head is not None and not loaded_confidence_head:
self.model.confidence_head = None
self.process_weights_after_loading()
logger.info_once("DSpark draft model loaded: %d params", len(loaded_params))
return loaded_params
@@ -514,6 +514,9 @@ class DSparkDeepseekV4ForCausalLM(nn.Module):
for layer in self.model.layers:
layer.ffn.finalize_mega_moe_weights()
def process_weights_after_loading(self) -> None:
self._finalize_moe()
def _remap_dspark_name(self, name: str) -> str | None:
"""Map a checkpoint ``mtp.{i}.*`` name to this model's parameter path.
+4 -5
View File
@@ -504,10 +504,6 @@ class DeepseekV4MegaMoEExperts(nn.Module):
is_padding=is_padding,
)
# This method must have been already called during the weight loading phase.
# We call it again here to cover the dummy weight loading case.
self.finalize_weights()
assert self._transformed_l1_weights is not None
assert self._transformed_l2_weights is not None
deep_gemm.fp8_fp4_mega_moe(
@@ -1543,9 +1539,12 @@ class DeepseekV4ForCausalLM(
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
loader = AutoWeightsLoader(self, skip_substrs=["mtp."])
loaded_params = loader.load_weights(weights, mapper=self.hf_to_vllm_mapper)
self.process_weights_after_loading()
return loaded_params
def process_weights_after_loading(self) -> None:
self.model.finalize_mega_moe_weights()
self.model.finalize_mhc_broadcast_weights()
return loaded_params
def get_expert_mapping(self) -> list[tuple[str, str, int, str]]:
return self.model.get_expert_mapping()
+4 -1
View File
@@ -502,7 +502,7 @@ class DeepSeekV4MTP(nn.Module):
f"Use a checkpoint that includes MTP layer weights, "
f"or disable speculative decoding."
)
self.finalize_mega_moe_weights()
self.process_weights_after_loading()
logger.info_once("MTP draft model loaded: %d params", len(loaded_params))
return loaded_params
@@ -510,6 +510,9 @@ class DeepSeekV4MTP(nn.Module):
for layer in self.model.layers.values():
layer.mtp_block.ffn.finalize_mega_moe_weights()
def process_weights_after_loading(self) -> None:
self.finalize_mega_moe_weights()
def _rewrite_spec_layer_name(self, spec_layer: int, name: str) -> str:
"""
Rewrite the weight name to match the format of the original model.