nemo_automodel.components.models.ernie5_5.mtp_training
nemo_automodel.components.models.ernie5_5.mtp_training
One-depth shared-last-layer ERNIE 5.5 multi-token prediction training.
Semantics reference (independent implementation): NVIDIA-NeMo/Megatron-Bridge 60f7921aa13bff30d801c6b37c063a29786e3626, ERNIE modeling_ernie55/mtp.py, Apache-2.0. Reuses AutoModel’s actual decoder block, norms and MultiMax. The generic MTPModule consumes post-norm 3-D hidden states; this envelope instead needs the final 4-D streams and a second call to a single registered decoder body.
Module Contents
Classes
API
Bases: Module
Own exactly eight trainable MTP tensors and one persistent router buffer.
No decoder, embedding or vocabulary module is registered or cached here. Resolve the shared body at its decoder path after loading or FSDP wrapping.
Fuse the next token with each stream and call the shared body normally.
Parameters:
Final decoder tensor [batch, sequence, streams, hidden].
Shifted embeddings [batch, sequence, hidden]; no wrap.
Registered last decoder block, passed afresh after wrapping.
Same position/mask layout as the decoder’s original query slots.
Returns: torch.Tensor
MTP head input [batch, sequence, hidden] in the projection dtype. The
Initialize all owned state, including after meta materialization.
Bases: Ernie5_5_MoeForCausalLM
Train one shared-last-layer MTP depth with full parameters at CP1 and PP1.
Each batch contains one unpadded document. Main logits use the decoder’s existing computation and MultiMax. The SFT recipe divides both main and auxiliary CE sums by the same global main-token count, preserving the configured auxiliary coefficient per token. Packed inputs, CP, PP, LoRA and KV caching are unsupported. Training is rejected if an MTP-owned parameter is frozen (including the default LoRA configuration) or the model carries LoRA adapter tensors.
Run MTP inside the active inner FSDP forward, without a cached body.
Parameters:
Final decoder streams [batch, sequence, streams, hidden].
Decoder query-slot positions and causal masks.
Original integer tokens [batch, sequence].
Returns: torch.Tensor
Post-MultiMax logits [batch, sequence, vocab]. The rolled token-0
Reject training while an MTP-owned parameter is frozen or the model carries LoRA adapters.
Training is rejected if an MTP-owned parameter is frozen (including the default LoRA configuration,
which freezes every base parameter), and if any parameter name of the model contains lora_, the
test the framework’s trainability policy uses for adapter tensors. The second condition also covers
LoRA combined with a freeze configuration that unfreezes the MTP tensors. Frozen decoder parameters
without adapters are not detected. Only requires_grad and parameter names are read; no tensor
value is touched.
Raises:
ValueError: If a parameter registered undermtpdoes not require gradients, or a parameter name of the model containslora_.
Run the decoder and optionally the one-depth shared-body MTP path.
Parameters:
Integer tensor [1, sequence] containing one unpadded document.
Optional all-true tensor [1, sequence].
Optional all-false tensor [1, sequence].
Optional integer tensor [1, sequence] equal to 0..sequence-1.
Must be False; there is no KV cache.
Returns: Ernie5_5MTPOutput
Main and optional MTP logits [1, sequence, vocab]; neither includes loss.
Raises:
ValueError: If KV caching, CP, padded or multi-document inputs are requested, or the model is in training mode and a DSA indexer parameter requires gradients, an MTP-owned parameter does not, or the model carries LoRA adapter tensors.TypeError: If packing metadata such as seq_lens or packed_seq_ids is supplied.
Initialize the production decoder and every MTP-owned tensor.
Bases: Ernie5_5ModelParallelizer
Require the MTP envelope to belong to the outer FSDP root.
The inherited flow gives the FP32 hyper-head its own unit. The remaining five owned tensors live outside the decoder root and require outer wrapping.
Check that every trainable MTP parameter was claimed by an FSDP unit.
Raises:
RuntimeError: If the outer model is not an FSDP unit or a trainable MTP parameter remains unsharded.
Reject CP and uncovered MTP ownership before the executor mutates state.
Raises:
ValueError: If CP is enabled, outer wrapping is disabled, or the base parallelizer rejects the topology.
Bases: CausalLMOutputWithPast
Standard main logits plus one depth’s post-MultiMax auxiliary logits.
Main tensor of shape [batch, sequence, vocab].
Auxiliary-loss coefficient; no loss is computed here.
One tensor of shape [batch, sequence, vocab], or None for decoder-only evaluation. The standard SFT recipe applies the same global main-token denominator to main and auxiliary losses.