nemo_automodel.components.models.gpt_oss.state_dict_adapter
nemo_automodel.components.models.gpt_oss.state_dict_adapter
Module Contents
Classes
Functions
Data
API
Bases: StateDictAdapter
Convert the mxfp4 weights to bfloat16.
Build lazy direct and per-layer MXFP4 load parts.
Parameters:
Native names mapped to final single-device tensors. Expert tensors have layout
[experts, input_features, output_features] and BF16 or FP32 dtype. All direct destinations are
mutated in place by DCP.
Complete decoder-layer indices mapped to the two native expert projection names owned by each layer.
Map one native GPT-OSS tensor name to its Hugging Face name.
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
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.
Load a single-GPU GPT-OSS MXFP4 checkpoint one decoder layer at a time.
Ordinary checkpoint tensors load directly into their final model tensors. Each decoder-layer part allocates
only that layer’s packed uint8 expert blocks and scales. After DCP fills them, the part decodes one projection
at a time into the existing BF16 or FP32 model tensor and releases the packed values before advancing. Backend
bookkeeping entries ending in _extra_state are not checkpoint tensors and keep their initialized values.
This path intentionally requires a complete, non-distributed decoder. Distributed GPT-OSS loading already uses rank-local DCP tensors, while some distributed expert backends expose state-dict tensors that do not own the final parameter storage.
Parameters:
Native names mapped to final model tensors. Expert projection tensors must have layout
[experts, input_features, output_features], use BF16 or FP32, and own ordinary single-device
storage. Other tensors retain arbitrary model-defined shapes, dtypes, devices, strides, and storage.
Optional distributed mesh. A non-None mesh disables this single-device path.
Returns: Iterator[CheckpointLoadPart] | None
One direct-load part for ordinary tensors followed by one bounded temporary-load part per decoder layer,
Convert from native model state dict to HuggingFace format.
Install one decoder layer’s packed MXFP4 expert tensors into model storage.
Parameters:
GPT-OSS adapter that decodes the checkpoint’s MXFP4 representation.
Tuples of (target, blocks, scales). Each target is a final BF16 or FP32 model tensor with
layout [experts, input_features, output_features]. blocks is a temporary uint8 checkpoint tensor
with layout [experts, output_features, input_features / 32, 16]; each byte holds two FP4 values.
scales is its temporary uint8 exponent tensor with layout
[experts, output_features, input_features / 32]. This function mutates each target in place and does
not retain the temporary tensors.