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

## Module Contents

### Classes

| Name                                                                                     | Description |
| ---------------------------------------------------------------------------------------- | ----------- |
| [`Block`](#nemo_automodel-components-models-gpt_oss-model-Block)                         | -           |
| [`GptOssForCausalLM`](#nemo_automodel-components-models-gpt_oss-model-GptOssForCausalLM) | -           |
| [`GptOssModel`](#nemo_automodel-components-models-gpt_oss-model-GptOssModel)             | -           |

### Data

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

[`logger`](#nemo_automodel-components-models-gpt_oss-model-logger)

### API

```python
class nemo_automodel.components.models.gpt_oss.model.Block(
    layer_idx: int,
    config: transformers.models.gpt_oss.configuration_gpt_oss.GptOssConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig
)
```

**Bases:** `Module`

**`input_layernorm`**

---

**`mlp`** `= MoE(moe_config, backend)`

---

**`post_attention_layernorm`**

---

**`self_attn`**

---

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

```python
nemo_automodel.components.models.gpt_oss.model.Block.init_weights(
    buffer_device: torch.device
)
```

```python
class nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM(
    config: transformers.models.gpt_oss.configuration_gpt_oss.GptOssConfig,
    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)

**`backend`** `= backend or BackendConfig(attn='flex')`

---

**`lm_head`**

---

**`model`**

---

**`state_dict_adapter`**

---

**`tie_word_embeddings_support`** `TieSupport = TieSupport.UNTIED_ONLY`

---

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.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: bool | None = None,
    attn_kwargs: typing.Any = {}
) -> transformers.modeling_outputs.CausalLMOutputWithPast
```

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

**Parameters:**

**`input_ids`** `torch.Tensor`

Token IDs. BSHD: `[B, S]`; THD: `[1, T]` (squeezed internally).

---

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

Optional position indices.

---

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

Optional attention mask.

---

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

Optional padding mask.

---

**`logits_to_keep`** `Union[int, torch.Tensor]` — default: 0

If `0` (default) compute logits for all positions; otherwise
compute logits only for the last `logits_to_keep` positions (used by
memory-efficient fused cross-entropy / generation).

---

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

When truthy, the returned output carries the final hidden
states (the input to `lm_head`) so the recipe can run fused cross-entropy.

---

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

Additional attention kwargs forwarded to the base model
(e.g. `qkv_format`, `cu_seqlens`, `seq_idx`, CP kwargs).

---

**Returns:** `CausalLMOutputWithPast`

`CausalLMOutputWithPast` with `logits` and optional `hidden_states`.

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.from_config(
    config: transformers.models.gpt_oss.configuration_gpt_oss.GptOssConfig,
    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.gpt_oss.model.GptOssForCausalLM.from_pretrained(
    pretrained_model_name_or_path: str,
    model_args = (),
    kwargs = {}
)
```

classmethod

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.get_input_embeddings()
```

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.get_output_embeddings()
```

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

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.set_input_embeddings(
    value
)
```

```python
nemo_automodel.components.models.gpt_oss.model.GptOssForCausalLM.set_output_embeddings(
    new_embeddings
)
```

```python
class nemo_automodel.components.models.gpt_oss.model.GptOssModel(
    config: transformers.models.gpt_oss.configuration_gpt_oss.GptOssConfig,
    backend: nemo_automodel.components.models.common.BackendConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig | None = None,
    moe_overrides: dict | None = None
)
```

**Bases:** `Module`

**`embed_tokens`**

---

**`head_dim`**

---

**`layers`** `= torch.nn.ModuleDict()`

---

**`max_seq_len`** `= config.max_position_embeddings`

---

**`moe_config`** `= moe_config or MoEConfig(**moe_defaults)`

---

**`norm`**

---

**`rotary_emb`**

---

```python
nemo_automodel.components.models.gpt_oss.model.GptOssModel.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.gpt_oss.model.GptOssModel.init_weights(
    buffer_device: torch.device | None = None
) -> None
```

```python
nemo_automodel.components.models.gpt_oss.model.ModelClass = GptOssForCausalLM
```

```python
nemo_automodel.components.models.gpt_oss.model.logger = logging.getLogger(__name__)
```