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

Distributed-checkpoint destinations and export views of a sharded ERNIE 5.5 model.

Load destinations expose the storage of an already sharded, materialized model under the released Hugging Face
names and layouts, so that a distributed checkpoint (DCP) read writes every rank's shard in place. Tensors whose
released layout cannot alias model storage (the three mHC alphas and the fused DSA K/V projection) are read into
temporaries and installed by a `finish` callback.

Export views present the same sharded storage under the released names and layouts for a DCP save. Only the
fused DSA K/V projection is copied; the three mHC alphas are slices of the gathered scale vector.

Dtypes. The DCP reader converts the dtype stored in the checkpoint while it fills a destination; nothing here
reads or detects the stored dtype. A destination that aliases model storage has the dtype of the native tensor.
The only destination whose dtype is free is the temporary target of the fused DSA K/V projection:

* its temporary target dtype is fixed to FP32. FP32 represents every BF16, FP16 and FP32 value exactly, so
  the read does not round for a checkpoint that stores one of these three dtypes;
* `finish` then casts to the dtype of the native key and value projections (BF16, FP16 or FP32);
* BF16, FP16 and FP32 are the supported stored dtypes. A checkpoint that stores another dtype (FP64,
  integer or quantized formats) is not supported: the reader would convert it silently, and FP64 values
  would be rounded.

Limitations:

* Storage must be materialized (not on the meta device). mHC parameters and the DSA K/V projections must be
  one-dimensional `Shard(0)` DTensors.
* The K/V shards of a DSA layer must hold whole attention heads: the number of data-parallel ranks must
  divide `hybrid_mla_num_attention_heads`. With the 64 heads of the released configuration a load or a
  save works on 1, 2, 4, 8, 16, 32 or 64 ranks; on any other number of ranks both raise `ValueError`.
* Routed experts must have one of two layouts, without empty shards: `(Shard(1), Shard(0))` DTensors on
  an `(ep_shard, ep)` mesh, or `(Shard(0),)` DTensors on an `(ep,)` mesh, where every rank holds
  whole experts (one data-parallel rank per expert group). Tied embedding and output-head weights and MTP
  layers are rejected.
* Load destinations alias model storage and are written in place. They are meant for a checkpoint load
  between optimizer steps; a failed load leaves the model partially overwritten.
* All ranks must call the export functions in the same order: gathering the mHC scale is a collective.
  The per-expert keys of a rank cover only the experts that the rank holds.
* Optimizer state, PEFT adapters, quantized checkpoints and streaming export are not handled here.

## Module Contents

### Classes

| Name                                                                                            | Description                                                             |
| ----------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [`DsaKVDcpLoadPart`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-DsaKVDcpLoadPart) | Load a fused HF KV tensor into a temporary, then install split weights. |
| [`MhcDcpLoadPart`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-MhcDcpLoadPart)     | Load the HF projection and bias plus three one-element scale tensors.   |

### Functions

| Name                                                                                                                        | Description                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| [`_decoder_export_part`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_decoder_export_part)                     | Return the released tensors of one sharded decoder layer for a distributed save.                  |
| [`_decoder_layer_names`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_decoder_layer_names)                     | Return the native tensor names of one decoder layer, split by how they reach the released layout. |
| [`_shard_range`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_shard_range)                                     | Return the contiguous partition used by torch.chunk.                                              |
| [`_validate_kv`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_validate_kv)                                     | Check the split K/V projections of one DSA layer and return this rank's shards.                   |
| [`_validate_mhc`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_validate_mhc)                                   | Check the three parameters of one mHC unit before a distributed load or save.                     |
| [`common_hf_dcp_views`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-common_hf_dcp_views)                       | Return detached model-storage views in the eight released HF layouts.                             |
| [`expert_hf_dcp_views`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-expert_hf_dcp_views)                       | Return rank-local HF w1/w2/w3 destinations aliasing expert storage.                               |
| [`merge_dsa_kv_for_hf`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-merge_dsa_kv_for_hf)                       | Merge the split key and value projections of one DSA layer into the released fused layout.        |
| [`mhc_hf_export_views`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-mhc_hf_export_views)                       | Return the five released tensors of one mHC unit for a distributed save.                          |
| [`model_hf_dcp_load_destinations`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-model_hf_dcp_load_destinations) | Return the DCP destinations of a whole sharded model and the callbacks that complete the load.    |
| [`model_hf_distributed_export`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-model_hf_distributed_export)       | Return the released tensors of a whole sharded model for a distributed save.                      |

### Data

[`_EXPERT_LAYOUTS`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_EXPERT_LAYOUTS)

[`_FUSED_KV_TEMPORARY_DTYPE`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_FUSED_KV_TEMPORARY_DTYPE)

[`_MHC_UNITS`](#nemo_automodel-components-models-ernie5_5-checkpoint_io-_MHC_UNITS)

### API

```python
class nemo_automodel.components.models.ernie5_5.checkpoint_io.DsaKVDcpLoadPart(
    key_weight: torch.distributed.tensor.DTensor,
    value_weight: torch.distributed.tensor.DTensor,
    heads: int,
    latent: int,
    key_channels: int,
    value_channels: int
)
```

Load a fused HF KV tensor into a temporary, then install split weights.

Only one-dimensional `Shard(0)` projections whose shards hold whole attention heads are supported:
the number of ranks of the mesh must divide the head count.

The temporary target dtype is fixed to FP32. It is not the dtype stored in the checkpoint, which this
class never sees: the DCP reader converts the stored values while it fills the temporary. That conversion
is exact for the supported stored dtypes BF16, FP16 and FP32; another stored dtype is not supported.
`finish` then casts to the dtype of the native projections.

**`target`**

Temporary FP32 DTensor of global shape \[heads \* (key_channels + value_channels), latent] with
placements `(Shard(0),)`; the DCP destination of the released `kv_b_proj.weight`. Each rank
holds the rows of its own heads.

---

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.DsaKVDcpLoadPart.finish() -> None
```

Install a fully loaded temporary into the detached model targets once.

The rank-local rows of the fused temporary are split per head and copied, with a cast to the
dtype of the native projections, into the local shards of the key and value projections.

**Raises:**

* `RuntimeError`: If the part has already been finished.

```python
class nemo_automodel.components.models.ernie5_5.checkpoint_io.MhcDcpLoadPart(
    fn: torch.distributed.tensor.DTensor,
    base: torch.distributed.tensor.DTensor,
    scale: torch.distributed.tensor.DTensor,
    streams: int,
    hidden: int,
    hf_prefix: str
)
```

Load the HF projection and bias plus three one-element scale tensors.

The projection and bias destinations alias model storage. The checkpoint stores the scale as three
one-element tensors, which cannot alias a sharded vector of three, so they are loaded into replicated
temporaries and copied into the rank-local scale shard by `finish`.

Only one-dimensional `Shard(0)` parameters are supported.

**`_alpha_names`** `= ('alpha_pre', 'alpha_post', 'alpha_res')`

---

**`_alphas`** `= []`

---

**`_scale`** `= scale.to_local().detach()`

---

**`targets`**

Hugging Face names mapped to DCP destinations: `mapping_proj.weight`, the transposed
view of `fn` with global shape \[streams \* hidden, mix]; `bias` with global shape \[mix];
and `alpha_pre`, `alpha_post` and `alpha_res`, replicated FP32 temporaries of shape \[1].

---

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.MhcDcpLoadPart.finish() -> None
```

Install the loaded alpha values in the local scale shard once.

**Raises:**

* `RuntimeError`: If the part has already been finished.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._decoder_export_part(
    state: collections.abc.Mapping[str, torch.Tensor],
    config: nemo_automodel.components.models.ernie5_5.config.Ernie5_5Config,
    layer: nemo_automodel.components.models.ernie5_5.config.Ernie5_5LayerPlan
) -> dict[str, torch.Tensor]
```

Return the released tensors of one sharded decoder layer for a distributed save.

All ranks of the meshes must call this function in the same order. The per-expert names differ between
the ranks of the `ep` mesh dimension.

**Parameters:**

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

Exactly the materialized tensors of one decoder block, named relative to it with the module
names `mlp` (dense) or `moe` (MoE) for the feed-forward. The two norm weights, the attention
tensors other than the split K/V projections, the dense projections and the non-expert MoE
tensors may have any shape and placement and are exported as they are.
`attn_hc.&#123;fn,base,scale&#125;` and `ffn_hc.&#123;fn,base,scale&#125;` follow `mhc_hf_export_views`;
`moe.experts.gate_and_up_projs` and `moe.experts.down_projs` follow `expert_hf_dcp_views`;
`attention.k_b_proj` and `attention.v_b_proj` follow `merge_dsa_kv_for_hf`.

---

**`config`** `Ernie5_5Config`

Model configuration; supplies the stream count, the hidden size, the number and widths of the
routed experts and the DSA K/V dimensions.

---

**`layer`** `Ernie5_5LayerPlan`

Index and attention and feed-forward kinds of the layer.

---

**Returns:** `dict[str, torch.Tensor]`

`model.layers.&#123;index&#125;.*` names mapped to tensors in the released layouts: the tensors exported as

**Raises:**

* `ValueError`: If a state name is missing or unexpected, a tensor is not materialized, two results share
  a Hugging Face name or a component rejects its tensors, for example because the number of
  data-parallel ranks does not divide the number of DSA attention heads.
* `TypeError`: If an mHC, expert or K/V parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._decoder_layer_names(
    attention: typing.Literal['hca', 'dsa'],
    ffn: typing.Literal['dense', 'moe']
) -> tuple[dict[str, str], set[str]]
```

Return the native tensor names of one decoder layer, split by how they reach the released layout.

**Parameters:**

**`attention`** `Literal['hca', 'dsa']`

Attention kind of the layer.

---

**`ffn`** `Literal['dense', 'moe']`

Feed-forward kind of the layer.

---

**Returns:** `dict[str, str]`

Two collections of names relative to the decoder block. The first maps every tensor whose released

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._shard_range(
    size: int,
    shards: int,
    rank: int
) -> tuple[int, int]
```

Return the contiguous partition used by torch.chunk.

**Parameters:**

**`size`** `int`

Length of the sharded dimension.

---

**`shards`** `int`

Number of shards, i.e. the size of the mesh dimension that shards it.

---

**`rank`** `int`

Index of the shard, in `[0, shards)`.

---

**Returns:** `int`

Half-open `(start, end)` index range of shard `rank`. Trailing shards are empty when `size`

**Raises:**

* `ValueError`: If an argument is not an integer, `size` or `shards` is not positive, or `rank`
  is outside `[0, shards)`.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._validate_kv(
    key: torch.distributed.tensor.DTensor,
    value: torch.distributed.tensor.DTensor,
    heads: int,
    latent: int,
    key_channels: int,
    value_channels: int
) -> tuple[torch.Tensor, torch.Tensor]
```

Check the split K/V projections of one DSA layer and return this rank's shards.

The projections are sharded along their first axis over the data-parallel ranks, and every rank must hold
whole attention heads: the number of ranks of the mesh must divide the head count.

**Parameters:**

**`key`** `DTensor`

Materialized DTensor of global shape \[heads \* latent, key_channels] with placements
`(Shard(0),)`; BF16, FP16 or FP32.

---

**`value`** `DTensor`

Materialized DTensor of global shape \[heads \* value_channels, latent] on the same mesh and
device, with the same placements; BF16, FP16 or FP32.

---

**`heads`** `int`

Global number of attention heads, `hybrid_mla_num_attention_heads` of the configuration; a
multiple of the mesh size.

---

**`latent`** `int`

Latent width of the K/V projection.

---

**`key_channels`** `int`

Key rows per head in the fused matrix.

---

**`value_channels`** `int`

Value rows per head in the fused matrix.

---

**Returns:** `torch.Tensor`

The detached local shards, which alias the given storage: keys of shape

**Raises:**

* `ValueError`: If a dimension is invalid, the projections do not share one mesh that this rank belongs
  to, the number of ranks of the mesh does not divide the head count, or placements, shapes, dtypes
  or devices are not as described.
* `TypeError`: If a projection is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._validate_mhc(
    fn: torch.distributed.tensor.DTensor,
    base: torch.distributed.tensor.DTensor,
    scale: torch.distributed.tensor.DTensor,
    streams: int,
    hidden: int,
    hf_prefix: str
) -> None
```

Check the three parameters of one mHC unit before a distributed load or save.

**Parameters:**

**`fn`** `DTensor`

Materialized FP32 DTensor of global shape \[mix, streams \* hidden] with placements `(Shard(0),)`,
where `mix` is `(2 + streams) * streams`.

---

**`base`** `DTensor`

Materialized FP32 DTensor of global shape \[mix] on the same mesh and device, with the same
placements.

---

**`scale`** `DTensor`

Materialized FP32 DTensor of global shape \[3] on the same mesh and device, with the same
placements. Ranks beyond the third hold an empty shard.

---

**`streams`** `int`

Number of residual streams.

---

**`hidden`** `int`

Hidden size.

---

**`hf_prefix`** `str`

Hugging Face prefix of the unit, ending with a dot.

---

**Raises:**

* `ValueError`: If a dimension or the prefix is invalid, the parameters do not share one mesh that this rank
  belongs to, or placements, shapes, dtype or device are not as described.
* `TypeError`: If a parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.common_hf_dcp_views(
    state: collections.abc.Mapping[str, torch.Tensor],
    vocab: int,
    hidden: int,
    streams: int
) -> dict[str, torch.Tensor]
```

Return detached model-storage views in the eight released HF layouts.

**Parameters:**

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

Mapping that contains the eight native model-level tensors, named relative to the inner
model: `embed_tokens.weight` \[vocab, hidden], `lm_head.weight` \[vocab, hidden],
`norm.weight` \[hidden], `multimax.multimax_ranges` \[4], `multimax.multimax_ts` \[4],
`hyper_head.hc_fn` \[streams, streams \* hidden], `hyper_head.hc_base` \[streams] and
`hyper_head.hc_scale` \[1]. For a DTensor these are the global shapes; placements are not
inspected. Every tensor must be materialized and BF16, FP16 or FP32, and the hyper-head
tensors FP32. Other entries are ignored.

---

**`vocab`** `int`

Vocabulary size.

---

**`hidden`** `int`

Hidden size.

---

**`streams`** `int`

Number of residual streams.

---

**Returns:** `dict[str, torch.Tensor]`

Hugging Face names mapped to detached views that alias the given storage, so writing a view

**Raises:**

* `ValueError`: If a dimension is not a positive integer, a tensor is missing, not materialized, of
  another shape or of an unsupported dtype.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.expert_hf_dcp_views(
    gate_up: torch.distributed.tensor.DTensor,
    down: torch.distributed.tensor.DTensor,
    layer: int,
    experts: int,
    latent: int,
    intermediate: int
) -> dict[str, torch.Tensor]
```

Return rank-local HF w1/w2/w3 destinations aliasing expert storage.

Two layouts of the grouped expert tensors are accepted:

* `(Shard(1), Shard(0))` over `(ep_shard, ep)`: `ep` shards the expert axis and `ep_shard` the
  next axis. The resulting per-expert checkpoint tensors retain the `ep_shard` mesh and shard their HF
  column dimension.
* `(Shard(0),)` over `(ep,)`: every rank holds whole experts, as in a run with one data-parallel rank
  per expert group. The resulting per-expert checkpoint tensors are plain tensors of the rank that holds
  the expert.

A checkpoint load writes through the views and must run between optimizer steps; an export only reads
them. No caller may assume that all keys are present on every rank.

**Parameters:**

**`gate_up`** `DTensor`

Materialized DTensor of global shape \[experts, latent, 2 \* intermediate] in one of the two
layouts. `ep` shards the expert axis; `ep_shard`, when present, shards the latent axis. The
last axis holds the transposed gate projection followed by the transposed up projection.

---

**`down`** `DTensor`

Materialized DTensor of global shape \[experts, intermediate, latent] on the same mesh and
device, with the same placements and dtype. `ep` shards the expert axis; `ep_shard`, when
present, shards the intermediate axis. It must not share storage with `gate_up`.

---

**`layer`** `int`

Index of the decoder layer, used in the Hugging Face names.

---

**`experts`** `int`

Global number of routed experts.

---

**`latent`** `int`

Latent width of the expert projections.

---

**`intermediate`** `int`

Intermediate width of the expert projections.

---

**Returns:** `dict[str, torch.Tensor]`

For every expert held by this rank, `model.layers.&#123;layer&#125;.block_sparse_moe.experts.&#123;id&#125;.w1.weight`

**Raises:**

* `ValueError`: If a dimension is invalid, the layout is neither of the two accepted ones, the two
  tensors differ in mesh or placements, shapes, dtype or device are not as described, this rank
  is outside the mesh, a shard is empty or the tensors share storage.
* `TypeError`: If a parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.merge_dsa_kv_for_hf(
    key: torch.distributed.tensor.DTensor,
    value: torch.distributed.tensor.DTensor,
    heads: int,
    latent: int,
    key_channels: int,
    value_channels: int
) -> torch.distributed.tensor.DTensor
```

Merge the split key and value projections of one DSA layer into the released fused layout.

Only one-dimensional `Shard(0)` projections whose shards hold whole attention heads are supported: the
number of ranks of the mesh must divide the head count. Each rank merges its own heads; no data moves
between ranks.

**Parameters:**

**`key`** `DTensor`

Materialized DTensor of global shape \[heads \* latent, key_channels] with placements
`(Shard(0),)`; BF16, FP16 or FP32.

---

**`value`** `DTensor`

Materialized DTensor of global shape \[heads \* value_channels, latent] on the same mesh and
device, with the same placements and dtype.

---

**`heads`** `int`

Global number of attention heads, `hybrid_mla_num_attention_heads` of the configuration; a
multiple of the mesh size.

---

**`latent`** `int`

Latent width of the K/V projection.

---

**`key_channels`** `int`

Key rows per head in the fused matrix.

---

**`value_channels`** `int`

Value rows per head in the fused matrix.

---

**Returns:** `DTensor`

A newly allocated DTensor of global shape \[heads \* (key_channels + value_channels), latent] with

**Raises:**

* `ValueError`: If a dimension is invalid, the projections do not share one mesh that this rank belongs
  to, the number of ranks of the mesh does not divide the head count, or placements, shapes, dtypes
  or devices are not as described.
* `TypeError`: If a projection is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.mhc_hf_export_views(
    fn: torch.distributed.tensor.DTensor,
    base: torch.distributed.tensor.DTensor,
    scale: torch.distributed.tensor.DTensor,
    streams: int,
    hidden: int,
    hf_prefix: str
) -> dict[str, torch.distributed.tensor.DTensor]
```

Return the five released tensors of one mHC unit for a distributed save.

All ranks of the mesh must call this function in the same order: replicating the scale is a collective.

**Parameters:**

**`fn`** `DTensor`

Materialized FP32 DTensor of global shape \[mix, streams \* hidden] with placements `(Shard(0),)`,
where `mix` is `(2 + streams) * streams`.

---

**`base`** `DTensor`

Materialized FP32 DTensor of global shape \[mix] on the same mesh and device, with the same
placements.

---

**`scale`** `DTensor`

Materialized FP32 DTensor of global shape \[3] on the same mesh and device, with the same
placements. Ranks beyond the third hold an empty shard.

---

**`streams`** `int`

Number of residual streams.

---

**`hidden`** `int`

Hidden size.

---

**`hf_prefix`** `str`

Hugging Face prefix of the unit, ending with a dot.

---

**Returns:** `dict[str, DTensor]`

Hugging Face names mapped to DTensors on the same mesh: `mapping_proj.weight`, the transposed view of

**Raises:**

* `ValueError`: If a dimension or the prefix is invalid, the parameters do not share one mesh that this
  rank belongs to, or placements, shapes, dtype or device are not as described.
* `TypeError`: If a parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.model_hf_dcp_load_destinations(
    state: collections.abc.Mapping[str, torch.Tensor],
    config: nemo_automodel.components.models.ernie5_5.config.Ernie5_5Config
) -> tuple[dict[str, torch.Tensor], list[collections.abc.Callable[[], None]]]
```

Return the DCP destinations of a whole sharded model and the callbacks that complete the load.

Every layer's destinations are created before the read starts, and every layer owns its temporaries. The
caller must run all callbacks, in order, after the read and before the model is used, and must discard the
model after any failure.

**Parameters:**

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

Exactly the materialized native tensors of the model, named relative to the inner model: the
eight model-level tensors in the layouts of `common_hf_dcp_views` and, for every decoder layer,
`layers.&#123;index&#125;.*` with the module names `mlp` (dense) or `moe` (MoE) for the feed-forward.
The two norm weights, the attention tensors other than the split K/V projections, the dense
projections and the non-expert MoE tensors may have any shape and placement and are aliased as
they are. `attn_hc.&#123;fn,base,scale&#125;` and `ffn_hc.&#123;fn,base,scale&#125;` follow `MhcDcpLoadPart`;
`moe.experts.gate_and_up_projs` and `moe.experts.down_projs` follow `expert_hf_dcp_views`;
`attention.k_b_proj` and `attention.v_b_proj` follow `DsaKVDcpLoadPart`.

---

**`config`** `Ernie5_5Config`

Decoder-only model configuration with untied embedding and output head; supplies the layer
plan and the dimensions.

---

**Returns:** `dict[str, torch.Tensor]`

The destinations and the callbacks. The destinations map released Hugging Face names to tensors in the

**Raises:**

* `ValueError`: If the configuration has MTP layers or tied embeddings, a model-level tensor is missing, a
  layer has a missing or unexpected name, a name is outside the model-level tensors and the decoder
  layers, a tensor is not materialized, two destinations share a Hugging Face name or a component
  rejects its tensors, for example because the number of data-parallel ranks does not divide the
  number of DSA attention heads.
* `TypeError`: If an mHC, expert or K/V parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io.model_hf_distributed_export(
    state: collections.abc.Mapping[str, torch.Tensor],
    config: nemo_automodel.components.models.ernie5_5.config.Ernie5_5Config
) -> dict[str, torch.Tensor]
```

Return the released tensors of a whole sharded model for a distributed save.

All ranks must call this function in the same order and must discard the result after any failure. It does
not write files.

**Parameters:**

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

Exactly the materialized native tensors of the model, named relative to the inner model: the
eight model-level tensors in the layouts of `common_hf_dcp_views` and, for every decoder layer,
`layers.&#123;index&#125;.*` with the module names `mlp` (dense) or `moe` (MoE) for the feed-forward.
The two norm weights, the attention tensors other than the split K/V projections, the dense
projections and the non-expert MoE tensors may have any shape and placement and are exported as
they are. `attn_hc.&#123;fn,base,scale&#125;` and `ffn_hc.&#123;fn,base,scale&#125;` follow
`mhc_hf_export_views`; `moe.experts.gate_and_up_projs` and `moe.experts.down_projs` follow
`expert_hf_dcp_views`; `attention.k_b_proj` and `attention.v_b_proj` follow
`merge_dsa_kv_for_hf`.

---

**`config`** `Ernie5_5Config`

Model configuration without MTP layers; supplies the layer plan and the dimensions.

---

**Returns:** `dict[str, torch.Tensor]`

Released Hugging Face names mapped to tensors in the released layouts: the eight model-level tensors

**Raises:**

* `NotImplementedError`: If the configuration has MTP layers.
* `ValueError`: If a model-level tensor is missing, a layer has a missing or unexpected name, a name is
  outside the model-level tensors and the decoder layers, a tensor is not materialized, two results
  share a Hugging Face name or a component rejects its tensors, for example because the number of
  data-parallel ranks does not divide the number of DSA attention heads.
* `TypeError`: If an mHC, expert or K/V parameter is not a DTensor.

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._EXPERT_LAYOUTS = ((('ep_shard', 'ep'), (Shard(1), Shard(0))), (('ep',), (Shard(0),)))
```

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._FUSED_KV_TEMPORARY_DTYPE = torch.float32
```

```python
nemo_automodel.components.models.ernie5_5.checkpoint_io._MHC_UNITS = (('attn_hc', 'self_attention_hyper_connection'), ('ffn_hc', 'mlp_hyper_connectio...
```