Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsModelsErnie5 5nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter

nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter

View as MarkdownOpen in Claude

Whole-state, unsharded checkpoint layout for one-depth ERNIE 5.5 MTP.

The decoder conversion is delegated to its existing adapter. Shared MTP body keys are export aliases only; native storage has no duplicate body parameters. Low-memory/in-place DCP loading and streaming consolidation are not established by this whole-state adapter. Native state_dict save/restore does not require this adapter.

Module Contents

Classes

NameDescription
Ernie5_5MTPStateDictAdapterMap eight owned parameters, one bias and shared export aliases exactly.

Functions

NameDescription
_mtp_body_suffixUse the released extra nesting for the ten shared hyper-connection tensors.

Data

_OWNED

API

class nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter.Ernie5_5MTPStateDictAdapter(
)

Bases: StateDictAdapter

Map eight owned parameters, one bias and shared export aliases exactly.

bias_suffix
= 'block_sparse_moe.e_score_correction_bias'
body_prefix
= f'model.layers.{config.num_hidden_layers - 1}.'
decoder
mtp_prefix
= f'model.layers.{config.num_hidden_layers}.'
nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter.Ernie5_5MTPStateDictAdapter.convert_single_tensor_to_hf(
fqn: str,
tensor: torch.Tensor,
kwargs: str | bool | None = {}
) -> list[tuple[str, torch.Tensor]]

Reject streaming export until its full alias/decoder contract is implemented.

Parameters:

fqn
str

Native tensor name.

tensor
torch.Tensor

Tensor in the native parameter’s semantic layout.

**kwargs
str | bool | NoneDefaults to {}

Framework compatibility options.

Returns: list[tuple[str, torch.Tensor]]

No result; this adapter supports whole-state conversion only.

Raises:

  • NotImplementedError: Single-tensor conversion cannot construct the complete shared-body HF layout.
nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter.Ernie5_5MTPStateDictAdapter.from_hf(
hf_state_dict: dict[str, torch.Tensor],
device_mesh: torch.distributed.device_mesh.DeviceMesh | None = None,
kwargs: str | bool | None = {}
) -> dict[str, torch.Tensor]

Convert a complete HF mapping, refusing conflicting shared copies.

Parameters:

hf_state_dict
dict[str, torch.Tensor]

Whole unsharded HF tensors; decoder keys and MTP body keys have matching shapes/dtypes/values. The owned head matrix has HF shape [streams * hidden, streams]. Meta inputs are unsupported.

device_mesh
DeviceMesh | NoneDefaults to None

Must be None for this whole-state conversion.

**kwargs
str | bool | NoneDefaults to {}

Compatibility options forwarded to the decoder adapter.

Returns: dict[str, torch.Tensor]

Unique native tensors in registered layouts; the owned head matrix

Raises:

  • NotImplementedError: If the HF mapping contains sharded tensors.
  • ValueError: If required keys are missing, layouts are invalid or shared copies differ from their owners.
nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter.Ernie5_5MTPStateDictAdapter.to_hf(
state_dict: dict[str, torch.Tensor],
quantization: bool = False,
for_checkpoint_load: bool = False,
v4_compatible: bool = False,
kwargs: str | bool | torch.distributed.device_mesh.DeviceMesh | None = {}
) -> dict[str, torch.Tensor]

Export the whole native state without copying shared body storage.

Parameters:

state_dict
dict[str, torch.Tensor]

Unsharded native tensors in their registered layouts; decoder tensors have model.* names and MTP-owned tensors mtp.*. mHC head projection is [streams, streams * hidden] natively.

quantization
boolDefaults to False

Must be False.

for_checkpoint_load
boolDefaults to False

Must be False; in-place load sessions are not supported.

v4_compatible
boolDefaults to False

Must be False.

**kwargs
str | bool | DeviceMesh | NoneDefaults to {}

Checkpointer compatibility arguments passed to the decoder adapter.

Returns: dict[str, torch.Tensor]

HF tensor layouts, including [streams * hidden, streams] MTP head

Raises:

  • NotImplementedError: If load destinations, quantization or sharded tensors are requested.
  • ValueError: If the eight owned parameters and persistent router bias are not present exactly once.
nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter._mtp_body_suffix(
decoder_suffix: str
) -> str

Use the released extra nesting for the ten shared hyper-connection tensors.

nemo_automodel.components.models.ernie5_5.mtp_state_dict_adapter._OWNED = {'enorm.weight': 'enorm.weight', 'hnorm.weight': 'hnorm.weight', 'e_proj.weight'...