nemo_automodel.components.models.flint.state_dict_adapter
nemo_automodel.components.models.flint.state_dict_adapter
Strict Flint checkpoint conversion using the shared split-expert layout.
Module Contents
Classes
Data
API
Bases: MoESplitExpertsStateDictMixin, StateDictAdapter
Convert split BF16 base or FP32 resume weights without losing source names.
HF experts are [intermediate, hidden] gate/up and [hidden, intermediate] down tensors. Native grouped weights are [experts, hidden, 2 * intermediate] (gate before up) and [experts, intermediate, hidden]. Shared expert paths and the FP32 sink holder are
renamed; all other ordinary layouts are unchanged.
from_hf consumes its input mapping, as the shared merging implementation
does. Runtime storage remains FP32 when requested. to_hf never casts
training weights to BF16: consolidated-export dtype belongs to the shared
writer’s original-checkpoint metadata. Export may allocate contiguous
per-expert tensors; its memory use is distinct from direct loading.
Opt in only for the tested single-process model-backed Torch weights.
Enumerate source HF shapes without allocating any checkpoint tensors.
Validate and join complete expert PEFT families using the shared mixin.
Parameters:
Adapter-only HF tensors. Linear A/B weights have shape [rank,input]/[output,rank]; per-expert gate/up/down use those layouts independently. Meta tensors validate metadata without payload reads; materialized duplicated gate/up A values must be identical because they share one native adapter.
Returns: dict[str, torch.Tensor]
Native linear and grouped expert LoRA weights in layouts documented
Reverse only the two Flint-owned ordinary module path changes.
Identify only instantiated TE bookkeeping, never source HF weights.
Validate the shapes of existing native linear and grouped LoRA tensors.
Parameters:
Native BF16/FP32 tensors, optionally carrying the shared
PEFT base_model.model. prefix. Linear A/B weights are
[rank,input]/[output,rank]; grouped expert A/B weights are
[experts,input,rank]/[experts,rank,output]. DTensor shapes
are global and retain their expert-axis placements.
Returns: dict[str, tuple[int, ...]]
Exact allowed LoRA shapes derived from the corresponding known
Translate ordinary HF paths into the native shared-expert/sink paths.
Describe global native layouts, including the two grouped projections.
Reject unknown names, incompatible global shapes and unsupported dtypes.
Parameters:
Mapping of parameter names to BF16/FP32 tensors. Ordinary
HF tensors use [out, in] matrices or one-dimensional norm/
sink scales. Native grouped tensors use [experts, hidden, 2 * intermediate] and [experts, intermediate, hidden].
DTensor shapes are global, retaining their original placements.
Required global shape for every allowed mapping key.
Convert one global native weight using the shared expert machinery.
Parameters:
Exact native model parameter name.
BF16/FP32 native tensor. Ordinary shapes are unchanged;
grouped shapes are [experts, hidden, 2 * intermediate] or
[experts, intermediate, hidden]. DTensors retain global
shapes and the shared mixin’s adjusted rank-local placements.
Shared conversion flags, including for_checkpoint_load.
Returns: list[tuple[str, torch.Tensor]]
HF name/tensor pairs; plain Torch load-mode tensors alias the
Validate and consume HF weights, joining only the owned expert rows.
Parameters:
Complete BF16 base or FP32 resume mapping in HF
[out, in] layouts, consumed by this call. After to_hf in
load mode, keys must exactly match that call’s DCP destinations.
DTensors retain global shapes and shard placements.
Optional shared expert mesh selecting global expert IDs owned by this rank; no distributed capability is advertised.
Compatibility arguments of the shared adapter interface.
Returns: dict[str, torch.Tensor]
Native mapping with FP32 sinks/head, unchanged ordinary layouts and
Expose HF tensors, preserving resident precision and load aliases.
Parameters:
Native weights with the global layouts documented on this adapter. Tensor dtype/device/placements are preserved; load destinations alias native storage on the plain Torch path.
HF/native names to omit, typically backend state.
Must be false: the supplied checkpoint is unquantized.
Build a complete set of destination views for DCP. Save/export callers leave this false; grouped exports may allocate contiguous tensors without mutating source values.
Shared checkpoint protocol arguments forwarded to the expert mixin, including device mesh and serialization options.
Returns: dict[str, torch.Tensor]
HF-keyed tensors in split-expert [out, in] layout. Plain Torch
Hold one destination’s storage alive and identify its exact tensor view.
Identify local storage without copying any parameter payload.
Parameters:
Ordinary HF-shaped destination or DTensor with that global shape; the local tensor retains its existing strided storage.
Returns: _LoadAlias | None
Storage/view identity, or None for a shape-only meta destination.
Check the exact destination storage, offset, layout, dtype and device.
Parameters:
Current HF expert tensor, possibly a different Python view of the original destination. None denotes an absent key.
Returns: bool
Whether this view still aliases the recorded destination exactly.