Skip to main content

Life of an artifact

Your training code
khaos.modeling.build(“<artifact>”), then train however you like
↓
export_artifact
manifest.json and model.onnx
↓
Hugging Face Hub, or a local directory
<org>/<artifact>
↓
khaos.load() or khaos serve
adapter, then ONNX Runtime, then a result container
  1. Build. khaos.modeling.build("<artifact>") gives the architecture for an artifact, defined in khaos/<domain>/models/.
  2. Train. Your own loop, in your own environment. Khaos does not train.
  3. Export. export_artifact writes manifest.json and model.onnx.
  4. Publish. Push the directory to the Hugging Face Hub, or keep it local.
  5. Run. khaos.load() and khaos serve read the manifest, find the registered pipeline for that artifact, and run it on ONNX Runtime.

Design

  • Code and weights are separate. This repository holds the runtime and the architectures. Weights are published to the Hugging Face Hub and cached locally.
  • ONNX is the contract. Whatever you train with, the runtime only sees an ONNX file and a manifest. The architectures are written to export cleanly with dynamic batch and length, and the tests check that ONNX Runtime matches PyTorch.
  • One subpackage per domain. Each holds its adapter, containers and architectures, so optional dependencies stay isolated behind extras.
  • Domain-owned containers. Each domain defines its own result types. There is deliberately no shared base class: a filing, a field grid and a trajectory have nothing meaningful in common.
  • Registry-driven loading. @register("artifact_name") binds a pipeline class to a name; load() imports only the domain it needs.
  • Light runtime, heavy training. Serving needs ONNX Runtime and FastAPI. PyTorch and transformers live behind the train extra.
  • Local-first. Inference runs on the user’s machine through ONNX Runtime.
Structure was informed by spaCy: library and models are distributed separately, and components are resolved through a registry.

Adding a pipeline

A pipeline connects an exported model to the rest of the runtime. Subclass OnnxPipeline, turn raw input into named arrays, and build the domain’s container from the outputs:
Once registered, the name works everywhere: khaos.load("pde_darcy_flow_2d"), khaos serve pde_darcy_flow_2d, and khaos download pde_darcy_flow_2d.