[UX] Skip checkpoint shards an MTP head does not load (#60152)

Signed-off-by: Robert Shaw <robshaw@redhat.com>
Co-authored-by: Robert Shaw <robshaw@redhat.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Robert Shaw
2026-10-07 15:16:19 -04:00
committed by GitHub
co-authored by Robert Shaw Claude Opus 5.5
parent 17c70c8953
commit e572e02d21
9 changed files with 165 additions and 39 deletions
+7 -1
View File
@@ -251,6 +251,12 @@ class DeepseekV32MTP(nn.Module, DeepseekV2MixtureOfExperts, SupportsPP):
name = name.replace(f"model.layers.{spec_layer}.", "model.")
return name
def is_unused_checkpoint_weight(self, name: str) -> bool:
return (
get_spec_layer_idx_from_weight_name(self.config, name) is None
and "embed_tokens" not in name
)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
stacked_params_mapping = [
("gate_up_proj", "gate_proj", 0),
@@ -278,7 +284,7 @@ class DeepseekV32MTP(nn.Module, DeepseekV2MixtureOfExperts, SupportsPP):
loaded_params: set[str] = set()
_pending_wk_fp8: dict = {}
for name, loaded_weight in weights:
if "rotary_emb.inv_freq" in name:
if "rotary_emb.inv_freq" in name or self.is_unused_checkpoint_weight(name):
continue
spec_layer = get_spec_layer_idx_from_weight_name(self.config, name)
if spec_layer is None:
+7 -1
View File
@@ -356,6 +356,12 @@ class DeepseekV32MTP(nn.Module, DeepseekV2MixtureOfExperts, SupportsPP):
name = name.replace(f"model.layers.{spec_layer}.", "model.")
return name
def is_unused_checkpoint_weight(self, name: str) -> bool:
return (
get_spec_layer_idx_from_weight_name(self.config, name) is None
and "embed_tokens" not in name
)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
stacked_params_mapping = [
("gate_up_proj", "gate_proj", 0),
@@ -378,7 +384,7 @@ class DeepseekV32MTP(nn.Module, DeepseekV2MixtureOfExperts, SupportsPP):
loaded_params: set[str] = set()
_pending_wk_fp8: dict = {}
for name, loaded_weight in weights:
if "rotary_emb.inv_freq" in name:
if "rotary_emb.inv_freq" in name or self.is_unused_checkpoint_weight(name):
continue
spec_layer = get_spec_layer_idx_from_weight_name(self.config, name)
if spec_layer is None:
+21 -19
View File
@@ -340,6 +340,26 @@ class DeepSeekV4MTP(nn.Module):
) -> torch.Tensor | None:
return self.model.compute_logits(hidden_states, spec_step_idx)
def _to_spec_layer_name(self, name: str) -> str:
"""Remap V4 `mtp.{i}.*` names to `model.layers.{num_hidden_layers + i}.*`
so that get_spec_layer_idx_from_weight_name can identify them."""
mtp_layer_idx = 0
for subname in name.split("."):
try:
# we use the first encountered integer
mtp_layer_idx = int(subname)
break
except ValueError:
continue
return name.replace(
f"mtp.{mtp_layer_idx}.",
f"model.layers.{self.config.num_hidden_layers + mtp_layer_idx}.",
)
def is_unused_checkpoint_weight(self, name: str) -> bool:
name = self._to_spec_layer_name(name)
return get_spec_layer_idx_from_weight_name(self.config, name) is None
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
# Weight name remapping for checkpoint compatibility.
# Maps checkpoint weight paths to model parameter paths.
@@ -356,16 +376,6 @@ class DeepSeekV4MTP(nn.Module):
name = name.replace(old_pattern, new_pattern)
return name
def _find_mtp_layer_idx(name: str) -> int:
subnames = name.split(".")
for subname in subnames:
try:
# we return the first encountered integer
return int(subname)
except ValueError:
continue
return 0
stacked_params_mapping = [
# (param_name, shard_name, shard_id)
("gate_up_proj", "w1", 0),
@@ -409,15 +419,7 @@ class DeepSeekV4MTP(nn.Module):
)
for name, loaded_weight in weights:
mtp_layer_idx = _find_mtp_layer_idx(name)
# V4 checkpoints store MTP weights as `mtp.{i}.*`; remap to
# `model.layers.{num_hidden_layers + i}.*` so that
# get_spec_layer_idx_from_weight_name can identify them.
name = name.replace(
f"mtp.{mtp_layer_idx}.",
f"model.layers.{self.config.num_hidden_layers + mtp_layer_idx}.",
)
name = self._to_spec_layer_name(name)
spec_layer = get_spec_layer_idx_from_weight_name(self.config, name)
if spec_layer is None:
continue