nemo_automodel.components.checkpoint.state_dict_adapter
nemo_automodel.components.checkpoint.state_dict_adapter
Module Contents
Classes
API
Abstract base class for state dict transformations.
This class defines the interface for converting between native model state dict format and other model state dict formats.
Whether DCP can load this adapter without another full set of model weights.
Large checkpoint tensors must be loaded into the model’s existing weight memory. Small temporary tensors are allowed when they can be applied and discarded without making a model-sized copy. For example, Gemma4 loads a scale tensor and applies it to already-loaded expert weights.
Whether every checkpoint tensor is loaded directly into the model’s existing weight memory.
Enable this only when writing every tensor returned by to_hf for base-checkpoint loading updates the
model itself. This lets the loader skip a complete CPU copy of the checkpoint.
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.
Obtain native model state dict from HuggingFace format.
Parameters:
The HuggingFace format state dict
Optional device mesh for DTensor expert parallelism. If provided, only loads experts needed for the current rank.
Returns: dict[str, Any]
The converted native model state dict
Return the Hugging Face keys produced by to_hf.
Parameters:
Native model state mapping. Tensor values may have arbitrary rank and axis order and retain their exact parameter or buffer layouts.
Returns: list[str]
Hugging Face state-dict keys in adapter iteration order.
Translate a PEFT target-module name to the HuggingFace layout.
adapter_config.json’s target_modules are collected from native module
names. Adapters whose to_hf renames modules (e.g. Kimi K3’s
mlp.experts.{E}.gate_proj -> block_sparse_moe.experts.{E}.w1)
should override this with the same renames so PEFT can resolve the
entries against the converted checkpoint.
Parameters:
A target-module name in native layout.
Returns: str
The name in HuggingFace layout. Defaults to the name unchanged.
Convert from native model state dict to HuggingFace format.
Parameters:
The native model state dict
Returns: dict[str, Any]
The converted HuggingFace format state dict