Skip to navigation

nemo_automodel.components.models.ergo.model

View as MarkdownOpen in Claude

Native Ergo causal model with an FP32 residual stream.

Module Contents

Classes

NameDescription
ErgoForCausalLMTrain the floating Ergo target through the standard AutoModel factory.
ErgoModelEmbedding, globally numbered decoder blocks and final normalization.

Data

ModelClass

API

class nemo_automodel.components.models.ergo.model.ErgoForCausalLM(
logits_dtype: torch.dtype | None = torch.float32
)

Bases: HFCheckpointingMixin, Module, MoEFSDPSyncMixin

Train the floating Ergo target through the standard AutoModel factory.

_keep_in_fp32_modules_strict
_owns_cp_attention
bool

SDPA owns document-preserving CP; TE retains its packed alignment.

_packed_cp_attn_backends
= ('sdpa', 'te')
_pp_keep_self_forward
bool = True
_pp_return_hidden_states
bool = False
_pp_return_hidden_states_supported
bool = True
backend
compute_dtype
lm_head
model
moe_config
= config.build_moe_config(self.compute_dtype)
packed_mask_type
= 'document_ids'
parallelizer
= ErgoParallelizer()
requires_thd_batch_preparation
bool

Request CP1 raw-batch conversion for FA4; TE owns its CP partitioning.

state_dict_adapter
supports_thd
bool

TE owns packed preparation at CP1 as well as CP>1, including PP.

tie_word_embeddings_support
TieSupport = TieSupport.UNTIED_ONLY
nemo_automodel.components.models.ergo.model.ErgoForCausalLM.forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
labels: torch.Tensor | None = None,
logits_to_keep: int | torch.Tensor = 0,
output_hidden_states: bool | None = None,
attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast | torch.Tensor

Produce logits; unshifted HF labels are optional outside the recipe.

Standard training recipes own the shift and loss. They do not pass HF labels here. The final normalized hidden states are also returned for the shared fused/chunked loss path.

Parameters:

input_ids
torch.Tensor

Global token IDs [batch, sequence] on stage zero or CP-local FP32 residuals [batch, local_sequence, hidden] later.

position_ids
torch.Tensor | NoneDefaults to None

Integer RoPE positions matching local token axes.

attention_mask
torch.Tensor | NoneDefaults to None

Local document IDs [batch, local_sequence], or a CP1 boolean allow-mask [batch, 1, sequence, sequence].

padding_mask
torch.Tensor | NoneDefaults to None

Boolean padding indicators matching local token axes.

labels
torch.Tensor | NoneDefaults to None

Unshifted HF labels [batch, sequence], CP1 only. CP recipes shift labels before partitioning and compute loss externally.

logits_to_keep
int | torch.TensorDefaults to 0

Number of trailing tokens or integer token indices [selected_sequence] to project.

output_hidden_states
bool | NoneDefaults to None

Accepted for Hugging Face compatibility.

**attn_kwargs
AnyDefaults to {}

Backend-specific packed attention metadata.

Returns: CausalLMOutputWithPast | torch.Tensor

Model output containing local logits [batch, selected_sequence,

classmethod

Construct from the config resolved by AutoModel’s public loader.

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.get_input_embeddings() -> torch.nn.Embedding

Return the untied FP32 token embedding.

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.get_output_embeddings() -> nemo_automodel.components.models.common.LMHead

Return the untied output projection.

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.get_pipeline_stage_metas(
is_first: bool,
microbatch_size: int,
seq_len: int,
dtype: torch.dtype
) -> tuple[tuple[torch.Tensor, ...], tuple[torch.Tensor, ...]]

Describe token inputs, FP32 residual transport, and final logits.

Parameters:

is_first
bool

Whether this stage owns the token embedding.

microbatch_size
int

Number of sequences in one pipeline microbatch.

seq_len
int

Global tokens per sequence before CP padding.

dtype
torch.dtype

Framework compute dtype for a final projection without a logits override.

Returns: tuple[torch.Tensor, ...]

Input/output meta tensors: IDs [B,S], CP-local residuals [B,L,H],

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.initialize_weights(
buffer_device: torch.device | None = None,
dtype: torch.dtype = torch.bfloat16
) -> None

Materialize and initialize every parameter and routing buffer.

Storage and compute precision are the ones the constructor established from the configuration (dtype and compute_dtype); this method changes neither.

Parameters:

buffer_device
torch.device | NoneDefaults to None

Device for parameters and buffers; None keeps the parameters’ device.

dtype
torch.dtypeDefaults to torch.bfloat16

Unused. The checkpoint loader passes the dtype of the model’s first parameter, the token embedding, which is FP32 at every storage precision and so says nothing about the model.

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.prepare_model_inputs_for_cp(
batch: dict[str, typing.Any],
num_chunks: int = 1
) -> dict[str, typing.Any]

Select model-owned SDPA sharding or shared TE partitioning.

Parameters:

batch
dict[str, Any]

Global IDs and auxiliaries [batch, sequence]. SDPA accepts document-ID attention masks; TE uses THD for packed documents.

num_chunks
intDefaults to 1

Positive number of pipeline microbatches.

Returns: dict[str, Any]

A weight-free sharder descriptor and optional padding mask. BSHD

nemo_automodel.components.models.ergo.model.ErgoForCausalLM.update_moe_gate_bias() -> None

Keep source correction biases fixed during fine-tuning.

class nemo_automodel.components.models.ergo.model.ErgoModel(
dtype: torch.dtype
)

Bases: Module

Embedding, globally numbered decoder blocks and final normalization.

cp_mesh
DeviceMesh | None = None
embed_tokens
layers
norm
nemo_automodel.components.models.ergo.model.ErgoModel.forward(
input_ids: torch.Tensor,
position_ids: torch.Tensor | None = None,
attention_mask: torch.Tensor | None = None,
padding_mask: torch.Tensor | None = None,
attn_kwargs: typing.Any = {}
) -> torch.Tensor

Return FP32 states, preserving CP-local token ownership.

Parameters:

input_ids
torch.Tensor

Integer IDs [batch, global_sequence] on the first stage, or FP32 residuals [batch, local_sequence, hidden] on later stages. Packed TE IDs remain global [1, tokens] with local indices in metadata; later stages receive [1, local_tokens, hidden].

position_ids
torch.Tensor | NoneDefaults to None

Integer RoPE positions matching local token axes.

attention_mask
torch.Tensor | NoneDefaults to None

Local document IDs [batch, local_sequence], or a boolean allow-mask [batch, 1, sequence, sequence] without CP.

padding_mask
torch.Tensor | NoneDefaults to None

Boolean padding indicators matching local token axes.

**attn_kwargs
AnyDefaults to {}

Backend-specific packed attention metadata. The ergo_te_local_indices map selects stage-zero IDs exactly once.

Returns: torch.Tensor

FP32 states [batch, local_sequence, hidden] or [tokens, hidden].

nemo_automodel.components.models.ergo.model.ModelClass = ErgoForCausalLM