nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter
Model-owned extension of the existing whole-state MTP adapter.
Reuses the decoder’s public two-call load session, layouts and distributed export. Shared-body checkpoint copies are independent read destinations and must agree with the decoder destinations before its finishers run. A failed, abandoned or exchanged session makes this adapter unusable. Read copies are compared after conversion to the destination dtype, using value equality: signed zero agrees, NaN does not. This is not an audit of stored file bytes. Ordinary validation and decoder-finisher failures are agreed across rank groups. Control interrupts propagate immediately and require launcher-driven peer termination.
Module Contents
Classes
API
Bases: Ernie5_5MTPStateDictAdapter
Load in place and save sharded MTP state without duplicate native owners.
The admitted distributed topology covers all job ranks. Error agreement uses every axis group of the embedding’s mesh, which covers both flattened and two-dimensional diagnostic checkpoint layouts. The production ERNIE parallelizer admits a one-dimensional FSDP mesh. This requires symmetric calls on ranks; KeyboardInterrupt and SystemExit propagate immediately.
Copy the adapter without sharing a live session with a copied model.
Parameters:
Python copy.deepcopy memo, whose graph nodes have arbitrary
library-owned types. The opaque value type is confined to this
standard-library protocol boundary, as in the decoder adapter.
Returns: Ernie5_5MTPCheckpointAdapter
An independent idle adapter, or an unusable adapter when the original
Return MTP body names pointing at the decoder’s released tensors.
Parameters:
Released decoder destinations/export views, in their released layouts.
Returns: dict[str, torch.Tensor]
Alias names and the same tensor objects, excluding the decoder’s router bias.
Return the local shard of a global DTensor, or the original plain tensor.
Parameters:
Tensor in any layout; a DTensor has its declared global shape and placements.
Returns: torch.Tensor
Plain local tensor, without gathering or copying its storage.
Hold the tensor-bearing destination mapping weakly until its paired close.
Return released views of the nine owned tensors.
Parameters:
Native owned tensors. The head matrix has shape [streams, streams*hidden].
Returns: dict[str, torch.Tensor]
Released names and views; head shape [streams*hidden, streams], others unchanged.
Agree on failure across all mesh axes before ranks return or raise.
Parameters:
Released-layout destination mapping and explicit runtime groups/device.
Local failure, or None. No tensor values are exchanged.
Raises:
RuntimeError: If another rank rejects the load; the message identifies detecting ranks.BaseException: The original local validation or finisher error is re-raised on its detecting rank.
Split decoder tensors and the nine native MTP values without copying.
Parameters:
Native names mapped to registered tensors in native layouts; DTensor shapes are global. The owned head is [streams, streams*hidden].
Returns: tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]
Decoder mapping and owned mapping (without mtp.), both aliasing inputs.
Raises:
ValueError: If the native state does not contain exactly eight owned parameters and one router bias.
Verify shared copies, finish the decoder session and return native owners.
Parameters:
The exact live mapping returned by the load-opening to_hf,
with unchanged keys and tensor objects in released layouts. Without
a session, a complete unsharded mapping follows the parent contract.
Decoder load compatibility mesh. A plain-state load requires None.
Decoder compatibility options.
Returns: dict[str, torch.Tensor]
Native tensors with unique decoder and MTP owners; session-owned head matrix
Raises:
RuntimeError: If session identity or lifecycle is invalid, or another rank rejects the load.ValueError: If keys, destination identities or shared values violate the load contract.BaseException: Unexpected validation and decoder-finisher errors propagate after rank agreement; process-control interrupts propagate immediately.
Plan released names before sharding, without starting a load session.
Raises:
RuntimeError: If a load is active, failed or abandoned.ValueError: If key planning is requested after tensors have been sharded.
Return release-layout export views or one opaque in-place load session.
Parameters:
Native tensor mapping with decoder model.* and nine mtp.*
entries. DTensor global shapes/placements follow the decoder adapter;
owned head [streams, streams*hidden], bias [experts]. Bias may be a
replicated plain FP32 tensor while the parameters are DTensors.
Must be False.
Open a load session requiring an unchanged paired mapping.
Must be False.
Public decoder-checkpointer compatibility options.
Returns: dict[str, torch.Tensor]
Released tensors, head [streams*hidden, streams]. Export aliases share decoder
Raises:
NotImplementedError: If quantization or v4 metadata export is requested.RuntimeError: If a load is active, failed or abandoned.ValueError: If the native ownership or full-job embedding mesh is invalid.
Bases: dict[str, Tensor]
HF destinations and local runtime state owned by one checkpoint read.
Tensor values use released global layouts (DTensors hold only local shards). The decoder mapping stays strongly referenced and unchanged. Owned values retain their native layouts; the MTP head matrix is [streams, streams*hidden]. Alias pairs hold (independent scratch, decoder destination), both in the same released layout. Their plain local shards are compared after storage casts.
Unforgeable identity used only to distinguish active local load sessions.