> This page is for version Nightly (default).
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

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

# nemo_automodel.components.models.inkling2.quantized_export

Write a trained Inkling2 checkpoint in the layout of the released checkpoint it was trained from.

Training saves Inkling2 with floating-point experts (for example `&lt;step&gt;/model/consolidated`). Serving
runtimes that read the released `hf_quant_config.json` load NVFP4 or MXFP8 experts only. This module rewrites
such a floating export with the released tensor names, dtypes, shapes and shards, packed NVFP4/MXFP8 experts,
and the released `config.json`, `hf_quant_config.json` and other files, such as `tiktoken/`::

python -m nemo_automodel.components.models.inkling2.quantized_export \
\--released /path/to/Inkling-2-Mini \
\--trained /path/to/checkpoints/epoch_0_step_99/model/consolidated \
\--out /path/to/Inkling-2-Mini-finetuned

A tensor whose trained value equals its released value decoded to the trained dtype keeps its released bytes.
Each changed expert is written in whichever encoding decodes closest to its trained values (squared error):
its released bytes, or its trained values encoded with `quantize_mxfp8_experts`, or with
`quantize_nvfp4_experts` under its released `amax` or under its own largest magnitude. Training starts
from the decoded release, so a weight that moved less than half a quantization step rounds back to its released
code. An expert whose every update is that small keeps its released bytes, and its update is not in the export;
the summary counts these experts apart. Other changed tensors are cast to their released dtype.
`model.visual.*` tensors that a text-only export lacks are copied from the release. The result is for
serving; resume training from the floating checkpoint.

## Module Contents

### Classes

| Name                                                                                         | Description                                                                                                |
| -------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [`ExportSummary`](#nemo_automodel-components-models-inkling2-quantized_export-ExportSummary) | What `export_quantized` wrote. Experts are counted per projection; the three counts add up to all of them. |

### Functions

| Name                                                                                               | Description                                                                                             |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| [`_bytes`](#nemo_automodel-components-models-inkling2-quantized_export-_bytes)                     | Raw bytes of a tensor, one row per index of its leading axis.                                           |
| [`_decode`](#nemo_automodel-components-models-inkling2-quantized_export-_decode)                   | Decode the storage of one expert projection in the released layout as checkpoint loading does.          |
| [`_export_experts`](#nemo_automodel-components-models-inkling2-quantized_export-_export_experts)   | Write one grouped expert projection, each changed expert in the encoding closest to its trained values. |
| [`_weight_map`](#nemo_automodel-components-models-inkling2-quantized_export-_weight_map)           | Tensor name to shard file name, from a checkpoint directory's SafeTensors index.                        |
| [`export_quantized`](#nemo_automodel-components-models-inkling2-quantized_export-export_quantized) | Write `trained` in the layout of `released` to the new directory `out`.                                 |
| [`main`](#nemo_automodel-components-models-inkling2-quantized_export-main)                         | Command line entry point; see the module docstring.                                                     |

### Data

[`_DECODE_ELEMENTS`](#nemo_automodel-components-models-inkling2-quantized_export-_DECODE_ELEMENTS)

[`_EXPERT`](#nemo_automodel-components-models-inkling2-quantized_export-_EXPERT)

[`_FLOATING`](#nemo_automodel-components-models-inkling2-quantized_export-_FLOATING)

[`_INDEX`](#nemo_automodel-components-models-inkling2-quantized_export-_INDEX)

[`_NVFP4_METADATA`](#nemo_automodel-components-models-inkling2-quantized_export-_NVFP4_METADATA)

[`logger`](#nemo_automodel-components-models-inkling2-quantized_export-logger)

### API

```python
class nemo_automodel.components.models.inkling2.quantized_export.ExportSummary(
    unchanged_experts: int,
    rounded_to_release_experts: int,
    requantized_experts: int,
    kept_tensors: int,
    converted_tensors: int,
    released_only_tensors: int
)
```

Dataclass

What `export_quantized` wrote. Experts are counted per projection; the three counts add up to all of them.

**`converted_tensors`** `int`

Floating tensors written from their trained values in the released dtype.

---

**`kept_tensors`** `int`

Floating tensors whose released bytes were kept.

---

**`released_only_tensors`** `int`

`model.visual.*` tensors absent from the trained export, copied from the release.

---

**`requantized_experts`** `int`

Experts written with codes or scales that differ from the release.

---

**`rounded_to_release_experts`** `int`

Experts that training changed but whose released bytes still decode closest
to the trained values, so the bytes are kept and the update is not in the export.

---

**`unchanged_experts`** `int`

Experts whose trained values equal their decoded released bytes; the bytes are kept.

---

```python
nemo_automodel.components.models.inkling2.quantized_export._bytes(
    tensor: torch.Tensor
) -> torch.Tensor
```

Raw bytes of a tensor, one row per index of its leading axis.

**Parameters:**

**`tensor`** `torch.Tensor`

Tensor of shape \[rows, ...] or a scalar, any dtype.

---

**Returns:** `torch.Tensor`

uint8 tensor of shape \[rows, bytes_per_row] (one row for a scalar). Comparing bytes treats -0.0 and

```python
nemo_automodel.components.models.inkling2.quantized_export._decode(
    adapter: nemo_automodel.components.models.inkling2.state_dict_adapter.Inkling2StateDictAdapter,
    stored: dict[str, torch.Tensor]
) -> torch.Tensor
```

Decode the storage of one expert projection in the released layout as checkpoint loading does.

**Parameters:**

**`adapter`** `Inkling2StateDictAdapter`

The released checkpoint's state dict adapter.

---

**`stored`** `dict[str, torch.Tensor]`

A released expert weight (`model.llm.layers.N.mlp.experts.&#123;w13,w2&#125;_weight`) with its
`_scale` and, for NVFP4, `_amax` and `_outer_scale_denominator` tensors, in the released
dtypes, for a run of experts.

---

**Returns:** `torch.Tensor`

FP32 tensor of shape \[experts, output, input], the released axis order.

```python
nemo_automodel.components.models.inkling2.quantized_export._export_experts(
    adapter: nemo_automodel.components.models.inkling2.state_dict_adapter.Inkling2StateDictAdapter,
    released: dict[str, torch.Tensor],
    name: str,
    trained: torch.Tensor
) -> tuple[dict[str, torch.Tensor], int, int]
```

Write one grouped expert projection, each changed expert in the encoding closest to its trained values.

**Parameters:**

**`adapter`** `Inkling2StateDictAdapter`

Decodes released experts exactly as checkpoint loading does.

---

**`released`** `dict[str, torch.Tensor]`

The projection's released tensors: `name` (NVFP4 uint8 codes \[experts, output, input/2] or
MXFP8 float8_e4m3fn values \[experts, output, input]), `name + "_scale"` and, for NVFP4,
`name + "_amax"` \[experts] and `name + "_outer_scale_denominator"` \[1].

---

**`name`** `str`

Released weight name, `model.llm.layers.N.mlp.experts.&#123;w13,w2&#125;_weight`.

---

**`trained`** `torch.Tensor`

Floating tensor of shape \[experts, output, input], the released axis order (gate/up rows of
`w13` interleaved).

---

**Returns:** `dict[str, torch.Tensor]`

Newly allocated tensors with the released names, dtypes and shapes; the number of changed experts

```python
nemo_automodel.components.models.inkling2.quantized_export._weight_map(
    folder: pathlib.Path
) -> dict[str, str]
```

Tensor name to shard file name, from a checkpoint directory's SafeTensors index.

**Parameters:**

**`folder`** `Path`

Checkpoint directory holding `model.safetensors.index.json`.

---

**Returns:** `dict[str, str]`

The index's `weight_map`.

```python
nemo_automodel.components.models.inkling2.quantized_export.export_quantized(
    released: str | pathlib.Path,
    trained: str | pathlib.Path,
    out: str | pathlib.Path
) -> nemo_automodel.components.models.inkling2.quantized_export.ExportSummary
```

Write `trained` in the layout of `released` to the new directory `out`.

**Parameters:**

**`released`** `str | Path`

Local directory of the released checkpoint the run started from, with its sharded
SafeTensors index, `config.json` and `hf_quant_config.json`.

---

**`trained`** `str | Path`

Floating Inkling2 export with released tensor names and a SafeTensors index, such as a
consolidated training save. Experts are \[experts, output, input] in F32, BF16 or F16.

---

**`out`** `str | Path`

Output directory; it must not exist. The export is written next to it and renamed into place
once complete, so a failed export leaves no `out`.

---

**Returns:** `ExportSummary`

Counts of kept, rounded-back and requantized experts and of kept and converted tensors.

```python
nemo_automodel.components.models.inkling2.quantized_export.main(
    argv: list[str] | None = None
) -> int
```

Command line entry point; see the module docstring.

**Parameters:**

**`argv`** `list[str] | None` — default: None

Arguments without the program name; `None` reads `sys.argv`.

---

**Returns:** `int`

Process exit status, 0 on success.

```python
nemo_automodel.components.models.inkling2.quantized_export._DECODE_ELEMENTS = 1 << 26
```

```python
nemo_automodel.components.models.inkling2.quantized_export._EXPERT = re.compile('model\\.llm\\.layers\\.\\d+\\.mlp\\.experts\\.w(?:13|2)_weight')
```

```python
nemo_automodel.components.models.inkling2.quantized_export._FLOATING = (torch.float32, torch.bfloat16, torch.float16)
```

```python
nemo_automodel.components.models.inkling2.quantized_export._INDEX = 'model.safetensors.index.json'
```

```python
nemo_automodel.components.models.inkling2.quantized_export._NVFP4_METADATA = ('_scale', '_amax', '_outer_scale_denominator')
```

```python
nemo_automodel.components.models.inkling2.quantized_export.logger = logging.getLogger(__name__)
```