← Instruments

Julia trains,
Rust infers.

The model is defined twice — once in Julia for training, once in Rust for real-time inference — and the two are kept equal by a file format and tests, not by a shared runtime. Julia writes a model file; Rust reads it, checks every tensor against the contract, and runs it on the audio thread.

  • safetensors + manifest.toml
  • golden vectors
  • no runtime, no allocations
Julia fit · train parallel scans export Rust load · check per-sample recurrence audio thread model file golden vectors · parity in CI DAW ← CLAP 48 kHz · 128 samples
Two languages, one contract · at runtime they share nothing but the file — and the proof that they agree
The hand-off

One file, checked both ways.

safetensors: a JSON header plus raw tensor bytes — no pickle, no code execution, memory-mappable. The manifest beside it carries the architecture version, the hyperparameters, the training commit, the dataset hash, and the licence and sources of the data the model was fitted from. Every version of this shape is on disk in the repository:

models/<instrument>/<version>/
models/piano/1.2.0/
  manifest.toml      # architecture name + version, hyperparameters, sample-rate
                     # handling, tensor list with shapes, training commit,
                     # dataset hash, licence + sources
  model.safetensors  # all weights, f32, little-endian, named "layers.0.A_log"
  golden.safetensors # inputs and expected outputs, for the parity tests
  LICENSE
  ATTRIBUTION.md     # the data this piano was fitted from, named on the box

The contract

  • Names and shapes. Every tensor's presence, shape and dtype is checked against what the architecture version expects — anything else is refused at load.
  • Versioned. The manifest names the architecture version; a Rust change that changes outputs bumps it.
  • Index-compatible. A Julia A[i, j] is A[i-1][j-1] in Rust — the shape is kept, the bytes permuted, tested against hand-checked matrices.
  • Licensed. Export refuses a manifest without licence and sources; attribution ships with the model.
The two sides

Built for its job, on both ends.

Julia gets the tools that make fitting pleasant — autodiff, GPU, a REPL. Rust gets the obligations of real time — no allocation, no locks, no surprises. Neither drags the other's world across the seam.

Julia · training/

Fitting, not guessing

Per-note analysis pulls partials, decays and beat rates out of each recorded note; a differentiable model of the instrument is fitted to them with gradient descent — decay curves across the whole keyboard, hammer force per velocity, unison detunes.

Lux, Zygote, Enzyme

Explicit parameters as a nested NamedTuple: walked into named tensors on export without a graph trace. Gradients by Zygote or Enzyme; CUDA and Reactant when the fit wants a GPU.

The reference recurrence

Training uses the fast parallel scan; export uses the same per-sample loop Rust will run. Golden vectors come from the recurrence, so scan-vs-recurrence mismatches are caught before Rust is involved.

Rust · crates/dsp

Hand-written inference

No ONNX, no runtime: an SSM at inference is one recurrence per sample plus a few nonlinearities. Hand-written Rust with preallocated f32 arrays is shorter than any runtime integration — and SIMD-vectorises.

Allocation-free, by construction

The Processor trait forbids allocation, locks and I/O in event/render. Weights and state are laid out in initialize; the audio thread only multiplies.

The loader checks everything

Tensor names, shapes and dtypes are the contract: the Rust loader verifies every tensor against what the architecture version expects and refuses anything else.

Sample rates

Physics has no sample rate — so it travels without one.

A model trained at 48 kHz and run at 96 kHz is wrong unless its time constants are rescaled. Continuous-time state-space models solve this at the root: what is exported is continuous, and the discrete step happens where the host's rate is known.

  1. Export

    Continuous time

    Λ, B, C, D and log Δ leave Julia as learned — in continuous time, at the training rate.

  2. Load

    Discretise at the host's rate

    In Rust, at initialize: Ā = exp(ΛΔ′), B̄ = Λ⁻¹(Ā − I)B, with Δ′ = Δ · f_train / f_host.

  3. Result

    Trained at 48, correct at 96

    44.1, 48, 88.2, 96, 192 kHz: the same instrument, not a resampled one. Time constants are physics, not baked into the weights.

The proof

Two languages agree because they are made to.

Nothing about the parity is hoped for. Each of these is a test that runs before anything ships.

  • Golden vectors: the same inputs pushed through Julia and through Rust give the same outputs, bit for bit, in CI
  • The column-major/row-major seam is tested against the raw bytes of hand-checked matrices
  • A model file without licence and sources is refused at export time
  • Sample-rate correctness by construction: continuous parameters, discretised at load
  • clap-validator runs over every bundled plugin before it ships
  • The in-process CLAP host exercises the plugin in tests: params, state, ports, GUI
Go deeper

The decisions, with their reasons.

Every choice above is an architecture decision record in the documentation — CLAP first with clack, the DSP core free of plugin types, Julia trains and Rust infers over safetensors, egui for the editor, licences named on every model — each with the options it beat.