nemo_automodel.components.models.mistral_large4.state_dict_adapter
nemo_automodel.components.models.mistral_large4.state_dict_adapter
Native names and bounded E4M3 reconstruction using existing DCP load parts.
Matrices retain separate gate/up projections and individual expert identities. Grouped expert storage exports the same released identities through transposed views.
Module Contents
Classes
Functions
Data
API
Bases: StateDictAdapter
Lossless name mapping and bounded source-FP8 initialization.
Individual and grouped experts export the same released gate/up/down matrices. Vision tensors retain their native names/layouts and load directly into the conditional model. DSpark draft tensors keep their released names and are not loaded. Native floating save/resume never attaches original FP8 scales. FSDP and balanced expert-subset loading are supported. Pipeline peers group local destinations into equal numbers of nonempty load parts, retaining bounded FP8 staging.
Fuse complete per-layer expert banks for the in-memory import path.
Parameters:
Floating native matrices [out, in]. Expert inputs must be complete unsharded matrices; the streaming loader supports sharded destinations without making this in-memory copy.
Optional MoE mesh; only the EP axis participates here.
Returns: dict[str, torch.Tensor]
New mapping with grouped [E, hidden, 2*intermediate] gate/up and
Yield one parameter per part, staging at most one local expert bank.
Parameters:
Native tensors; linear matrices [out, in], grouped gate/up [experts, hidden, 2*intermediate] and down [experts, intermediate, hidden]. EP shards axis 0 and expert FSDP shards axis 1. Other tensors retain checkpoint axes.
Returns: Iterator[CheckpointLoadPart]
Parts whose FP8 staging covers only the local parameter shard.
Keep original local storage views even when distributed export changes device.
Parameters:
Native grouped gate/up or down parameter name.
Grouped [E, hidden, 2*intermediate] or [E, intermediate, hidden] tensor, optionally EP/FSDP sharded and CPU offloaded.
Returns: dict[str, torch.Tensor]
Released per-expert names to plain local [out, in] views. Their
Convert one floating tensor for checkpoint import or export.
Parameters:
Model parameter name.
Floating tensor with native axes, [output, input] for matrices; grouped gate/up [E, hidden, 2*intermediate], down [E, intermediate, hidden]. EP shards axis 0; expert FSDP shards axis 1. Splits/transposes alias storage. Floating exports preserve DTensor layouts.
Unsupported; exports preserve the floating training dtype.
Returns: list[tuple[str, torch.Tensor]]
Native (name, tensor) pairs whose values alias the input.
Prevent export from recasting decoded weights to the source FP8 dtype.
Parameters:
Already-exported tensors retaining checkpoint axes, matrices [output, input], optionally DTensors. Only dtype is inspected.
Returns: dict[str, str]
Released-key dtype overrides for every floating tensor. FP32 master
Convert a dependency-complete source mapping without consuming it.
Parameters:
Native checkpoint tensors, with weights [output, input] and FP32 scale grids [ceil(output/128), ceil(input/128)]. BF16 tensors retain checkpoint axes and may alias the returned values. FP8 matrices may be regular DTensor shards with global shapes.
Existing loader argument; DTensors own their placements.
Returns: dict[str, torch.Tensor]
Model names with matching axes, or fused grouped gate/up
Yield bounded destination groups through the existing checkpoint loader hook.
Parameters:
Model names mapped to final tensors; linear weights use [output, input]; grouped gate/up uses [E, hidden, 2*intermediate] and down [E, intermediate, hidden]. Other tensors keep checkpoint axes. DTensors may shard either matrix axis; every rank must iterate the same number of parts. Nonquantized values alias final model storage. Quantized values use local FP8 staging.
Existing loader argument; each DTensor carries its mesh.
Returns: Iterator[CheckpointLoadPart]
Parts covering every model key exactly once. PP groups at most
Use the same projection mapping in adapter metadata and tensor export.
Export floating training weights with released checkpoint names.
Parameters:
Model tensors with checkpoint axes; matrix [output, input] or grouped experts [E, hidden, 2*intermediate] / [E, intermediate, hidden], optionally EP Shard(0) and expert-FSDP Shard(1) DTensors.
Existing checkpoint API filter on model names.
Unsupported; source FP8 is decoded on import, training saves floating weights.
Existing export hook; DTensors carry their EP ownership.
Existing hook; released names have one layout.
Existing hook; this model has no grouped ParamWrapper.
Existing hook; floating destinations always alias model storage.
Returns: dict[str, torch.Tensor]
Floating tensors alias inputs and retain their training dtype.
Reconstruct into existing floating storage, using global scale coordinates.
FP32 conversion and elementwise scale temporaries cover at most 1024x1024 values each. FP8 source values are cast to FP32, scaled, then cast once into destination storage. Neither source input is modified.
Parameters:
E4M3 matrix [global_output, global_input], local or a regular Shard/Replicate DTensor. No projection transpose has occurred.
Replicated FP32 grid [ceil(global_output/128), ceil(global_input/128)] on the weight’s device, holding positive finite numeric multipliers.
BF16/FP32 matrix with the same global shape and placements as weight. Written in place without changing parameter identity. The local tensor may be a noncontiguous view.
Decode local FP8 expert matrices sequentially into existing model views.
Decode each FP8 matrix [out, in] sequentially into final model storage.
Find global coordinates of a contiguous two-dimensional DTensor shard.
Parameters:
Matrix [global_output, global_input], with regular Shard or Replicate placements on any mesh axes. Partial and strided shards are unsupported. Repeated sharding of either axis is allowed.
Returns: tuple[int, int]
Global output and input offsets of the rank-local matrix.
Map a released text tensor name to its model-owned native parameter.
Reverse the text mapping without allocating or reading tensor values.