Phasic← Overview

Adding a model

Adding a model is a repeatable path, not an integration project. Each model is integrated in isolation, depends on no previous model’s setup, and at most extends the shared contract rather than working around it.

A model that fits the existing contract needs no changes to Phasic.

The shape of the work

0. Training happens elsewhere

Producing the weights belongs in a separate repository, outside Phasic. It needs PyTorch and the upstream project’s own model code — neither of which Phasic has or wants.

This boundary is the point. Phasic consumes a directory; how that directory was produced is not its concern.

1. Export to ONNX

An export script loads the upstream code and checkpoint, wraps the model for shape-agnostic ONNX export, and writes models/<name>/.

The exported graph is a black box to Phasic, so anything Phasic’s pipeline cannot express must be baked into the graph — model-specific preprocessing, output reshaping, anything idiosyncratic.

Export with dynamic axes for batch, window count, and — for a set-based model — channel count. A graph with a frozen batch size cannot be run in batches.

Self-verification is mandatory. After exporting, run every graph under ONNX Runtime on a reference recording and compare elementwise against PyTorch. A mismatch fails the export. The manifest is only trustworthy because this check passed, and the result is recorded in the manifest so the interface can show it.

2. Write the manifest

Describe the contract: rate, window geometry, channel groups, output. See the manifest reference.

Derive the values from the upstream data preparation step, not just the training loader. Data prep defines the resampling, montage and normalization that constitute the parity target — get these from the code that produced the training tensors.

Record _license and _source. A restrictive licence is something users are obliged to know, and it travels with the model only if you write it here.

3. Check it fits

If the model needs something the contract cannot express, extend a pure layer once, with tests — never special-case the runtime for one model. An extension made properly is reusable by every later model; a special case is a debt paid by the next person.

4. Drop it in

Place models/<name>/ where Phasic can find it. It loads with no rebuild.

5. Validate

A validation script runs the PyTorch reference and Phasic’s pipeline on a real annotated recording, and keeps two questions apart:

Port parity — do the two pipelines agree? They should agree almost exactly. Any gap is a bug in the port.

Model quality — how good is the model against ground truth? A separate question, with a metric appropriate to the task.

Conflating these makes a poor result uninterpretable: you cannot tell a faithful port of a mediocre model from a broken port of a good one. See Correctness for how the shipped models are validated.

6. Benchmark

Confirm CPU throughput is acceptable for the recording lengths you care about.

Checklist

  • External repository produces the final checkpoint
  • Upstream data-prep read, and the parity target understood
  • Export script: shape-agnostic, preprocessing baked in, self-verified against PyTorch
  • manifest.json written, with _license and _source
  • Contract fits — or one pure layer extended, with tests
  • Model directory loads with no Rust change
  • Validation script proves port parity; quality reported separately
  • Benchmark confirms throughput

Practical notes

Opset versions matter. A spectrogram tokenizer using torch.stft needs opset 17 or newer. Some models require a newer PyTorch than upstream pins, because older exporters lack symbolic functions for operations on the attention path.

Unknown _-prefixed manifest keys are ignored, so an exporter may record whatever provenance it likes without breaking compatibility.