> 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.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.models.ernie4_5.model

## Module Contents

### Classes

| Name                                                                                                  | Description                                                    |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| [`Ernie4_5Attention`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5Attention)             | ERNIE 4.5 GQA attention with interleaved RoPE.                 |
| [`Ernie4_5Block`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5Block)                     | Dense ERNIE 4.5 decoder block.                                 |
| [`Ernie4_5ForCausalLM`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5ForCausalLM)         | Dense ERNIE 4.5 causal language model.                         |
| [`Ernie4_5Model`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5Model)                     | Dense ERNIE 4.5 transformer body.                              |
| [`Ernie4_5MoeBlock`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5MoeBlock)               | ERNIE 4.5 MoE decoder block.                                   |
| [`Ernie4_5_MoeForCausalLM`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5_MoeForCausalLM) | ERNIE 4.5 MoE causal language model with AutoModel EP support. |
| [`Ernie4_5_MoeModel`](#nemo_automodel-components-models-ernie4_5-model-Ernie4_5_MoeModel)             | ERNIE 4.5 MoE transformer body.                                |

### Functions

| Name                                                                              | Description |
| --------------------------------------------------------------------------------- | ----------- |
| [`_config_dtype`](#nemo_automodel-components-models-ernie4_5-model-_config_dtype) | -           |

### Data

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

### API

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5Attention(
    config: transformers.models.ernie4_5.configuration_ernie4_5.Ernie4_5Config | transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

ERNIE 4.5 GQA attention with interleaved RoPE.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5Attention.forward(
    x: torch.Tensor,
    position_embeddings: tuple[torch.Tensor, torch.Tensor],
    attention_mask: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> torch.Tensor
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5Block(
    config: transformers.models.ernie4_5.configuration_ernie4_5.Ernie4_5Config | transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

Dense ERNIE 4.5 decoder block.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5Block.forward(
    x: torch.Tensor,
    position_embeddings: tuple[torch.Tensor, torch.Tensor],
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> torch.Tensor
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM(
    config: transformers.models.ernie4_5.configuration_ernie4_5.Ernie4_5Config,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

**Bases:** [HFCheckpointingMixin](/nemo-automodel/nemo_automodel/components/models/common/hf_checkpointing_mixin#nemo_automodel-components-models-common-hf_checkpointing_mixin-HFCheckpointingMixin), `Module`

Dense ERNIE 4.5 causal language model.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.forward(
    input_ids: torch.Tensor,
    position_ids: torch.Tensor | None = None,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    logits_to_keep: typing.Union[int, torch.Tensor] = 0,
    output_hidden_states: typing.Optional[bool] = None,
    attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.from_config(
    config: transformers.models.ernie4_5.configuration_ernie4_5.Ernie4_5Config,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.from_pretrained(
    pretrained_model_name_or_path: str,
    model_args = (),
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.get_input_embeddings()
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.get_output_embeddings()
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.set_input_embeddings(
    value
)
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.set_output_embeddings(
    new_embeddings
)
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5ForCausalLM.tie_weights()
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5Model(
    config: transformers.models.ernie4_5.configuration_ernie4_5.Ernie4_5Config,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

Dense ERNIE 4.5 transformer body.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5Model.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
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5MoeBlock(
    layer_idx: int,
    config: transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

ERNIE 4.5 MoE decoder block.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5MoeBlock.forward(
    x: torch.Tensor,
    position_embeddings: tuple[torch.Tensor, torch.Tensor],
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> torch.Tensor
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM(
    config: transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

**Bases:** [HFCheckpointingMixin](/nemo-automodel/nemo_automodel/components/models/common/hf_checkpointing_mixin#nemo_automodel-components-models-common-hf_checkpointing_mixin-HFCheckpointingMixin), `Module`, [MoEFSDPSyncMixin](/nemo-automodel/nemo_automodel/components/moe/fsdp_mixin#nemo_automodel-components-moe-fsdp_mixin-MoEFSDPSyncMixin)

ERNIE 4.5 MoE causal language model with AutoModel EP support.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.forward(
    input_ids: torch.Tensor,
    position_ids: torch.Tensor | None = None,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    logits_to_keep: typing.Union[int, torch.Tensor] = 0,
    output_hidden_states: typing.Optional[bool] = None,
    attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.from_config(
    config: transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    backend: nemo_automodel.components.models.common.BackendConfig | None = None,
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.from_pretrained(
    pretrained_model_name_or_path: str,
    model_args = (),
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.get_capabilities(
    config
) -> nemo_automodel._transformers.model_capabilities.ModelCapabilities
```

classmethod

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:

1. `baidu/ERNIE-4.5-21B-A3B-PT` -- MoE variant (this NeMo custom
   class). `moe_num_experts &gt; 0` in the HF config.
   Demonstrated by examples/llm\_finetune/ernie4\_5/ernie4\_5\_21b\_a3b\_hellaswag.yaml
   (ep\_size=8).
2. `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).

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.get_input_embeddings()
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.get_output_embeddings()
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.set_input_embeddings(
    value
)
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.set_output_embeddings(
    new_embeddings
)
```

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeForCausalLM.tie_weights()
```

```python
class nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeModel(
    config: transformers.models.ernie4_5_moe.configuration_ernie4_5_moe.Ernie4_5_MoeConfig,
    backend: nemo_automodel.components.models.common.BackendConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    moe_overrides: dict | None = None
)
```

**Bases:** `Module`

ERNIE 4.5 MoE transformer body.

```python
nemo_automodel.components.models.ernie4_5.model.Ernie4_5_MoeModel.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
```

```python
nemo_automodel.components.models.ernie4_5.model._config_dtype(
    config: typing.Any
) -> torch.dtype
```

```python
nemo_automodel.components.models.ernie4_5.model.ModelClass = Ernie4_5_MoeForCausalLM
```