> ## Documentation Index
> Fetch the complete documentation index at: https://khaos-ml.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Artifacts and export

> The manifest, the artifact directory and export_artifact.

An **artifact** is a directory the runtime can load. Training produces it and
`export_artifact` writes the part the runtime needs.

## Directory layout

```text theme={null}
<artifact>/
├── manifest.json        required: name, domain, version, files, metadata
├── model.onnx           required: the exported network
├── model.pt             PyTorch weights (not needed to serve)
├── metrics.json         test results and training history
├── train_config.json    settings used for training
├── README.md            model card
└── tokenizer/           only for text models (finance, record matching)
```

## `khaos.manifest.Manifest`

```python theme={null}
from khaos.manifest import Manifest
```

A dataclass describing an artifact.

| Field | Type | Default | Description |
| - | - | - | - |
| `name` | `str` | required | Artifact name, matching `khaos info`. |
| `vertical` | `str` | required | The domain subpackage (`"physics"`, `"chem"`, ...). The JSON key is named `vertical`. |
| `version` | `str` | `"v1"` | Release label. The first release of every artifact is `v1`. |
| `framework` | `str` | `"onnx"` | Only `onnx` is supported. |
| `files` | `dict[str, str]` | `{"model": "model.onnx"}` | Paths relative to the artifact directory. |
| `meta` | `dict` | `{}` | Anything the pipeline needs: normalization constants, labels, thresholds, vocabularies. |

| Method | Description |
| - | - |
| `Manifest.read(directory)` | Loads `manifest.json`. Raises `FileNotFoundError` if it is missing and `ValueError` if `name` or `vertical` is absent. |
| `manifest.write(directory)` | Writes `manifest.json` and returns its path. |

The `meta` of a trained artifact carries what is needed to use it. For example, `chem_logp`
stores `target_mean` and `target_std` (multiply the output by the standard deviation and add the
mean), the SMILES `tokenizer_vocab`, and the maximum length. `robo_failure_detection` stores its
calibrated `alarm_threshold`.

## `khaos.export.export_artifact`

```python theme={null}
export_artifact(model, name, out_dir, *, version="v1", meta=None, opset=17) -> Path
```

Exports a PyTorch model to `out_dir` as `model.onnx` plus `manifest.json`, and returns the
directory.

**model** `torch.nn.Module` *required*

A model from `khaos.<domain>.models`, or any module that declares the attributes below.

**name** `str` *required*

The artifact name. The domain is looked up in `khaos.registry.ARTIFACTS`.

**version** `str` (default: v1)

Release label written to the manifest.

**meta** `dict`

Extra entries merged into `manifest.meta`.

**opset** `int` (default: 17)

ONNX opset used for the export.

The export reads these attributes from the model:

| Attribute | Required | Meaning |
| - | - | - |
| `input_names` | yes | Names of the forward arguments, in order. |
| `output_names` | yes | Names of the outputs. |
| `example_inputs()` | yes | Returns a tuple of tensors used to trace the model. |
| `dynamic_axes` | no | `{name: {axis: label}}`. Defaults to a dynamic batch axis on every input and output. |
| `manifest_meta()` | no | Returns a dict added to `manifest.meta`. |

The manifest always records `architecture`, `inputs` and `outputs` in `meta`.

```python theme={null}
from khaos.export import export_artifact
from khaos.modeling import build

model = build("tele_sensor_vibration")
# ... train ...
export_artifact(model, "tele_sensor_vibration", "./my-artifact", version="v1")
```

See [Bringing your own weights](https://khaos-ml.mintlify.site/usage/training-handoff.md) for the full training handoff.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.