> This page is for version 0.7.0 · 26.10.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.

# nemo_automodel.components.models.ergo.model

Native Ergo causal model with an FP32 residual stream.

## Module Contents

### Classes

| Name                                                                              | Description                                                            |
| --------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| [`ErgoForCausalLM`](#nemo_automodel-components-models-ergo-model-ErgoForCausalLM) | Train the floating Ergo target through the standard AutoModel factory. |
| [`ErgoModel`](#nemo_automodel-components-models-ergo-model-ErgoModel)             | Embedding, globally numbered decoder blocks and final normalization.   |

### Data

[`ModelClass`](#nemo_automodel-components-models-ergo-model-ModelClass)

### API

```python
class nemo_automodel.components.models.ergo.model.ErgoForCausalLM(
    config: nemo_automodel.components.models.ergo.config.ErgoConfig,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    logits_dtype: torch.dtype | None = torch.float32
)
```

**Bases:** [HFCheckpointingMixin](/nemo/automodel/v0.7/nemo-automodel/nemo_automodel/components/models/common/hf_checkpointing_mixin#nemo_automodel-components-models-common-hf_checkpointing_mixin-HFCheckpointingMixin), `Module`, [MoEFSDPSyncMixin](/nemo/automodel/v0.7/nemo-automodel/nemo_automodel/components/moe/fsdp_mixin#nemo_automodel-components-moe-fsdp_mixin-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`

---

```python
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 | None` — default: None

Integer RoPE positions matching local token axes.

---

**`attention_mask`** `torch.Tensor | None` — default: None

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

---

**`padding_mask`** `torch.Tensor | None` — default: None

Boolean padding indicators matching local token axes.

---

**`labels`** `torch.Tensor | None` — default: None

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

---

**`logits_to_keep`** `int | torch.Tensor` — default: 0

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

---

**`output_hidden_states`** `bool | None` — default: None

Accepted for Hugging Face compatibility.

---

**`**attn_kwargs`** `Any` — default: \{}

Backend-specific packed attention metadata.

---

**Returns:** `CausalLMOutputWithPast | torch.Tensor`

Model output containing local logits \[batch, selected_sequence,

```python
nemo_automodel.components.models.ergo.model.ErgoForCausalLM.from_config(
    config: nemo_automodel.components.models.ergo.config.ErgoConfig,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    logits_dtype: torch.dtype | None = torch.float32
) -> nemo_automodel.components.models.ergo.model.ErgoForCausalLM
```

classmethod

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

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

Return the untied FP32 token embedding.

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

Return the untied output projection.

```python
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],

```python
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 | None` — default: None

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

---

**`dtype`** `torch.dtype` — default: 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.

---

```python
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`** `int` — default: 1

Positive number of pipeline microbatches.

---

**Returns:** `dict[str, Any]`

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

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

Keep source correction biases fixed during fine-tuning.

```python
class nemo_automodel.components.models.ergo.model.ErgoModel(
    config: nemo_automodel.components.models.ergo.config.ErgoConfig,
    backend: nemo_automodel.components.models.common.BackendConfig,
    dtype: torch.dtype
)
```

**Bases:** `Module`

Embedding, globally numbered decoder blocks and final normalization.

**`cp_mesh`** `DeviceMesh | None = None`

---

**`embed_tokens`**

---

**`layers`**

---

**`norm`**

---

```python
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 | None` — default: None

Integer RoPE positions matching local token axes.

---

**`attention_mask`** `torch.Tensor | None` — default: None

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

---

**`padding_mask`** `torch.Tensor | None` — default: None

Boolean padding indicators matching local token axes.

---

**`**attn_kwargs`** `Any` — default: \{}

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].

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