> This page is for version 0.5.0 · 26.06.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.7.0 · 26.10: https://docs.nvidia.com/nemo/automodel/v0.7/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.

# 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

| Name                                                                                                                             | Description                                                               |
| -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| [`Ernie5_5MTPCheckpointAdapter`](#nemo_automodel-components-models-ernie5_5-mtp_checkpoint_adapter-Ernie5_5MTPCheckpointAdapter) | Load in place and save sharded MTP state without duplicate native owners. |
| [`_CheckpointDestinations`](#nemo_automodel-components-models-ernie5_5-mtp_checkpoint_adapter-_CheckpointDestinations)           | HF destinations and local runtime state owned by one checkpoint read.     |
| [`_SessionIdentity`](#nemo_automodel-components-models-ernie5_5-mtp_checkpoint_adapter-_SessionIdentity)                         | Unforgeable identity used only to distinguish active local load sessions. |

### API

```python
class nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter(
    config: nemo_automodel.components.models.ernie5_5.config.Ernie5_5Config
)
```

**Bases:** [Ernie5_5MTPStateDictAdapter](/nemo/automodel/v0.5/nemo-automodel/nemo_automodel/components/models/ernie5_5/mtp_state_dict_adapter#nemo_automodel-components-models-ernie5_5-mtp_state_dict_adapter-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.

**`_active_session`** `ReferenceType[_CheckpointDestinations] | None = None`

---

**`_ended_destinations`** `list[ReferenceType[Tensor]] = []`

---

**`_identity`** `_SessionIdentity | None = None`

---

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter.__deepcopy__(
    memo: dict[int, typing.Any]
) -> nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter
```

Copy the adapter without sharing a live session with a copied model.

**Parameters:**

**`memo`** `dict[int, Any]`

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

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._body_aliases(
    decoder: dict[str, torch.Tensor]
) -> dict[str, torch.Tensor]
```

Return MTP body names pointing at the decoder's released tensors.

**Parameters:**

**`decoder`** `dict[str, torch.Tensor]`

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._local(
    value: torch.Tensor
) -> torch.Tensor
```

staticmethod

Return the local shard of a global DTensor, or the original plain tensor.

**Parameters:**

**`value`** `torch.Tensor`

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._open(
    session: nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter._CheckpointDestinations
) -> None
```

Hold the tensor-bearing destination mapping weakly until its paired close.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._owned_hf(
    owned: dict[str, torch.Tensor]
) -> dict[str, torch.Tensor]
```

Return released views of the nine owned tensors.

**Parameters:**

**`owned`** `dict[str, torch.Tensor]`

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._raise_together(
    session: nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter._CheckpointDestinations,
    error: BaseException | None
) -> None
```

staticmethod

Agree on failure across all mesh axes before ranks return or raise.

**Parameters:**

**`session`** `_CheckpointDestinations`

Released-layout destination mapping and explicit runtime groups/device.

---

**`error`** `BaseException | None`

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter._split_state(
    state: dict[str, torch.Tensor]
) -> tuple[dict[str, torch.Tensor], dict[str, torch.Tensor]]
```

Split decoder tensors and the nine native MTP values without copying.

**Parameters:**

**`state`** `dict[str, torch.Tensor]`

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter.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]
```

Verify shared copies, finish the decoder session and return native owners.

**Parameters:**

**`hf_state_dict`** `dict[str, torch.Tensor]`

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.

---

**`device_mesh`** `DeviceMesh | None` — default: None

Decoder load compatibility mesh. A plain-state load requires None.

---

**`**kwargs`** `str | bool | None` — default: \{}

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter.get_hf_state_dict_keys(
    state_dict: dict[str, torch.Tensor]
) -> list[str]
```

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.

```python
nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter.Ernie5_5MTPCheckpointAdapter.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]
```

Return release-layout export views or one opaque in-place load session.

**Parameters:**

**`state_dict`** `dict[str, torch.Tensor]`

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.

---

**`quantization`** `bool` — default: False

Must be False.

---

**`for_checkpoint_load`** `bool` — default: False

Open a load session requiring an unchanged paired mapping.

---

**`v4_compatible`** `bool` — default: False

Must be False.

---

**`**kwargs`** `str | bool | DeviceMesh | None` — default: \{}

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.

```python
class nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter._CheckpointDestinations()
```

**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.

**`alias_pairs`** `dict[str, tuple[Tensor, Tensor]]`

---

**`created`** `tuple[ReferenceType[Tensor], ...]`

---

**`decoder_destinations`** `dict[str, Tensor]`

---

**`flag_device`** `device`

---

**`groups`** `tuple[ProcessGroup, ...]`

---

**`original`** `dict[str, Tensor]`

---

**`owned_native`** `dict[str, Tensor]`

---

```python
class nemo_automodel.components.models.ernie5_5.mtp_checkpoint_adapter._SessionIdentity()
```

Unforgeable identity used only to distinguish active local load sessions.