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

## Module Contents

### Classes

| Name                                                                                                            | Description |
| --------------------------------------------------------------------------------------------------------------- | ----------- |
| [`GPTOSSStateDictAdapter`](#nemo_automodel-components-models-gpt_oss-state_dict_adapter-GPTOSSStateDictAdapter) | -           |

### Data

[`FP4_VALUES`](#nemo_automodel-components-models-gpt_oss-state_dict_adapter-FP4_VALUES)

### API

```python
class nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter(
    config: transformers.GptOssConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig,
    dtype: torch.dtype = torch.bfloat16
)
```

**Bases:** [StateDictAdapter](/nemo-automodel/nemo_automodel/components/checkpoint/state_dict_adapter#nemo_automodel-components-checkpoint-state_dict_adapter-StateDictAdapter)

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter._apply_key_mapping(
    state_dict: dict[str, typing.Any],
    mapping: dict[str, str]
) -> dict[str, typing.Any]
```

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter._convert_moe_packed_tensors(
    blocks,
    scales,
    dtype: torch.dtype = torch.bfloat16,
    rows_per_chunk: int = 32768 * 1024
) -> torch.Tensor
```

Convert the mxfp4 weights to bfloat16.

Source: [https://github.com/huggingface/transformers/blob/869735d37d0f929311ac6611728c482a4414ba8c/src/transformers/integrations/mxfp4.py#L77](https://github.com/huggingface/transformers/blob/869735d37d0f929311ac6611728c482a4414ba8c/src/transformers/integrations/mxfp4.py#L77)

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter._dequantize_block_scale_tensors(
    state_dict: dict[str, typing.Any]
) -> dict[str, typing.Any]
```

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter.convert_single_tensor_to_hf(
    fqn: str,
    tensor: typing.Any,
    kwargs = {}
) -> list[tuple[str, typing.Any]]
```

Convert a single tensor from native format to HuggingFace format.

**Parameters:**

Fully qualified name of the tensor in native format

The tensor to convert

Additional arguments for conversion

**Returns:** `list[tuple[str, Any]]`

List of (fqn, tensor) tuples in HuggingFace format

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter.from_hf(
    hf_state_dict: dict[str, typing.Any],
    device_mesh: typing.Optional[torch.distributed.device_mesh.DeviceMesh] = None,
    kwargs = {}
) -> dict[str, typing.Any]
```

Convert HF checkpoint to native format in-place.

* Apply key mappings from HF to internal format
* Dequantize block/scale tensors (freeing originals)

Operates in-place on the input dict to avoid allocating a full copy,
reducing peak memory from 2x to \~1x model size.

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.GPTOSSStateDictAdapter.to_hf(
    state_dict: dict[str, typing.Any],
    exclude_key_regex: typing.Optional[str] = None,
    quantization: bool = False,
    kwargs = {}
) -> dict[str, typing.Any]
```

Convert from native model state dict to HuggingFace format.

```python
nemo_automodel.components.models.gpt_oss.state_dict_adapter.FP4_VALUES = [+0.0, +0.5, +1.0, +1.5, +2.0, +3.0, +4.0, +6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -...
```