Skip to content

Releases

v0.5.0 — models start settled, Linear and Sequential, nine activations

Choose a tag to compare

@OpenSauce OpenSauce released this 01 Dec 14:05
e723f67

The largest release so far. Models now start settled and match NAM Core from the first sample, two more architectures and five more activations load, and a batch of files that used to load wrongly, or bring the process down, are handled. It is a breaking release: read Breaking before upgrading.

Breaking

The parsed types are #[non_exhaustive] (#81). Error, ModelConfig, ActivationSpec, GatingMode, NamModel and every config struct inside it. Downstream code has to:

  • give a match on one of the enums a wildcard arm;
  • end a pattern on one of the structs, or on ActivationSpec::Named, in ..;
  • get config values by parsing a .nam file. A struct literal no longer compiles outside the crate.

Field access is unchanged. This is what lets a new architecture, error or config key arrive in a 0.5.x from now on, as Linear and Sequential would not have been able to.

Model::from_nam and Model::reset now prewarm (#70). A model comes back settled against silence, as NAM Core's does, so the first block is clean and the output matches NAM Core from the first sample. Compared with 0.4.1 this changes the samples a model used to spend on its startup transient: the receptive field for a WaveNet, and up to about half a second for an LSTM whose stored state is not already settled. Model::from_nam_without_prewarm and Model::reset_without_prewarm give the zero-filled start that 0.4.1 gave. reset does not run the model again: it copies back the state captured at load, and stays allocation-free.

File versions are checked (#83). A file whose version is outside 0.5.0 to 0.7.x, the range NAM Core loads, fails with the new Error::UnsupportedVersion. Until now such a file loaded if its config happened to parse.

MSRV is 1.77 (#80). The 1.71 that 0.4.1 declared stopped being true when thiserror raised its own floor.

Added

  • Linear (#87): NAM's impulse response as a model. Mono, convolved directly at the file's own sample rate. It also runs as a container submodel and as a WaveNet's condition_dsp.
  • Sequential (#91): complete models in series in one file, such as an amp model followed by an impulse response. A chain always starts settled.
  • Five more activations (#58, thanks to @JustinLakra): Hardtanh, Softsign, SiLU, Hardswish and Fasttanh, as a layer's activation, as a gate's, and in the post-stack head. That makes nine of NAM Core's eleven.
  • Prewarm control (#70): Model::prewarm(), Model::prewarm_samples(), and the two opt-outs above. WaveNet and Lstm gain prewarm and prewarm_samples too.
  • Loaders for a file already in memory (#74): NamModel::from_slice(&[u8]) and NamModel::from_reader(impl Read).
  • Slimmable controls (#76): size_breakpoints() for snapping a dial to the submodel boundaries, and select_and_reset() / set_slim_size_and_reset(), which reset the incoming submodel before it takes over, as NAM Core does. select and set_slim_size are unchanged.
  • head_dilation (#84) on a layer array's head, which NAM Core v0.6.0 reads.

Performance

The LSTM is faster again (#96, thanks to @sreichholf): the cell is vectorized, and process_buffer dispatches to an AVX2 build at run time, as the WaveNet already did. Output is bit-identical to before.

LSTM, process_buffer, µs/sample 0.4.1 0.5.0
3 × 18 (trained) 1.41 0.80
2 × 16 (trained) 0.93 0.36
1 × 8 0.26 0.09

128-sample blocks on a 2.1 GHz Xeon cloud vCPU. process_sample gains too.

The repository also has a benchmark against NAM Core itself on the same models, input and blocks (#93, also @sreichholf): tests/oracle/bench.sh.

Fixed

Wrong output with no error:

  • layer1x1_post_film was applied only under BLENDED gating. It is now applied under every gating mode, as the trainer and NAM Core v0.6.0 do (#69).
  • A file that set head_dilation above 1 ran as if it were 1 (#84).
  • A layer array using the older gated key together with a secondary_activation ran that activation as the gate, where NAM Core always uses a Sigmoid there (#97).

Loading:

  • A crafted .nam could panic or abort the whole process in Model::from_nam: an oversized dilation, a convolution with no channels, an LSTM with weightless layers, layer arrays that do not fit together. These now return Error::ConfigTooLarge or Error::UnsupportedFeature before anything is allocated (#77).
  • A WaveNet whose condition_dsp is at another sample rate used to load and run the nested model at the wrong rate. It is refused, as NAM Core refuses it (#89).
  • secondary_activation is read only where NAM Core reads it: on a layer that gating_mode gates. An ungated layer with an empty or unknown name there now loads; a gated layer with null there is now refused (#97).
  • An LSTM stating "sample_rate": -1, NAM Core's value for an unknown rate, is prewarmed as one that states none (#92).
  • On 32-bit x86 without SSE2 the fast tanh and sigmoid were wrong by up to 0.17. Those targets now use std's (#82).

Compatibility

Output against 0.4.1. The opening samples after a load or a reset differ, because the model now starts settled. After that the output is the same as 0.4.1's, except for files that one of the fixes above applies to.

Parity. The claim is now two bounds against the reference, both from the first sample: an error-to-signal ratio of at most 1e-10, and no sample off by more than 1e-4 times the larger of 1 and the reference's peak (#78). Over 109 real captures the worst error-to-signal ratio is 2.5e-12 and the worst sample is 1.3e-5 off. The C++ oracle is NAM Core v0.6.0 (#67), and its output is now recorded at full f32 precision (#75).

Which files load. Stricter in several places, as above: file versions, a condition_dsp at another sample rate, structurally inconsistent configs, and a null gate activation on a gated layer. That includes one shape the Python trainer exports and NAM Core also refuses, a condition_dsp nested two deep with a rate stated on the first only. Looser in one: junk in secondary_activation on an ungated layer.

Platforms. CI now runs the tests on aarch64 as well as x86-64 (#82), and checks that the library builds on the MSRV (#80).

Not supported yet: the ConvNet architecture, the LeakyHardtanh and PReLU activations, mixed gating modes within one layer array, and multi-channel input. A file that needs one of these fails at load with an error that names it. #33 tracks the remaining gap to NAM Core.

The real-time-safety contract is unchanged: processing, reset and slimmable switching allocate nothing, take no locks and make no system calls, on every architecture.

v0.4.1 — a much faster block path, and an LSTM audio-thread panic fixed

Choose a tag to compare

@OpenSauce OpenSauce released this 30 Nov 00:07
3934e70

A performance release: the block path is roughly 3× faster on WaveNet and 2× faster on LSTM, with no API change. It also fixes a panic on the audio thread.

Performance

process_buffer is much faster on both architectures (#59, thanks to @sreichholf):

Model (512-sample blocks) 0.4.0 0.4.1
WaveNet, standard ~1.02 ms ~0.34 ms
LSTM, standard ~0.65 ms ~0.31 ms

Measured with cargo bench on one core of a Ryzen 7 9800X3D (x86-64, AVX2). Numbers vary with CPU and model size.

What changed underneath:

  • the block conv keeps one linear history row per input channel and computes outputs in register-sized tiles
  • tanh and sigmoid are vectorizable approximations
  • the LSTM stores its gate matrix transposed
  • on x86-64, the conv, activation and gating loops dispatch at run time to an AVX2 build when the CPU has it; no compiler flags are needed

process_sample on WaveNet is a few percent slower. Prefer whole blocks.

Fixed

  • An LSTM model with input_size != 1 used to construct successfully and then panic on the audio thread. It is now rejected at construction with Error::UnsupportedFeature (#56).
  • A .nam file with an architecture this crate does not implement is now reported as an unsupported architecture instead of a JSON error (#50).

Added

Model gains forwarding accessors, so a host no longer needs to keep the NamModel around for them (#51): expected_sample_rate(), loudness(), input_level_dbu(), output_level_dbu().

Compatibility

No breaking changes; nothing public was removed or changed.

Audio output is not bit-identical to 0.4.0, because of the new tanh and sigmoid. It moves by under 1e-6 on the fixture models driven at 0 dBFS, and the measured error against the reference is unchanged, well inside the 1e-5 parity tolerance. The real-time-safety contract is unaffected.

The declared MSRV is lowered from 1.74 to 1.71 (#53).

The aarch64 (NEON-width) path is not exercised by CI.

v0.4.0 — descriptive metadata, cab detection, and a loudness unit correction

Choose a tag to compare

@OpenSauce OpenSauce released this 27 Jul 20:00
97fba1e

Typed access to the rest of a .nam file's metadata block, plus a correction to what loudness has always meant.

⚠️ loudness() is dBFS RMS, not LUFS

This is the item that silently changes behaviour, and it needs no code change to hit you.

Metadata::loudness / NamModel::loudness() were documented as "perceived loudness … in LUFS" in 0.2.0 and 0.3.0. That was wrong. NAM's trainer computes

loudness = 20·log10(sqrt(mean(y²)))

against a standardized input — plain RMS in dBFS, with no K-weighting and no gating. It is not a perceptual measure and not ITU-R BS.1770.

If you built loudness normalization on loudness() believing it was LUFS, you have been applying a wrong gain, and two models with the same loudness but different spectra will not match perceptually. The fix here is documentation only — your code still compiles and still misbehaves. Nothing is deprecated or renamed, so nothing will warn you.

No yank: the number itself was always correct and unchanged, only its description was wrong. But if you consume it, re-read what you do with it.

Added

metadata_typed() now returns the whole descriptive block, not just the three calibration numbers:

name, modeled_by, gear_make, gear_model, gear_type, tone_type, trainer, date (new Date type), gain, and the trainer's raw training blob (left untyped — its shape is trainer- and version-specific).

Metadata::includes_cab() / NamModel::includes_cab() answer whether a capture already contains a speaker cabinet, which decides whether an impulse response after the model would be a second one:

match model.includes_cab() {
    Some(true)  => // cab is baked in — don't add an IR
    Some(false) => // no cab — an IR belongs after this
    None        => // unknown — leave the signal chain alone
}

gear_type is a String, not an enum: NAM's trainer and TONE3000 use overlapping-but-different vocabularies, and TONE3000 has already deprecated values (full-rig, ir) that exist in files on disk, so an enum over either set would reject real files. includes_cab() normalizes case, whitespace and - vs _ across both, and returns None rather than guessing at anything it doesn't recognize.

Note it reports what the file claims. gear_type is author-supplied and captures do mislabel themselves — treat the answer as a default to offer the user, not a fact to reroute audio on silently.

Fixed

Metadata fields are now parsed leniently, one at a time. metadata_typed() converts the block in a single from_value that falls back to Default on error, so previously one malformed entry discarded every other field — including the calibration numbers. Widening from 3 fields to 11 made that blast radius unacceptable; each field now absorbs its own error and yields None.

Breaking

Metadata gains fields and is now #[non_exhaustive], so it can no longer be built with a struct literal:

// no longer compiles
Metadata { loudness: None, input_level_dbu: None, output_level_dbu: None }

Read it from metadata_typed() instead. It was never constructible usefully by hand — it only ever comes out of a parsed file — and #[non_exhaustive] means future metadata fields are additive rather than another breaking bump.

Compatibility

No change to the forward pass. Metadata never reaches inference, so audio output is bit-identical to 0.3.0. Parity and RT-safety contracts are unaffected.

Verified against 233 real .nam files: all parse, none lose their calibration numbers, and the cab-inclusive captures are exactly the ones flagged.