sava-ONNX / README.md
jennyxue's picture
Model card and the original license
c2eb492 verified
|
Raw History Blame Contribute Delete
14.4 kB
---
base_model: inworld/sava
base_model_relation: quantized
license: apache-2.0
pipeline_tag: voice-activity-detection
library_name: onnx
tags:
- onnx
- moonbox
- onnxruntime
- inworld
- sava
- voice-activity-detection
- vad
- end-of-turn
- turn-detection
- streaming
- realtime
---
# SAVA (voice activity + end of turn) ONNX
ONNX builds of [SAVA (voice activity + end of turn)](https://huggingface.co/inworld/sava), made by Moonbox for on-device use with ONNX Runtime (CPU, CUDA, DirectML). Each
precision is one folder holding the streaming step graph and `pipeline.py`, a numpy port of the original package's
streaming session; what the graph takes and returns is under *How to run*.
## Files
The last column is the benchmark: every 40 ms frame of 20 synthetic conversations streamed through the build and
through the original package (details under *How to run*), and how far the build's speech and end-of-turn
probabilities are from the original's.
| Precision | File | Size | sha256 | Benchmark |
|---|---|---|---|---|
| fp16 | [`fp16/LICENSE`](https://huggingface.co/moonbox-dev/sava-ONNX/blob/main/fp16/LICENSE) | 11.4 kB | `cfc7749b96f6` | fp16 weights / fp32 math: speech probability within 0.0016 and end of turn within 0.0015 of the original's, 1 of 45,334 decisions changed; 7 ms per 40 ms frame on one CPU thread (RTF 0.18; original 0.09) |
| fp16 | [`fp16/NOTICE`](https://huggingface.co/moonbox-dev/sava-ONNX/blob/main/fp16/NOTICE) | 0.7 kB | `f845c91d8624` | fp16 weights / fp32 math: speech probability within 0.0016 and end of turn within 0.0015 of the original's, 1 of 45,334 decisions changed; 7 ms per 40 ms frame on one CPU thread (RTF 0.18; original 0.09) |
| fp16 | [`fp16/config.json`](https://huggingface.co/moonbox-dev/sava-ONNX/blob/main/fp16/config.json) | 1.8 kB | `87345d68edc7` | fp16 weights / fp32 math: speech probability within 0.0016 and end of turn within 0.0015 of the original's, 1 of 45,334 decisions changed; 7 ms per 40 ms frame on one CPU thread (RTF 0.18; original 0.09) |
| fp16 | [`fp16/pipeline.py`](https://huggingface.co/moonbox-dev/sava-ONNX/blob/main/fp16/pipeline.py) | 6.3 kB | `c475d6911a2d` | fp16 weights / fp32 math: speech probability within 0.0016 and end of turn within 0.0015 of the original's, 1 of 45,334 decisions changed; 7 ms per 40 ms frame on one CPU thread (RTF 0.18; original 0.09) |
| fp16 | [`fp16/step.onnx`](https://huggingface.co/moonbox-dev/sava-ONNX/blob/main/fp16/step.onnx) | 51.5 MB | `e6df2e108c0a` | fp16 weights / fp32 math: speech probability within 0.0016 and end of turn within 0.0015 of the original's, 1 of 45,334 decisions changed; 7 ms per 40 ms frame on one CPU thread (RTF 0.18; original 0.09) |
## How to run
Inworld's SAVA (streaming voice activity and end-of-turn detection in one 25.5M model: 16 kHz mono in, a speech and
an end-of-turn probability every 40 ms out) as one ONNX graph of a streaming step plus `pipeline.py`, a numpy port of
the `inworld-sava` package's `Session` (push / flush) and `run` around it:
- `step.onnx`: `pcm` [1, 640] (one 40 ms frame, float32 in [-1, 1]) and the stream state (19 tensors named
`state.*`: the mel front end's sample context, the frame mixer's previous frame, the three Mamba-2 blocks' conv
tails and SSM states, the four attention blocks' 512-frame key / value windows and position counters, the previous
speech probability, the frame counter; shapes and dtypes in `config.json`) -> `lookahead` [1, 1] (the speech logit
of the frame three frames back), `speech` [1, 1] (on time), `turn` [1, 1, 4] (end-of-turn logits at horizons 0,
200, 400, 800 ms) and the next state (`next.*`, same order). Start from zeros; feed each step's `next.*` back.
`pipeline.py` keeps the state as ONNX Runtime values between steps and needs only numpy and onnxruntime (soundfile
and soxr for files):
```bash
python fp16/pipeline.py recording.wav # per-frame speech and end-of-turn probabilities
```
```python
import sys; sys.path.insert(0, "fp16")
import pipeline
model = pipeline.Sava("fp16") # CPU, one thread
session = pipeline.Session(model)
for piece in pieces_of_16k_audio: # any length
frames = session.push(piece) # frames.speech, frames.turn: one value per whole 40 ms frame
frames = session.flush() # the last frames' speech verdicts
```
As in the original, the speech probability emitted at frame t judges frame t - 3 (120 ms of lookahead): the first
three values of a stream are the no-speech floor, and `flush()` steps three frames of silence so the last real frames
get their verdicts. The end-of-turn probability is on time. The package's turn policy (`sava.segment`, which turns
the curves into speech segments and turn ends) is not ported: use the original package's `segmenter.py` (pure
Python) on these curves, or your own policy.
**Precisions.** `fp16/`: the weights stored in fp16, computed in fp32 (50 MB). An int8 build (weight-only, MatMuls
int8) moved probabilities by up to 0.11, flipped 46 of 45,334 decisions (11 speech, 35 end of turn) and ran 7 times
slower on the CPU; not published.
**Benchmark.** 20 synthetic conversations (904 s): 3-6 utterances of LibriSpeech test-clean each, separated by
0.3-2.5 s pauses, with light white noise, pushed to the session in pieces of 0.1-0.5 s, then flushed. Each build
against the original package (`inworld-sava` 1.0.0 at github.com/inworld-ai/sava @b4221a5, its own streaming
`Session`, fp32 on the CPU): every frame's speech (lookahead) and end-of-turn probability, and how many frames fall
on the other side of 0.5. Real-time factor on one thread of the laptop CPU of an RTX 3080 Laptop machine, whole
pipeline.
| | Frames | Speech: largest difference | Speech: decisions changed | End of turn: largest difference | End of turn: decisions changed | Real-time factor (CPU, 1 thread) |
|---|---|---|---|---|---|---|
| original (PyTorch fp32) | 22,667 | - | - | - | - | 0.090 |
| ONNX fp32 (not published) | 22,667 | 2.0e-6 | 0 | 3.0e-6 | 0 | 0.17 |
| `fp16/` | 22,667 | 0.0016 | 0 | 0.0015 | 1 | 0.18 |
The ONNX step takes about 7 ms per 40 ms frame on one CPU thread (the original 3.6 ms): many small ops per frame, so
the per-step overhead dominates; keeping the state in ONNX Runtime between steps made no difference.
**License.** Apache-2.0 (code and weights), as the original; `LICENSE` and `NOTICE` (third-party datasets used in
training) are in every folder.
## How these were made
From [SAVA (voice activity + end of turn)](https://huggingface.co/inworld/sava) at revision `1beae7c1dd`: the package's own `SavaModel.step` (one frame, the whole stream state
in and out) exported with torch.onnx (opset 17) and checked against the module frame by frame. fp16: fp16 weights
with fp32 math. int8: weight-only, every MatMul / Conv weight int8 with a per-output-channel scale behind
DequantizeLinear and activations in fp32, so it runs on the CPU provider without a calibration set. Every build was
benchmarked before upload; the `sha256` column above is what the files must hash to.
## License
Apache-2.0. These files are a derivative of the original model and carry its license and notice (`LICENSE`,
`NOTICE` in every folder): they govern your use of these files. The original model card follows unchanged.
---
# Original model card
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/inworld/sava/resolve/main/docs/assets/inworld-logo-white.svg">
<img src="https://huggingface.co/inworld/sava/resolve/main/docs/assets/inworld-logo-black.svg" alt="Inworld" width="220">
</picture>
</p>
<h1 align="center">SAVA</h1>
<p align="center">
Semantic acoustic voice activity: streaming speech and end-of-turn detection in one model with an open license.
</p>
<p align="center">
<a href="https://github.com/inworld-ai/sava"><img src="https://img.shields.io/badge/GitHub-inworld--ai%2Fsava-181717?logo=github" alt="GitHub: inworld-ai/sava"></a>
</p>
---
## TL;DR
SAVA returns two probabilities for a live audio stream:
* `speech` → whether a frame holds speech
* `turn` → whether the speaker's turn has ended
The model's shared network uses acoustic and sentence context to distinguish speech from coughs, laughs, music and keyboard clatter.
| | SAVA |
|---|---|
| made for | voice activity and conversational turn taking |
| input | 16 kHz mono audio |
| output | two probabilities every 40 ms |
| timing | speech probability for a frame is emitted 120 ms later (lookahead); end-of-turn probability has no lookahead |
| parameters | 25.5M |
| execution | plain PyTorch, CPU or an explicitly selected device |
Use it to open a turn when speech starts and close it when the sentence is complete.
The [reference turn policy](https://github.com/inworld-ai/sava/blob/main/docs/USAGE.md) turns the probabilities into segments; applications can supply their own policy.
SAVA responds to any voice. It does not pick out a target speaker, and it leaves interruptions and backchannels to the application's dialogue policy.
## Quick start
Using a coding agent? Point it at the [setup section of AGENTS.md](https://github.com/inworld-ai/sava/blob/main/AGENTS.md#setting-up-sava-for-a-user): it installs the package, checks the machine with `sava-doctor` and runs SAVA on a first recording.
With Python 3.10 or later:
```bash
python -m pip install inworld-sava
# Or from a clone: git clone https://github.com/inworld-ai/sava && cd sava && python -m pip install -e .
sava run recording.wav
sava run recording.wav --turns_dir turns/ --curves curves.json
```
```python
from inworld import sava
model = sava.load("inworld/sava")
curves = sava.run(model, sava.load_audio("recording.wav"))
turns = sava.segment(curves, sava.Policy(), model.lookahead_frames)
session = sava.Session(model)
for piece in pieces_of_16k_audio: # One-dimensional floating-point mono samples.
frames = session.push(piece)
frames = session.flush()
```
`sava.load("inworld/sava")` and the CLI's default model download the weights on first use and verify their checksum.
The CLI defaults to CPU; `--device` selects another device.
For microphone input, install `python -m pip install "inworld-sava[mic]"` and run `sava mic`.
The code, [the integration guide](https://github.com/inworld-ai/sava/blob/main/docs/USAGE.md) and the [benchmarks](https://github.com/inworld-ai/sava/blob/main/bench/README.md) are on GitHub: [inworld-ai/sava](https://github.com/inworld-ai/sava).
## Hardware
Tested on NVIDIA Ampere, Hopper and Blackwell GPUs and on CPU.
On an Apple M3 Max CPU one stream takes 3.8 ms per 40 ms frame; [the integration guide](https://github.com/inworld-ai/sava/blob/main/docs/USAGE.md) lists the measured configurations.
## The benchmarks
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/inworld/sava/resolve/main/docs/assets/vad-dark.svg">
<img src="https://huggingface.co/inworld/sava/resolve/main/docs/assets/vad-light.svg" alt="Voice-activity frame AUC for SAVA and Silero VAD on nine public dataset readings" width="100%">
</picture>
</p>
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/inworld/sava/resolve/main/docs/assets/turn-dark.svg">
<img src="https://huggingface.co/inworld/sava/resolve/main/docs/assets/turn-light.svg" alt="End-of-turn clip AUC for SAVA and smart-turn on public datasets" width="100%">
</picture>
</p>
Voice activity is compared with Silero VAD; end of turn is compared with pipecat smart-turn v3.2.
These are per-dataset measurements, with no combined ranking.
Speech scores use each model's own output timing, so SAVA's 120 ms lookahead makes the comparison unequal in latency.
Quiet speech-like noise can trigger SAVA; the ESC-50 results measure that failure mode.
[The complete tables, confidence intervals, noise tests, turn latency and reproduction steps](https://github.com/inworld-ai/sava/blob/main/bench/README.md) are on GitHub.
## Architecture
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/inworld/sava/resolve/main/docs/assets/architecture-dark.svg">
<img src="https://huggingface.co/inworld/sava/resolve/main/docs/assets/architecture-light.svg" alt="SAVA: causal log-mel features, frame mixer, Mamba and attention trunk, speech and turn heads" width="100%">
</picture>
</p>
| part | detail |
|---|---|
| front end | causal log-mel, 128 Slaney mel bins of a 25 ms Hann DFT every 10 ms, log10 with a 1e-10 floor, `(x + 4) / 4`; four hops per frame plus the frame's log RMS |
| mixer | the current and previous frame's features, one linear projection to 512, RMSNorm |
| trunk | three Mamba-2 blocks (expand 2, head dim 64, state 128, conv kernel 4) and one attention block (8 query heads, 2 key/value heads, head dim 64, 512-frame causal window, rotary positions, RMS-normed q and k, exclusive self attention), each with a SwiGLU FFN of 2048 |
| voice-activity head | RMSNorm, down-projection to 512, one attention block (window 512, FFN 1536), RMSNorm, two linear readouts: on time, and the released three-frame look-ahead |
| end-of-turn head | the trunk output with a 64-wide embedding of the previous frame's on-time speech probability, the same block shape, a linear readout with four horizon columns (0, 200, 400, 800 ms); column 0 is the released output |
## Training data
SAVA was trained on approximately 5,000 hours of unique audio.
Inworld built training examples from real and synthetic conversational speech
mixed with non-verbal vocal sounds, noise, music and room acoustics, with a
speech label and an end-of-turn label for every frame. The training recipe,
code and data are not part of this release.
Third-party datasets used in training are credited in [NOTICE](NOTICE).
## License
Code and weights are Apache-2.0 ([LICENSE](LICENSE)).
Third-party notices are in [NOTICE](NOTICE).
## How to contribute
Everyone is welcome to use the model however they like and to make it better in any way they see fit!
Development happens on GitHub: see [CONTRIBUTING.md](https://github.com/inworld-ai/sava/blob/main/CONTRIBUTING.md) for setup, tests and bug reports.
---
<p align="center">Built for people with ❤️ by Inworld.</p>