> 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.step3p5.model

## Module Contents

### Classes

| Name                                                                                       | Description                                                            |
| ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| [`Block`](#nemo_automodel-components-models-step3p5-model-Block)                           | Step3p5 transformer block with attention, MLP/MoE, and shared experts. |
| [`Step3p5ForCausalLM`](#nemo_automodel-components-models-step3p5-model-Step3p5ForCausalLM) | Step3p5 model for causal language modeling.                            |
| [`Step3p5Model`](#nemo_automodel-components-models-step3p5-model-Step3p5Model)             | Step3p5 transformer model.                                             |

### Functions

| Name                                                                                                         | Description                                                             |
| ------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
| [`_keep_step_router_bias_fp32`](#nemo_automodel-components-models-step3p5-model-_keep_step_router_bias_fp32) | Keep Step router correction bias in fp32 after module-wide dtype casts. |
| [`parse_moe_layers_enum`](#nemo_automodel-components-models-step3p5-model-parse_moe_layers_enum)             | Parse moe\_layers\_enum to get set of MoE layer indices.                |

### Data

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

### API

```python
class nemo_automodel.components.models.step3p5.model.Block(
    layer_idx: int,
    config: typing.Any,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

Step3p5 transformer block with attention, MLP/MoE, and shared experts.

```python
nemo_automodel.components.models.step3p5.model.Block.forward(
    x: torch.Tensor,
    freqs_cis: torch.Tensor,
    attention_mask: torch.Tensor | None = None,
    padding_mask: torch.Tensor | None = None,
    position_ids: torch.Tensor | None = None,
    attn_kwargs: typing.Any = {}
) -> torch.Tensor
```

```python
nemo_automodel.components.models.step3p5.model.Block.init_weights(
    buffer_device: torch.device
) -> None
```

```python
class nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM(
    config: typing.Any,
    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)

Step3p5 model for causal language modeling.

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.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
```

Forward pass returning :class:`~transformers.modeling_outputs.CausalLMOutputWithPast`.

Supports both BSHD format (`input_ids` shape `[B, S]`) and THD format
(`input_ids` shape `[1, T]`); when `attn_kwargs["qkv_format"] == "thd"`,
inputs are squeezed to THD before the base-model forward and `logits` (and the
final `hidden_states`) are unsqueezed back to a leading-batch dimension on exit.

**Parameters:**

Input token IDs.

Optional position indices.

Optional 2D padding mask.

Optional padding mask used by the THD squeeze helper.

If `0` (default), compute logits for all positions; if `&gt; 0`
(or a tensor), only compute logits for the last `logits_to_keep` positions
(avoids materialising the full logit matrix during generation / fused CE).

Whether to carry the final hidden states on the output.

Additional arguments forwarded to the base model.

**Returns:** `CausalLMOutputWithPast`

class:`~transformers.modeling_outputs.CausalLMOutputWithPast` with `logits` and,

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.from_config(
    config: typing.Any,
    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.step3p5.model.Step3p5ForCausalLM.from_pretrained(
    pretrained_model_name_or_path: str,
    model_args = (),
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.get_input_embeddings()
```

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.get_output_embeddings()
```

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.initialize_weights(
    buffer_device: torch.device | None = None,
    dtype: torch.dtype = torch.bfloat16
) -> None
```

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.set_input_embeddings(
    value
)
```

```python
nemo_automodel.components.models.step3p5.model.Step3p5ForCausalLM.set_output_embeddings(
    new_embeddings
)
```

```python
class nemo_automodel.components.models.step3p5.model.Step3p5Model(
    config: typing.Any,
    backend: nemo_automodel.components.models.common.BackendConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    moe_overrides: dict | None = None
)
```

**Bases:** `Module`

Step3p5 transformer model.

```python
nemo_automodel.components.models.step3p5.model.Step3p5Model._apply(
    fn
)
```

```python
nemo_automodel.components.models.step3p5.model.Step3p5Model.forward(
    input_ids: torch.Tensor | None = None,
    inputs_embeds: torch.Tensor | None = None,
    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.step3p5.model.Step3p5Model.init_weights(
    buffer_device: torch.device | None = None
) -> None
```

```python
nemo_automodel.components.models.step3p5.model._keep_step_router_bias_fp32(
    module: torch.nn.Module
) -> None
```

Keep Step router correction bias in fp32 after module-wide dtype casts.

```python
nemo_automodel.components.models.step3p5.model.parse_moe_layers_enum(
    moe_layers_enum: str | int | tuple | list | None,
    num_hidden_layers: int
) -> set[int]
```

Parse moe\_layers\_enum to get set of MoE layer indices.

**Parameters:**

Tuple/list of layer indices, integer, comma-separated string, or None.
HF Step-3.5-Flash uses tuple format like (3, 4, 5, ..., 44).

Total number of hidden layers.

**Returns:** `set[int]`

Set of layer indices that should be MoE layers.

```python
nemo_automodel.components.models.step3p5.model.ModelClass = Step3p5ForCausalLM
```