This repository contains example models for the anira library, designed for validation and demonstration purposes.
-
SimpleGainNetwork: This folder contains an example model, designed for multichannel audio inference. It includes:- Inputs:
- Audio data: A multichannel input array representing the audio signal. Models are generated for
1(mono),2(stereo),4and16channels. - Gain parameter: A parameter to apply gain (amplification) to the input audio.
- Audio data: A multichannel input array representing the audio signal. Models are generated for
- Outputs:
- Processed audio: The input audio after applying the gain.
- Peak gain: The maximum absolute gain measured across all channels.
- Formats: Each channel count is exported to TorchScript (
.pt), ONNX (.onnx), TFLite (.tflite), and ExecuTorch (.pte). The build script cross-checks that all four runtimes produce consistent outputs.
- Inputs:
-
StatefulAccumulatorNetwork: This folder contains an example model with explicit state, designed to validate state passing: the state is an ordinary input tensor and an ordinary output tensor, and the caller feedsstate_outback as the nextstate_in. The model itself keeps nothing between two calls, so the same model runs in every runtime (none of them needs a hidden state) and the feedback is observable from outside. It has no weights and no randomness. It includes:- Inputs, in this order:
state_in: float32[1, C, 2]. Per channelc,state_in[0, c, 0]is the running sum andstate_in[0, c, 1]a block counter. It starts as zeros.data: float32[1, C, N], the audio block.Nis dynamic. Models are generated forC = 1(mono) andC = 2(stereo).
- Outputs, in this order:
processed_data: float32[1, C, N], withprocessed_data[0, c, n] = data[0, c, n] + state_in[0, c, 0].state_out: float32[1, C, 2], withstate_out[0, c, 0] = state_in[0, c, 0] + sum_n data[0, c, n]andstate_out[0, c, 1] = state_in[0, c, 1] + 1.
- State position: The state is deliberately the first input and the last output, because state tensors may sit anywhere in a model's tensor order.
- Expectation: With the state fed back, the output of block
kis its input plus the sum of every sample of the blocks0..k-1of the same channel, and the counter ofstate_outreadsk + 1. Without feedback (zero state at every block) the output equals the input. With small integer-valued inputs every value is exact in float32, so both hold bit-exactly, and a stale or zeroed state is visible in the samples. - Tensor order per format: TorchScript, ONNX and ExecuTorch keep the order above; the ONNX tensor names are exactly
state_in,data,processed_data,state_out. The converted TFLite files keep it on the input side only. By position (get_input_details()/get_output_details(), which is what a consumer that binds TFLite tensors by position sees, as anira does), mono and stereo alike:- input 0:
state_in(serving_default_args_0:0,[1, C, 2]), input 1:data(serving_default_args_0_1:0,[1, C, -1]) - output 0:
state_out(PartitionedCall:1,[1, C, 2]), output 1:processed_data(PartitionedCall:0,[1, C, -1]) - The
serving_defaultsignature keeps the declared mapping:args_0=state_in,args_0_1=data,output_0=processed_data,output_1=state_out.
- input 0:
- Formats: Each channel count is exported to TorchScript (
.pt), ONNX (.onnx), TFLite (.tflite), and ExecuTorch (.pte). The build script prints the tensors each file reports, then runs the saved TorchScript trace and every export withN = 10andN = 64over three consecutive blocks, with the state fed back and without, and asserts the expectation above with exact equality. - Negated twin (
stateful_accumulator_network_negated_monoand_stereo): a second model of exactly this tensor set, designed to validate switching between the models of one form while a stream runs. It differs in one rule:processed_data[0, c, n] = data[0, c, n] - state_in[0, c, 0], it subtracts the running sum where the accumulator adds it.state_outfollows the accumulator's rule, so the state after a block does not depend on which of the two models ran which block, and either model continues from the other'sstate_out.- Expectation: Alone, with the state fed back, the output of block
kis its input minus the sum of every sample of the blocks0..k-1, and the counter readsk + 1. When a consumer changes the model before blockkand keeps the state, blockkis its input plus (accumulator) or minus (twin) that same sum, and the counter goes on tok + 1; when the model that takes over starts from a zero state instead, blockkequals its input and the counter reads1. So the sign of the running sum inprocessed_datatells which model ran a block, and its size and the counter tell whether the state was kept. While the running sum is zero (the first block after a zero state) the two models agree. - Tensor order per format: the accumulator's in every format, names included (the ONNX names, the TFLite positions, tensor names and signature keys listed above). The ONNX and TFLite graphs differ from the accumulator's in one operator (
SubforAdd). - Formats: the same four per channel count. The build script asserts that the twin reports the accumulator's tensors in every format, runs the twin through the checks of the accumulator, and runs the five-block sequence accumulator, accumulator, twin, twin, accumulator in every runtime with both files of that runtime, once with the state kept at each switch and once with a zero state at each switch, all with exact equality.
- Expectation: Alone, with the state fed back, the output of block
- Inputs, in this order:
-
TypedGainNetwork: This folder contains theSimpleGainNetworktensor set at other dtypes than float32, designed to validate that model tensors of any dtype travel end to end through a runtime. The models compute in float32 and cast at the boundary (processed_data = Cast(Cast(data, float32) * Cast(gain, float32), <dtype>)), so every runtime needs only a Cast for the boundary dtype, and with small integer-valued inputs and a gain of 2 every output is exact. It includes:typed_gain_network_<dtype>,<dtype>one ofint16,int8,float16, mono:- Inputs:
data[1, 1, N](Ndynamic) andgain[1]([1, 1, 1]in the TFLite file), both of<dtype>. - Outputs:
processed_data[1, 1, N]andpeak[1](the largest absolute sample), both of<dtype>. - Formats: TorchScript (
.pt), ONNX (.onnx), TFLite (.tflite, no quantisation parameters on any tensor) and ExecuTorch (.pte). The TFLite files order their tensors asSimpleGainNetwork's: input 0 isdata(serving_default_args_0:0), input 1gain.
- Inputs:
typed_gain_network_<dtype>_unplanned.pte: the same method at a static[1, 1, 512]window with its inputs and outputs left out of ExecuTorch's memory plan (MemoryPlanningPass(alloc_graph_input=False, alloc_graph_output=False)), so a runtime binds its caller's memory to them instead of copying:Method::set_inputaliases the input,Method::set_output_data_ptrtakes the output buffer. The window is static becauseset_output_data_ptrtakes a buffer of the output's full capacity, which a dynamic axis would make its upper bound (65536 samples).dtype_matrix_<dtype>.onnx, for the ten dtypesfloat32,float64,float16,bfloat16,int8,uint8,int16,int32,int64,bool: one inputdata[1, 1, N]and one outputprocessed_dataof that dtype,processed_data = Cast(Cast(data, float32) * 2, <dtype>)(aboolinput comes back unchanged), written withonnx.helper(opset 17, IR version 8).quantized_gain_network_int8.tflite: a fully integer TFLite model,y = 0.5 * xon[1, 1, 64], whose input and output areint8tensors with a scale and a zero point (quantised I/O, for a consumer's refusal of it).- Checks: the build script runs every file in its runtime and asserts exact equality with the expectation (the unplanned
.pteat its 512-sample window, the quantised model by its tensor types, its parameters and one inference within a quantisation step).
-
VariantGainNetwork: This folder contains three models of one architecture with different weights, designed to validate switching between the models of one form while a stream runs: they report identical tensors (names, order, shapes, dtypes) and differ only in what they compute. The architecture is oneConv1d(1, 1, kernel_size=1, bias=False), and its single weight is all that a variant sets. It includes:variant_gain_network_<variant>_mono,<variant>one ofhalf(weight0.5),double(weight2.0),invert(weight-1.0):- Input:
data, float32[1, 1, N].Nis dynamic. - Output:
processed_data, float32[1, 1, N], withprocessed_data[0, 0, n] = w * data[0, 0, n].
- Input:
- Expectation: Every weight is a power of two or
-1, sow * datais exact in float32 for every sample, not only for integer-valued ones, and in every runtime. A consumer tells from any non-zero block which of the three models produced it. - Tensors per format: identical for the three variants.
- TorchScript: one argument
data, one tensor returned (no tuple); the weight is the parameterconv.weight[1, 1, 1]. - ONNX: input
data[1, 1, dynamic], outputprocessed_data[1, 1, dynamic]; oneConvnode with the initializerconv.weight. - TFLite: input 0 is
data(serving_default_args_0:0,[1, 1, -1]), output 0 isprocessed_data(PartitionedCall:0,[1, 1, -1]); theserving_defaultsignature names themargs_0andoutput_0. The file convolves in TensorFlow's[batch, time, channel]layout between two transposes (TRANSPOSE,EXPAND_DIMS,CONV_2D,RESHAPE,TRANSPOSE). - ExecuTorch: the method
forwardwith one input and one output; the dynamic axis reads as its upper bound,[1, 1, 65536].
- TorchScript: one argument
- Formats: Each variant is exported to TorchScript (
.pt), ONNX (.onnx), TFLite (.tflite), and ExecuTorch (.pte). The ONNX, TFLite and ExecuTorch files of two variants differ in the bytes of the weight alone. The build script asserts that the three variants of a format report identical tensors, then runs the saved TorchScript trace and every export withN = 10,N = 64andN = 512, on integer-valued and on fractional samples, and assertsprocessed_data == w * datawith exact equality.
-
RaveDjembe: A RAVE neural audio codec (v1 architecture, 44.1 kHz mono, trained on djembe) ported from its TorchScript streaming export to ONNX Runtime, LiteRT/TFLite and ExecuTorch with all streaming state passed as explicit input/output tensors, so stateless runtimes can run real-time block-by-block inference. Ships separate encoder / decoder / forward models per format, parity tests against golden reference vectors, and the full export pipeline. Seethird-party/ircam-acids/RAVE/RaveDjembe/README.md.
The Python environment is managed with uv: pyproject.toml declares it, uv.lock pins every package and .python-version selects Python 3.12. Create it with:
uv syncThis installs a CPU build of torch, onnx, onnxruntime, onnxscript, tensorflow and executorch. torch and executorch are pinned as a pair (torch 2.14 with executorch 1.5), because the ExecuTorch wheels are built against one torch release without declaring it. uv run syncs the environment on its own, so the uv sync step is optional. The RaveDjembe scripts need the rave dependency group on top, see its README.
To (re)generate the SimpleGainNetwork models:
uv run python SimpleGainNetwork/simple_gain_network.pyBy default this builds the (1, 2, 4, 16) channel set; edit the channel_counts argument to main() to change it.
To (re)generate the StatefulAccumulatorNetwork models:
uv run python StatefulAccumulatorNetwork/stateful_accumulator_network.pyBy default this builds the (1, 2) channel set, the accumulator and its negated twin for each. The .pte export is skipped when executorch is not installed. The committed accumulator files were produced and verified with Python 3.12.14 on Linux aarch64, with torch 2.14.0 (CPU build), onnx 1.23.0, onnxruntime 1.30.0, onnxscript 0.7.2, tensorflow 2.21.0 (its bundled TFLite converter and interpreter), executorch 1.5.0 and numpy 2.5.3.
The committed files of the negated twin were produced and verified with Python 3.12.13 on Linux x86_64, with the versions uv.lock pins: torch 2.14.1 (CPU build), onnx 1.23.2, onnxruntime 1.31.1, onnxscript 0.7.2, tensorflow 2.21.0, executorch 1.5.1 and numpy 2.5.4. That run rebuilt the accumulator's .tflite and .pte files byte for byte. Its .onnx and .pt files do not rebuild to the byte (the ONNX file records the torch version, the TorchScript file a serialization id and the source positions of the script), so the committed ones were kept and the twin was verified against them. Both models also run exactly, alone and switched, in the Python builds of the runtime versions anira pins (onnxruntime 1.26.0, the TFLite interpreter of tensorflow 2.17.0, torch 2.12.0, executorch 1.3.1).
To (re)generate the TypedGainNetwork models:
uv run python TypedGainNetwork/typed_gain_network.pyThe .pte exports are skipped when executorch is not installed. TensorFlow's graph optimizer, which the quantised conversion runs, fails on a machine whose CUDA libraries are present but do not load; run the script with CUDA_VISIBLE_DEVICES=-1 there. The committed files were produced and verified with Python 3.12 on Linux x86_64, with torch 2.14.0 (CPU build), onnx 1.23.0, onnxruntime 1.30.0, onnxscript 0.7.2, tensorflow 2.21.0, executorch 1.5.0 and numpy 2.5.3, and each loads and runs exactly in anira's pinned runtimes (ONNX Runtime 1.26.0, TFLite 2.17.0, LibTorch 2.12.0, ExecuTorch 1.3.1).
To (re)generate the VariantGainNetwork models:
uv run python VariantGainNetwork/variant_gain_network.pyThis builds the three variants half, double and invert. The .pte export is skipped when executorch is not installed. The committed files were produced and verified with Python 3.12.13 on Linux x86_64, with the versions uv.lock pins: torch 2.14.1 (CPU build), onnx 1.23.2, onnxruntime 1.31.1, onnxscript 0.7.2, tensorflow 2.21.0 (its bundled TFLite converter and interpreter), executorch 1.5.1 and numpy 2.5.4, and each also runs exactly in the Python builds of the runtime versions anira pins (onnxruntime 1.26.0, the TFLite interpreter of tensorflow 2.17.0, torch 2.12.0, executorch 1.3.1).