# helia_edge.importers.mapping

Declarative weight mappings from a source file to a Keras model; importable without Keras.

## helia_edge.importers.mapping.SHA256

`constant` · `python`

```python
SHA256 = Annotated[str, Field(pattern='^[0-9a-f]{64}$')]
```

Source: `helia_edge/importers/mapping.py:10`

## helia_edge.importers.mapping.Transform

`attribute` · `python`

```python
Transform = Annotated[Transpose | Reshape | GateReorder | Split | SumParts, Field(discriminator='kind')]
```

Source: `helia_edge/importers/mapping.py:103`

## helia_edge.importers.mapping.Transpose

`class` · `python`

```python
Transpose()
```

Permute the axes, as ``numpy.transpose``.

Source: `helia_edge/importers/mapping.py:13`

### helia_edge.importers.mapping.Transpose.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:16`

### helia_edge.importers.mapping.Transpose.kind

`attribute` · `python`

```python
kind: Literal['transpose'] = 'transpose'
```

Source: `helia_edge/importers/mapping.py:18`

### helia_edge.importers.mapping.Transpose.perm

`attribute` · `python`

```python
perm: tuple[int, ...]
```

Source: `helia_edge/importers/mapping.py:19`

### helia_edge.importers.mapping.Transpose.apply

`method` · `python`

```python
apply(x: npt.NDArray) -> npt.NDArray
```

Source: `helia_edge/importers/mapping.py:21`

## helia_edge.importers.mapping.Reshape

`class` · `python`

```python
Reshape()
```

Reshape in C order, as ``numpy.reshape``.

Source: `helia_edge/importers/mapping.py:25`

### helia_edge.importers.mapping.Reshape.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:28`

### helia_edge.importers.mapping.Reshape.kind

`attribute` · `python`

```python
kind: Literal['reshape'] = 'reshape'
```

Source: `helia_edge/importers/mapping.py:30`

### helia_edge.importers.mapping.Reshape.shape

`attribute` · `python`

```python
shape: tuple[int, ...]
```

Source: `helia_edge/importers/mapping.py:31`

### helia_edge.importers.mapping.Reshape.apply

`method` · `python`

```python
apply(x: npt.NDArray) -> npt.NDArray
```

Source: `helia_edge/importers/mapping.py:33`

## helia_edge.importers.mapping.GateReorder

`class` · `python`

```python
GateReorder()
```

Reorder equal gate blocks along ``axis``, for example ONNX LSTM ``"iofc"`` to Keras ``"ifco"``.

``source`` and ``target`` name the same gates, one letter each, in their stored orders.

Source: `helia_edge/importers/mapping.py:37`

### helia_edge.importers.mapping.GateReorder.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:43`

### helia_edge.importers.mapping.GateReorder.kind

`attribute` · `python`

```python
kind: Literal['gate_reorder'] = 'gate_reorder'
```

Source: `helia_edge/importers/mapping.py:45`

### helia_edge.importers.mapping.GateReorder.source

`attribute` · `python`

```python
source: str
```

Source: `helia_edge/importers/mapping.py:46`

### helia_edge.importers.mapping.GateReorder.target

`attribute` · `python`

```python
target: str
```

Source: `helia_edge/importers/mapping.py:47`

### helia_edge.importers.mapping.GateReorder.axis

`attribute` · `python`

```python
axis: int = 0
```

Source: `helia_edge/importers/mapping.py:48`

### helia_edge.importers.mapping.GateReorder.apply

`method` · `python`

```python
apply(x: npt.NDArray) -> npt.NDArray
```

Source: `helia_edge/importers/mapping.py:56`

## helia_edge.importers.mapping.Split

`class` · `python`

```python
Split()
```

Take part ``index`` of ``parts`` equal parts along ``axis``.

A source tensor may feed several rows only through splits that together use every part once.

Source: `helia_edge/importers/mapping.py:63`

### helia_edge.importers.mapping.Split.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:69`

### helia_edge.importers.mapping.Split.kind

`attribute` · `python`

```python
kind: Literal['split'] = 'split'
```

Source: `helia_edge/importers/mapping.py:71`

### helia_edge.importers.mapping.Split.axis

`attribute` · `python`

```python
axis: int
```

Source: `helia_edge/importers/mapping.py:72`

### helia_edge.importers.mapping.Split.parts

`attribute` · `python`

```python
parts: int = Field(ge=2)
```

Source: `helia_edge/importers/mapping.py:73`

### helia_edge.importers.mapping.Split.index

`attribute` · `python`

```python
index: int = Field(ge=0)
```

Source: `helia_edge/importers/mapping.py:74`

### helia_edge.importers.mapping.Split.apply

`method` · `python`

```python
apply(x: npt.NDArray) -> npt.NDArray
```

Source: `helia_edge/importers/mapping.py:82`

## helia_edge.importers.mapping.SumParts

`class` · `python`

```python
SumParts()
```

Add ``parts`` equal parts along ``axis``, for example an ONNX LSTM's input and recurrent biases.

Source: `helia_edge/importers/mapping.py:88`

### helia_edge.importers.mapping.SumParts.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:91`

### helia_edge.importers.mapping.SumParts.kind

`attribute` · `python`

```python
kind: Literal['sum_parts'] = 'sum_parts'
```

Source: `helia_edge/importers/mapping.py:93`

### helia_edge.importers.mapping.SumParts.axis

`attribute` · `python`

```python
axis: int
```

Source: `helia_edge/importers/mapping.py:94`

### helia_edge.importers.mapping.SumParts.parts

`attribute` · `python`

```python
parts: int = Field(ge=2)
```

Source: `helia_edge/importers/mapping.py:95`

### helia_edge.importers.mapping.SumParts.apply

`method` · `python`

```python
apply(x: npt.NDArray) -> npt.NDArray
```

Source: `helia_edge/importers/mapping.py:97`

## helia_edge.importers.mapping.WeightRow

`class` · `python`

```python
WeightRow()
```

One model weight: its source tensors, how they combine, and the transforms to its layout.

Source: `helia_edge/importers/mapping.py:106`

### helia_edge.importers.mapping.WeightRow.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:123`

### helia_edge.importers.mapping.WeightRow.sources

`attribute` · `python`

```python
sources: tuple[str, ...] = Field(min_length=1)
```

Source tensor names. Several sources are combined by ``combine`` before ``transforms``.

Source: `helia_edge/importers/mapping.py:125`

### helia_edge.importers.mapping.WeightRow.combine

`attribute` · `python`

```python
combine: Literal['sum', 'concat'] | None = None
```

``sum`` (for example an LSTM's input and recurrent biases) or ``concat`` along
``concat_axis``; required with several sources.

Source: `helia_edge/importers/mapping.py:126`

### helia_edge.importers.mapping.WeightRow.concat_axis

`attribute` · `python`

```python
concat_axis: int = 0
```

Source: `helia_edge/importers/mapping.py:127`

### helia_edge.importers.mapping.WeightRow.transforms

`attribute` · `python`

```python
transforms: tuple[Transform, ...] = ()
```

Applied in order to the (combined) source. A ``Split`` may only come first and
only with one source.

Source: `helia_edge/importers/mapping.py:128`

### helia_edge.importers.mapping.WeightRow.layer

`attribute` · `python`

```python
layer: str
```

Name of the Keras layer holding the weight (``outer/inner`` for a nested model).

Source: `helia_edge/importers/mapping.py:129`

### helia_edge.importers.mapping.WeightRow.weight

`attribute` · `python`

```python
weight: str
```

Name of the weight within the layer, such as ``kernel`` or ``bias``, or its path inside a
composite layer, such as ``query/kernel`` in a ``MultiHeadAttention``.

Source: `helia_edge/importers/mapping.py:130`

### helia_edge.importers.mapping.WeightRow.source_shape

`attribute` · `python`

```python
source_shape: tuple[Annotated[int, Field(ge=0)], ...] | None = None
```

The shape every source tensor must have, checked before ``combine`` and
``transforms``; None checks only the final shape. A ``Reshape`` alone cannot tell a
transposed source of the same size from the right one.

Source: `helia_edge/importers/mapping.py:131`

### helia_edge.importers.mapping.WeightRow.split

`attribute` · `python`

```python
split: Split | None
```

Source: `helia_edge/importers/mapping.py:147`

### helia_edge.importers.mapping.WeightRow.value

`method` · `python`

```python
value(tensors: dict[str, npt.NDArray]) -> npt.NDArray
```

This row's weight value from the source tensors.

Source: `helia_edge/importers/mapping.py:151`

## helia_edge.importers.mapping.SourceFormat

`class` · `python`

```python
SourceFormat()
```

File formats ``import_weights`` reads (see ``helia_edge.importers.readers``).

Source: `helia_edge/importers/mapping.py:165`

### helia_edge.importers.mapping.SourceFormat.ONNX

`constant` · `python`

```python
ONNX = 'onnx'
```

Source: `helia_edge/importers/mapping.py:168`

### helia_edge.importers.mapping.SourceFormat.SAFETENSORS

`constant` · `python`

```python
SAFETENSORS = 'safetensors'
```

Source: `helia_edge/importers/mapping.py:169`

### helia_edge.importers.mapping.SourceFormat.TORCH

`constant` · `python`

```python
TORCH = 'torch'
```

Source: `helia_edge/importers/mapping.py:170`

## helia_edge.importers.mapping.SourcePin

`class` · `python`

```python
SourcePin()
```

The one source file a mapping was written for.

Source: `helia_edge/importers/mapping.py:173`

### helia_edge.importers.mapping.SourcePin.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:176`

### helia_edge.importers.mapping.SourcePin.uri

`attribute` · `python`

```python
uri: str
```

Source: `helia_edge/importers/mapping.py:178`

### helia_edge.importers.mapping.SourcePin.sha256

`attribute` · `python`

```python
sha256: SHA256
```

Source: `helia_edge/importers/mapping.py:179`

### helia_edge.importers.mapping.SourcePin.format

`attribute` · `python`

```python
format: SourceFormat
```

Source: `helia_edge/importers/mapping.py:180`

### helia_edge.importers.mapping.SourcePin.note

`attribute` · `python`

```python
note: str = ''
```

Source: `helia_edge/importers/mapping.py:181`

## helia_edge.importers.mapping.WeightMapping

`class` · `python`

```python
WeightMapping()
```

Every weight of one architecture, from one source format.

Source: `helia_edge/importers/mapping.py:184`

### helia_edge.importers.mapping.WeightMapping.model_config

`attribute` · `python`

```python
model_config = ConfigDict(frozen=True, extra='forbid')
```

Source: `helia_edge/importers/mapping.py:194`

### helia_edge.importers.mapping.WeightMapping.name

`attribute` · `python`

```python
name: str
```

Mapping name.

Source: `helia_edge/importers/mapping.py:196`

### helia_edge.importers.mapping.WeightMapping.source

`attribute` · `python`

```python
source: SourcePin
```

The pinned source file and its format.

Source: `helia_edge/importers/mapping.py:197`

### helia_edge.importers.mapping.WeightMapping.rows

`attribute` · `python`

```python
rows: tuple[WeightRow, ...] = Field(min_length=1)
```

One row per model weight.

Source: `helia_edge/importers/mapping.py:198`

### helia_edge.importers.mapping.WeightMapping.unused

`attribute` · `python`

```python
unused: tuple[str, ...] = ()
```

Source tensors deliberately not imported (every other one must be used).

Source: `helia_edge/importers/mapping.py:199`
