[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:
co-authored by
Robert Shaw
Claude Opus 5.5
parent
17c70c8953
commit
e572e02d21
@@ -426,6 +426,11 @@ class NemotronHMTP(nn.Module, SupportsPP, SupportsQuant):
|
||||
)
|
||||
return self.logits_processor(self.lm_head, hidden_states)
|
||||
|
||||
def is_unused_checkpoint_weight(self, name: str) -> bool:
|
||||
"""Only MTP, embedding and LM head weights are loaded."""
|
||||
name = name.removeprefix("language_model.")
|
||||
return not name.startswith(("mtp.", "lm_head.")) and "embeddings" not in name
|
||||
|
||||
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
|
||||
"""Load MTP weights with proper name remapping."""
|
||||
stacked_params_mapping = [
|
||||
@@ -456,17 +461,11 @@ class NemotronHMTP(nn.Module, SupportsPP, SupportsQuant):
|
||||
# MTP weights are nested in "language_model."
|
||||
# in Multimodal Nemotron-H checkpoints.
|
||||
name = name.removeprefix("language_model.")
|
||||
if self.is_unused_checkpoint_weight(name):
|
||||
continue
|
||||
is_lm_head_weight = name.startswith("lm_head.")
|
||||
if is_lm_head_weight:
|
||||
self.has_own_lm_head = True
|
||||
# Only process MTP and LM head weights -
|
||||
# skip all non-MTP and non-LM head weights
|
||||
if (
|
||||
not name.startswith("mtp.")
|
||||
and "embeddings" not in name
|
||||
and not is_lm_head_weight
|
||||
):
|
||||
continue
|
||||
# Skip rotary embeddings (computed, not loaded)
|
||||
if "rotary_emb.inv_freq" in name:
|
||||
continue
|
||||
|
||||
@@ -300,16 +300,20 @@ class Qwen3_5MTP(LocalArgmaxMixin, nn.Module, SupportsMultiModal, SupportsPP):
|
||||
) -> torch.Tensor | None:
|
||||
return self.logits_processor(self.lm_head, hidden_states)
|
||||
|
||||
def is_unused_checkpoint_weight(self, name: str) -> bool:
|
||||
return not name.startswith("mtp.") and not any(
|
||||
key in name for key in ["embed_tokens", "lm_head"]
|
||||
)
|
||||
|
||||
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
|
||||
def remap_weight_names(weights):
|
||||
for name, weight in weights:
|
||||
if self.is_unused_checkpoint_weight(name):
|
||||
continue
|
||||
if name.startswith("mtp."):
|
||||
name = name.replace("mtp.", "model.")
|
||||
elif any(key in name for key in ["embed_tokens", "lm_head"]):
|
||||
if "embed_tokens" in name:
|
||||
name = name.replace("language_model.", "")
|
||||
else:
|
||||
continue
|
||||
elif "embed_tokens" in name:
|
||||
name = name.replace("language_model.", "")
|
||||
yield name, weight
|
||||
|
||||
loader = AutoWeightsLoader(self)
|
||||
|
||||
@@ -227,15 +227,18 @@ class Qwen3NextMTP(nn.Module, QwenNextMixtureOfExperts):
|
||||
) -> torch.Tensor | None:
|
||||
return self.logits_processor(self.lm_head, hidden_states)
|
||||
|
||||
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
|
||||
shared_weight_names = ["embed_tokens", "lm_head"]
|
||||
def is_unused_checkpoint_weight(self, name: str) -> bool:
|
||||
return not name.startswith("mtp.") and not any(
|
||||
key in name for key in ["embed_tokens", "lm_head"]
|
||||
)
|
||||
|
||||
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
|
||||
def remap_weight_names(weights):
|
||||
for name, weight in weights:
|
||||
if self.is_unused_checkpoint_weight(name):
|
||||
continue
|
||||
if name.startswith("mtp."):
|
||||
name = name.replace("mtp.", "model.")
|
||||
elif not any(key in name for key in shared_weight_names):
|
||||
continue
|
||||
yield name, weight
|
||||
|
||||
loader = AutoWeightsLoader(self)
|
||||
|
||||
Reference in New Issue
Block a user