nemo_automodel.components.models.inkling2.quantized_export
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 <step>/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
Functions
Data
API
What export_quantized wrote. Experts are counted per projection; the three counts add up to all of them.
Floating tensors written from their trained values in the released dtype.
Floating tensors whose released bytes were kept.
model.visual.* tensors absent from the trained export, copied from the release.
Experts written with codes or scales that differ from the release.
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.
Experts whose trained values equal their decoded released bytes; the bytes are kept.
Raw bytes of a tensor, one row per index of its leading axis.
Parameters:
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
Decode the storage of one expert projection in the released layout as checkpoint loading does.
Parameters:
The released checkpoint’s state dict adapter.
A released expert weight (model.llm.layers.N.mlp.experts.{w13,w2}_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.
Write one grouped expert projection, each changed expert in the encoding closest to its trained values.
Parameters:
Decodes released experts exactly as checkpoint loading does.
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].
Released weight name, model.llm.layers.N.mlp.experts.{w13,w2}_weight.
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
Tensor name to shard file name, from a checkpoint directory’s SafeTensors index.
Parameters:
Checkpoint directory holding model.safetensors.index.json.
Returns: dict[str, str]
The index’s weight_map.
Write trained in the layout of released to the new directory out.
Parameters:
Local directory of the released checkpoint the run started from, with its sharded
SafeTensors index, config.json and hf_quant_config.json.
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.
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.
Command line entry point; see the module docstring.
Parameters:
Arguments without the program name; None reads sys.argv.
Returns: int
Process exit status, 0 on success.