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

Checkpoint conversion for the released GLM-5.3-Flash VLM.

The checkpoint already uses the native vision/text prefix layout. Conversion is
needed for grouped EP experts, flat mHC/KDA parameters, the extra MTP layer, and
128x128 block-scaled FP8 training weights.

## Module Contents

### Classes

| Name                                                                                                                  | Description                                                          |
| --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [`Glm5NextStateDictAdapter`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-Glm5NextStateDictAdapter) | Convert GLM split experts and FP8 weights to trainable grouped BF16. |

### Functions

| Name                                                                                                                    | Description                                                               |
| ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| [`_apply_local_block_scales`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_apply_local_block_scales) | Apply global-grid block scales to one possibly misaligned local shard.    |
| [`_hf_to_native_key`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_hf_to_native_key)                 | -                                                                         |
| [`_local_shard_offsets`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_local_shard_offsets)           | Return the global start coordinate of a DTensor's contiguous local shard. |
| [`_native_to_hf_key`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_native_to_hf_key)                 | -                                                                         |
| [`_scale_placeholder`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_scale_placeholder)               | Create the global FP8 block-scale load destination for a 2-D weight.      |
| [`_scale_shape`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_scale_shape)                           | -                                                                         |
| [`dequantize_block_fp8`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-dequantize_block_fp8)           | Dequantize an e4m3 weight with 128x128 fp32 inverse scales.               |

### Data

[`_BLOCK_SIZE`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_BLOCK_SIZE)

[`_FP8_WEIGHT`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_FP8_WEIGHT)

[`_HC_KEY`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_HC_KEY)

[`_KDA_PARAMETER`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_KDA_PARAMETER)

[`_NATIVE_HC_KEY`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_NATIVE_HC_KEY)

[`_NATIVE_KDA_PARAMETER`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_NATIVE_KDA_PARAMETER)

[`_SPARSE_O_WEIGHT`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-_SPARSE_O_WEIGHT)

[`__all__`](#nemo_automodel-components-models-glm5_next-state_dict_adapter-__all__)

### API

```python
class nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter(
    config: nemo_automodel.components.models.glm5_next.config.Glm5NextConfig,
    moe_config: nemo_automodel.components.moe.config.MoEConfig,
    backend: nemo_automodel.components.models.common.BackendConfig,
    dtype: torch.dtype = torch.bfloat16
)
```

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

Convert GLM split experts and FP8 weights to trainable grouped BF16.

**`_expert_path_segment`** `str`

---

**`_hf_prefix`** `str`

---

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter._dequantize(
    state_dict: dict[str, typing.Any]
) -> None
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter.Glm5NextStateDictAdapter._is_fp8_weight(
    key: str
) -> bool
```

Match the checkpoint's quantized matrices, including DSA-only output projections.

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

Convert one native tensor, including split expert and FP8 load targets.

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

Dequantize, drop MTP, route flat parameters and aggregate experts.

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

Expand grouped experts and restore released checkpoint names.

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._apply_local_block_scales(
    local_weight: torch.Tensor,
    local_scale: torch.Tensor,
    local_offsets: tuple[int, int],
    dtype: torch.dtype
) -> torch.Tensor
```

Apply global-grid block scales to one possibly misaligned local shard.

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._hf_to_native_key(
    key: str
) -> str
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._local_shard_offsets(
    tensor: torch.Tensor
) -> tuple[int, ...]
```

Return the global start coordinate of a DTensor's contiguous local shard.

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._native_to_hf_key(
    key: str
) -> str
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._scale_placeholder(
    weight: torch.Tensor
) -> torch.Tensor
```

Create the global FP8 block-scale load destination for a 2-D weight.

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._scale_shape(
    weight: torch.Tensor
) -> tuple[int, int]
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter.dequantize_block_fp8(
    weight: torch.Tensor,
    scale_inv: torch.Tensor,
    dtype: torch.dtype = torch.bfloat16
) -> torch.Tensor
```

Dequantize an e4m3 weight with 128x128 fp32 inverse scales.

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._BLOCK_SIZE = 128
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._FP8_WEIGHT = re.compile('^model\\.language_model\\.layers\\.\\d+\\.(?:self_attn\\.(?:q_a_proj...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._HC_KEY = re.compile('^(model\\.language_model\\.layers\\.\\d+)\\.hc_(attn|ffn)_(fn|base|s...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._KDA_PARAMETER = re.compile('^(model\\.language_model\\.layers\\.\\d+\\.self_attn)\\.(A_log|dt_bi...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._NATIVE_HC_KEY = re.compile('^(model\\.language_model\\.layers\\.\\d+)\\.(attn_hc|ffn_hc)(?:\\._f...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._NATIVE_KDA_PARAMETER = re.compile('^(model\\.language_model\\.layers\\.\\d+\\.self_attn)\\._fp32_params...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter._SPARSE_O_WEIGHT = re.compile('^model\\.language_model\\.layers\\.(\\d+)\\.self_attn\\.o_proj\\.wei...
```

```python
nemo_automodel.components.models.glm5_next.state_dict_adapter.__all__ = ['Glm5NextStateDictAdapter', 'dequantize_block_fp8']
```