nemo_automodel.components.models.ernie4_5.model
nemo_automodel.components.models.ernie4_5.model
Module Contents
Classes
Functions
Data
API
Bases: Module
ERNIE 4.5 GQA attention with interleaved RoPE.
Bases: Module
Dense ERNIE 4.5 decoder block.
Bases: HFCheckpointingMixin, Module
Dense ERNIE 4.5 causal language model.
Run the decoder and project the kept positions to vocabulary logits.
Parameters:
Token IDs of shape [batch, sequence], or packed (THD) IDs of shape [1, tokens].
Optional positions of shape [batch, sequence], or [1, tokens] for packed input, which requires them.
Optional Tensor of shape [batch, sequence], 1 at valid tokens and 0 at padding, or, with SDPA, a dense mask of shape [batch, 1, sequence, sequence]; packed input ignores it.
Optional bool Tensor of shape [batch, sequence], or [1, tokens] when packed, true at padding; the dense layers do not use it.
0 keeps every position, a positive int keeps the last N positions, and an integer
Tensor of shape [kept] keeps those positions.
Whether the output carries the final hidden states; None reads
config.output_hidden_states.
Backend metadata for the decoder. Packed input sets qkv_format="thd" and passes
int32 cu_seqlens and cu_seqlens_padded of shape [1, documents + 1], padded with -1000, and
max_seqlen.
Returns: CausalLMOutputWithPast
CausalLMOutputWithPast whose logits have shape [batch, kept, vocab], or [1, kept, vocab] for packed
Bases: Module
Dense ERNIE 4.5 transformer body.
Run the decoder layers on padded or packed (THD) input.
Packed input arrives batched and is squeezed to [tokens, …] for the layers, which TE’s packed kernels take; the hidden states come back batched.
Parameters:
Token IDs of shape [batch, sequence], or packed token IDs of shape [1, tokens]. Later pipeline stages pass hidden states of shape [batch, sequence, hidden] or [1, tokens, hidden].
Optional positions of shape [batch, sequence]; packed input requires them, as [1, tokens].
Optional Tensor of shape [batch, sequence], 1 at valid tokens and 0 at padding, or, with SDPA, a dense mask of shape [batch, 1, sequence, sequence]; packed input ignores it.
Optional bool mask of shape [batch, sequence] or [1, tokens], true at padding.
Backend metadata. Packed input sets qkv_format="thd" and passes int32
cu_seqlens and cu_seqlens_padded of shape [1, documents + 1], padded with -1000, and
max_seqlen.
Returns: torch.Tensor
Hidden states of shape [batch, sequence, hidden], or [1, tokens, hidden] for packed input.
Bases: Module
ERNIE 4.5 MoE decoder block.
Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin
ERNIE 4.5 MoE causal language model with AutoModel EP support.
Run the decoder and project the kept positions to vocabulary logits.
Parameters:
Token IDs of shape [batch, sequence], or packed (THD) IDs of shape [1, tokens].
Optional positions of shape [batch, sequence], or [1, tokens] for packed input, which requires them.
Optional Tensor of shape [batch, sequence], 1 at valid tokens and 0 at padding, or, with SDPA and an explicit padding_mask, a dense mask of shape [batch, 1, sequence, sequence]; packed input ignores it.
Optional bool Tensor of shape [batch, sequence], or [1, tokens] when packed, true at padding; when None, the MoE layers derive it from attention_mask.
0 keeps every position, a positive int keeps the last N positions, and an integer
Tensor of shape [kept] keeps those positions.
Whether the output carries the final hidden states; None reads
config.output_hidden_states.
Backend metadata for the decoder. Packed input sets qkv_format="thd" and passes
int32 cu_seqlens and cu_seqlens_padded of shape [1, documents + 1], padded with -1000, and
max_seqlen.
Returns: CausalLMOutputWithPast
CausalLMOutputWithPast whose logits have shape [batch, kept, vocab], or [1, kept, vocab] for packed
Return parallelism capabilities for a specific ERNIE-4.5 config.
ERNIE-4.5 ships in two flavors that share this class file but exercise different code paths:
baidu/ERNIE-4.5-21B-A3B-PT— MoE variant (this NeMo custom class).moe_num_experts > 0in the HF config. Demonstrated by examples/llm_finetune/ernie4_5/ernie4_5_21b_a3b_hellaswag.yaml (ep_size=8).baidu/ERNIE-4.5-0.3B-PT— dense variant. No expert config. Demonstrated by examples/llm_finetune/ernie4_5/ernie4_5_0p3b_hellaswag.yaml (tp/cp/pp/ep all 1).
Bases: Module
ERNIE 4.5 MoE transformer body.
Run the decoder layers on padded or packed (THD) input.
Packed input arrives batched and is squeezed to [tokens, …] for the layers, which TE’s packed kernels take; the hidden states come back batched.
Parameters:
Token IDs of shape [batch, sequence], or packed token IDs of shape [1, tokens]. Later pipeline stages pass hidden states of shape [batch, sequence, hidden] or [1, tokens, hidden].
Optional positions of shape [batch, sequence]; packed input requires them, as [1, tokens].
Optional Tensor of shape [batch, sequence], 1 at valid tokens and 0 at padding, or, with SDPA and an explicit padding_mask, a dense mask of shape [batch, 1, sequence, sequence]; packed input ignores it.
Optional bool mask of shape [batch, sequence] or [1, tokens], true at padding.
Backend metadata. Packed input sets qkv_format="thd" and passes int32
cu_seqlens and cu_seqlens_padded of shape [1, documents + 1], padded with -1000, and
max_seqlen.
Returns: torch.Tensor
Hidden states of shape [batch, sequence, hidden], or [1, tokens, hidden] for packed input.