Skip to navigation

nemo_automodel.components.models.glm5_next.mtp

View as MarkdownOpen in Claude

GLM-5.3-Flash multi-token prediction (MTP) head.

The released checkpoint stores one MTP layer after the decoder stack, as model.language_model.layers.{num_hidden_layers}. It is a plain pre-norm residual block (no mHC) with the same NoPE MLA + KPool indexer attention and routed MoE as the sparse decoder layers:

fused = eh_proj(cat(enorm(next_token_embedding), hnorm(h_prev))) hidden = fused + self_attn(input_layernorm(fused)) output = final_layernorm(hidden + mlp(post_attention_layernorm(hidden)))

h_prev is the backbone output after its final norm, and the shared lm_head projects output for the auxiliary loss. final_layernorm is stored as shared_head.norm in the checkpoint.

Module Contents

Classes

NameDescription
Glm5NextMTPGLM-5.3-Flash MTP stack: one Glm5NextMTPSublayer per depth.
Glm5NextMTPSublayerOne GLM-5.3-Flash MTP depth: embedding fusion, sparse MLA, MoE and final norm.

API

Bases: MTPModule

GLM-5.3-Flash MTP stack: one Glm5NextMTPSublayer per depth.

Parameters:

config
Glm5NextTextConfig

GLM-5.3 text config.

mtp_config
MTPConfig

Enabled MTP config with the single-sublayer pattern "*".

moe_config
MoEConfig

MoE config shared with the decoder’s sparse layers.

backend
BackendConfig

Kernel backend selection.

dtype
torch.dtype

Parameter dtype of the fusion projection and norms.

nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTP.init_weights(
buffer_device: torch.device,
init_std: float
) -> None

Initialize every depth on buffer_device.

nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTP.update_moe_gate_bias() -> None

Update every depth’s routing correction bias.

class nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTPSublayer(
layer_idx: int,
dtype: torch.dtype
)

Bases: Module

One GLM-5.3-Flash MTP depth: embedding fusion, sparse MLA, MoE and final norm.

Parameters:

config
Glm5NextTextConfig

GLM-5.3 text config.

layer_idx
int

Checkpoint layer index of this depth (num_hidden_layers + depth).

moe_config
MoEConfig

MoE config shared with the decoder’s sparse layers.

backend
BackendConfig

Kernel backend selection.

dtype
torch.dtype

Parameter dtype of the fusion projection and norms.

eh_proj
enorm
= Glm5NextRMSNorm(hidden_size, eps, dtype)
final_layernorm
= Glm5NextRMSNorm(hidden_size, eps, dtype)
hnorm
= Glm5NextRMSNorm(hidden_size, eps, dtype)
input_layernorm
= Glm5NextRMSNorm(hidden_size, eps, dtype)
mlp
= MoE(moe_config, backend)
post_attention_layernorm
= Glm5NextRMSNorm(hidden_size, eps, dtype)
self_attn
nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTPSublayer.forward(
hidden_states: torch.Tensor,
embed_input: torch.Tensor,
padding_mask: torch.Tensor | None = None
) -> torch.Tensor

Predict one token further ahead.

Parameters:

hidden_states
torch.Tensor

Previous depth’s output (the backbone’s final-norm output for depth 1) with shape [batch, local_sequence, hidden].

embed_input
torch.Tensor

Embedding of the token depth positions ahead, in the same local layout, zero where that token leaves the document.

packed_context
Glm5NextPackedContext

Document map shared with the backbone attention.

padding_mask
torch.Tensor | NoneDefaults to None

Optional [batch, local_sequence] mask, True on padding.

Returns: torch.Tensor

Normalized hidden states [batch, local_sequence, hidden] for the

nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTPSublayer.init_weights(
buffer_device: torch.device,
init_std: float
) -> None

Initialize a checkpoint-free MTP depth on buffer_device.

nemo_automodel.components.models.glm5_next.mtp.Glm5NextMTPSublayer.update_moe_gate_bias() -> None

Update this depth’s no-aux-loss routing correction bias.