Feat/support nemotron h mtp (#17013)

Signed-off-by: Shahar Mor <smor@nvidia.com>
This commit is contained in:
shaharmor98
2026-01-14 16:30:35 +08:00
committed by GitHub
parent b025cff441
commit ba625c2d90
4 changed files with 378 additions and 1 deletions
+28 -1
View File
@@ -728,7 +728,20 @@ class NemotronHForCausalLM(nn.Module):
def get_seqlen_agnostic_capture_inputs(self, batch_size: int):
return self.mamba_cache.get_seqlen_agnostic_capture_inputs(batch_size)
def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> None:
def get_embed_and_head(self):
return self.model.embed_tokens.weight, self.lm_head.weight
def set_embed_and_head(self, embed, head):
del self.model.embed_tokens.weight
del self.lm_head.weight
self.model.embed_tokens.weight = embed
self.lm_head.weight = head
torch.cuda.empty_cache()
torch.cuda.synchronize()
def load_weights(
self, weights: Iterable[tuple[str, torch.Tensor]], is_mtp: bool = False
) -> None:
updated_weights = []
for name, loaded_weight in weights:
name = replace_prefix(name, self.remap_prefix)
@@ -749,6 +762,20 @@ class NemotronHForCausalLM(nn.Module):
params_dict = dict(self.named_parameters())
for name, loaded_weight in updated_weights:
if is_mtp:
if "mtp" not in name:
continue
name = name.replace("mtp.layers.", "model.layers.")
if "embeddings" in name:
name = name.replace("embeddings", "model.embed_tokens")
if name.startswith("backbone."):
name = name.replace("backbone.", "")
if not is_mtp and "mtp" in name:
continue
if "scale" in name:
name = maybe_remap_kv_scale_name(name, params_dict)
if name is None: