nemo_automodel.components.models.inkling2.state_dict_adapter
nemo_automodel.components.models.inkling2.state_dict_adapter
Inkling2 text checkpoint mapping and mixed-precision import through DCP load targets.
Module Contents
Classes
Functions
Data
API
Bases: StateDictAdapter
Map the delivered text weights; preserve floating checkpoint layouts on export.
Multimodal configs additionally map visual parameters without changing their layout.
Load destinations normally alias model storage. Quantized experts, row-sharded fused
projections and singleton residual queries instead get staging tensors from
to_hf(for_checkpoint_load=True); from_hf decodes or copies them into the
original storage and reports those keys through view_loaded_native_keys.
Native keys completed in model storage by from_hf after the most recent DCP load.
The shared loader counts them as loaded although from_hf omits them from its result.
Allocate one replicated native-shaped temporary for a row-sharded layout conversion.
Parameters:
Native fused projection or singleton residual query name.
Final destination with Shard(0) on one or more mesh axes.
Returns: dict[str, torch.Tensor]
Source-named views of the temporary for DCP to fill.
Allocate packed source-layout staging for one grouped expert projection.
Parameters:
Native grouped expert key, layers.N.mlp.experts.{gate_and_up_projs,down_projs}.
Final floating [experts, input, output] storage; DTensor shards are preserved and Partial placements are rejected.
Returns: dict[str, torch.Tensor]
Uninitialized packed weight, block scales and, for NVFP4 layers, per-expert amax and the
Return source-layout tensors, gathering row shards only when the layout requires it.
Parameters:
Native text parameter or persistent-buffer name.
Native parameter layout; grouped experts are [experts, input, output].
Zero omitted fused-projection padding in destination storage before loading. Floating export otherwise leaves the input unchanged.
Returns: list[tuple[str, torch.Tensor]]
Source names and tensors retaining dtype/device. Fused row splits and
Export actual floating dtypes instead of reusing packed source-checkpoint dtype metadata.
Parameters:
Source-named floating export views, with arbitrary parameter shapes.
Returns: dict[str, str]
SafeTensors dtype names for every exported tensor, including intrinsic FP32 groups.
Convert an already-read text checkpoint, preserving interleaving and supplied floating dtypes.
Parameters:
Delivered source names and floating or packed tensors. After a DCP load into
to_hf(for_checkpoint_load=True) destinations, the staged quantized experts and replicated
layout temporaries are decoded or copied into model storage here and omitted from the result.
model.visual tensors are omitted intentionally by the text-only entry point. Quantized experts
read into a full CPU state dict use [E,output,packed_input] storage.
Shared-loader context; DTensor values keep their own placements.
Returns: dict[str, torch.Tensor]
Native tensor mapping. Direct weights are views. Keys completed in model storage are reported
List released base keys without treating newly injected LoRA rows as base weights.
Parameters:
Native model tensors, possibly with unprefixed LoRA A/B matrices [rank, input]/[output, rank] or grouped [experts, …, rank].
Returns: list[str]
Released base tensor names only. Adapter saves use the shared PEFT
Export floating source-layout views, or allocate DCP load destinations.
Parameters:
Native tensors in their original floating layouts and placements.
Optional shared-loader exclusion pattern.
Allocate packed expert staging matching the released NVFP4/MXFP8 layout. Requires for_checkpoint_load; trained weights are exported without quantization.
Whether shared checkpointing requested DCP destinations. Row-sharded fused projections and singleton residual queries then get one replicated temporary each, which from_hf redistributes into the original shards.
Shared-loader context; placements are retained on each tensor view.
Legacy config export is not qualified for this text entry point.
Legacy expert LoRA export is unsupported.
Returns: dict[str, torch.Tensor]
Source-named tensors. Export returns floating views and leaves inputs unchanged. Load
One native-shaped temporary and its original sharded destination.
Copy [rows, hidden] or [queries, hidden] into the original DP/EP shard storage.
Source [experts, output, input] tensors and a matching floating destination view.
The destination aliases model storage, potentially a noncontiguous transpose. Packed FP4 has input/2 columns, scales have input/16 or input/32 columns. Only one expert and at most 128 output rows are expanded at a time.
Decode source tiles in FP32, cast once and copy into the existing destination.
Allocate [experts] outer-scale metadata, replicated across inner-axis shards.
Parameters:
Expert tensor [experts, …]; a DTensor supplies the mesh and placements, of which only a leading-axis shard is kept.
Returns: torch.Tensor
Newly allocated, uninitialized FP32 [experts] storage on the template’s device. A
Return the tensor’s local storage without copying.
Parameters:
Tensor of shape […], with arbitrary rank and axis order. A DTensor describes the global shape and its mesh placements.
Returns: torch.Tensor
Tensor with the same axis order, dtype and device. For a DTensor, each dimension
Identify source-layout operations that intersect a native row shard.
Parameters:
Native parameter name.
Projection [rows, hidden] or residual query [queries, hidden], optionally DTensor with Shard(0) on one or more mesh axes.
Returns: bool
True for a sharded fused row split or removal of a sharded singleton axis.
Allocate source-layout storage for […, input/divisor], preserving shard placements.
Parameters:
Floating destination […, input]; a DTensor supplies the global shape and
placements, and both its global and local trailing extents must be multiples
of divisor.
Source elements per storage element along the trailing axis: 2 for packed FP4 pairs, the block size for block scales.
Storage dtype of the source tensor.
Returns: torch.Tensor
Newly allocated, uninitialized […, input/divisor] storage on the template’s device.