nemo_automodel.components.models.minimax_m3_vl.state_dict_adapter
nemo_automodel.components.models.minimax_m3_vl.state_dict_adapter
State-dict adapter for the MiniMax M3 (text) backbone.
Converts between the released HF checkpoint layout and the native AutoModel layout:
block_sparse_moe.{gate,e_score_correction_bias}->mlp.gate.*block_sparse_moe.experts.{e}.{w1,w3,w2}-> groupedmlp.experts.*(gate/up/down) viaMoESplitExpertsStateDictMixinblock_sparse_moe.shared_experts.*->shared_experts.*(a sibling ofmlpon the decoder block)- dense (non-MoE) layers keep
mlp.{gate,up,down}_proj.*unchanged
MXFP8 weights (FP8 e4m3 with e8m0/uint8 block scales along the input dim) are dequantized to the training dtype on load. M3.1 adds NVFP4 packed routed experts and MXFP8 indexer projections. Its native load-part iterator writes directly into final sharded storage while bounding temporary memory to one grouped expert parameter or ordinary projection.
Module Contents
Classes
Functions
Data
API
Bases: MoESplitExpertsStateDictMixin, StateDictAdapter
Convert MiniMax M3 HF checkpoints to/from the native grouped-expert format.
Separate checkpoint metadata from final local projection views.
Parameters:
Native model state-dict name.
Final model tensor. Grouped experts use global [experts, input, 2 * intermediate] gate/up or [experts, intermediate, output] down layouts. EP shards the expert axis; FSDP may additionally shard the input axis.
Returns: list[tuple[str, torch.Tensor, torch.Tensor]]
Tuples of HF name, metadata template, and final local destination.
Decode quantized projections in place before grouped-expert merging.
Parameters:
HF projection weights and quantization companions. MXFP8 uses [output, input] FP8 weights and [output, input / 32] exponent scales. NVFP4 uses [output, input / 2] packed bytes, [output, input / 16] E4M3 scales, and an FP32 global scalar. Distributed tensors retain their matching mesh and placements.
Returns: dict[str, torch.Tensor]
The same mapping, with floating-point [output, input] weights.
Yield bounded M3.1 load parts over final native model storage.
Parameters:
Native names and final CPU/CUDA/DTensor storage with layouts documented by iter_checkpoint_load_parts.
HF wrapper namespace prepended to text checkpoint keys.
Convert MTP tensors through a temporary one-layer text namespace.
Prepare Hugging Face projection tensors for grouped-expert merging.
Parameters:
Mapping mutated in place. Expert projection tensors have shape [expert_hidden, hidden] for gate/up and [hidden, expert_hidden] for down; MXFP8 projection tensors are dequantized before their keys are renamed.
Convert an HF checkpoint to native format (operates in-place to limit peak memory).
Load M3.1 mixed quantized weights into bounded model-owned parts.
Parameters:
Final native storage, including global grouped expert tensors [experts, input, output]. DTensor expert-axis and input-axis shards, and CPU-offloaded local storage, are preserved. The iterator never creates a full model copy.
Existing expert mesh; placements are read from each destination DTensor.
Returns: Iterator[CheckpointLoadPart] | None
One direct-load part followed by one part per quantized native
Bases: StateDictAdapter
VLM adapter: splits the M3 VL checkpoint into text / vision / projector parts.
The released checkpoint stores the language backbone under
language_model.model.* / language_model.lm_head and the vision side
under vision_tower.vision_model.* with the projector / patch-merger at
top level (multi_modal_projector.* / patch_merge_mlp.*). The native
VLM keeps the text model at model.* / lm_head and nests the projector
/ merger under vision_tower.*. Text tensors are delegated to
MiniMaxM3StateDictAdapter (block_sparse_moe -> mlp, index branch,
MXFP8 dequant, grouped experts); vision tensors are BF16 and pass through.
Native text keys loaded through the inner adapter’s checkpoint views.
Yield direct vision storage and bounded text parameter load parts.
Parameters:
Final native tensors with the layout and alias contract documented by iter_checkpoint_load_parts.
Stream text quantization while loading native vision storage directly.
Parameters:
Final model tensors. Text layouts follow the text adapter’s iter_checkpoint_load_parts contract; vision tensors retain their arbitrary native shapes and DTensor placements. DCP writes every destination in place.
Existing expert mesh; tensor placements are retained.
Returns: Iterator[CheckpointLoadPart] | None
Complete, bounded M3.1 load parts, or None for earlier checkpoints.
Temporary checkpoint tensors plus the final projection view they fill.
Final floating-point [output, input] projection view. For experts this aliases the original rank-local CPU/CUDA storage; ordinary projections may retain their global DTensor placements.
Optional replicated FP32 scalar for NVFP4. It divides the block scales; None denotes MXFP8.
Uint8 [output, input / 32] MXFP8 exponents or E4M3 [output, input / 16] NVFP4 scales, matching weight’s placements.
FP8 [output, input] or packed uint8 [output, input / 2] checkpoint staging tensor, with the source DTensor placements.
Decode one [output, input] projection into existing local storage.
Decode the compressed-tensors NVFP4 projection layout used by M3.1.
Reference
Parameters:
Uint8 projection of shape [output, input / 2]. Even input columns use the low nibble, odd columns the high nibble.
E4M3 block scales of shape [output, input / 16].
Positive FP32 scalar in the reciprocal convention.
Floating-point output dtype. Computation takes place in FP32.
Returns: torch.Tensor
Independent tensor of shape [output, input], on packed’s device.
Decode each projection separately, bounding unpacked temporary storage.
Allocate a compressed checkpoint destination matching a weight shard.
Parameters:
Final floating-point projection of global shape [output, input]. A DTensor may shard either axis; every input-axis shard must align to divisor. Its local storage may be CPU or CUDA and noncontiguous.
Compression factor for the input axis, such as 2, 16, or 32.
Checkpoint storage dtype.
Materialization device for a meta template. A CUDA mesh uses CUDA staging even when final model storage is CPU offloaded.
Returns: torch.Tensor
Independent destination of global shape [output, input / divisor],
True for HF-format weight keys stored as MXFP8 in the checkpoint.
Slice a global scale_inv to a DTensor weight’s local shard.
MXFP8 block is [1, block_size]: dim 0 (out) is full-resolution (block 1, so a
row range maps 1:1) and dim 1 (in) is grouped by block_size. Custom MoE is
always tp=1, so sharding is on dim 0 (FSDP / ep_shard); dim 1 handled for safety.
Recognize the released M3.1 mixed MXFP8/NVFP4 checkpoint layout.
Load-time placeholder scale_inv (e8m0/uint8, GLOBAL shape [out, ceil(in/block)]).
Emitted by to_hf(quantization=True) so the DCP planner requests the
checkpoint’s *_scale_inv tensors; the values here are overwritten by the
load. Kept a regular (non-DTensor) tensor with global shape — the per-shard
slice happens in dequantize_mxfp8 (mirrors deepseek_v3).
Dequantize an MXFP8 weight (FP8 e4m3 + e8m0/uint8 block scales) to dtype.
weight is FP8 e4m3 [out, in]; scale_inv holds e8m0 (uint8)
exponents [out, ceil(in/block_size)] with dequant scale for input-block
b = 2 ** (scale_inv[:, b] - 127) (MX e8m0; confirmed vs sglang). Handles
DTensor weights: the local shard is dequantized against the matching slice of a
global scale_inv and rewrapped with the weight’s placements.