sava-telephony / scripts /README.md
matthiastl's picture
SAVA fine-tuned for phone lines: PyTorch, ONNX and 8-bit ONNX, with tests and scripts
547c405
|
Raw History Blame Contribute Delete
5.36 kB
# Scripts
The working copies of the code that produced the files and numbers in this repository. They are
here as a record and to let you retrain or re-test; using the model needs none of them.
They expect to sit in one folder together with `sava_onnx.py`.
```bash
uv venv --python 3.12
uv pip install inworld-sava onnx onnxruntime onnxscript pytest pyarrow scikit-learn scipy soundfile
# Fine-tune: 9 training files, one more held out to choose the checkpoint (5 GB in all).
hf download pipecat-ai/smart-turn-data-v3.2-train --repo-type dataset \
--include "data/train-0000[0-9]-of-00083.parquet" --local-dir data/pipecat-train
.venv/bin/python -I finetune.py --train data/pipecat-train/data/train-0000[0-8]-of-00083.parquet \
--validation data/pipecat-train/data/train-00009-of-00083.parquet --out runs/phone-1
# Export and quantize.
.venv/bin/python export.py --model runs/phone-1/best.safetensors --out build/sava-telephony.onnx
.venv/bin/python quantize.py --source build/sava-telephony.onnx
.venv/bin/python -m pytest test_parity.py test_channels.py
# Score on pipecat's test set, clean and through both phone lines, then compare clip for clip.
hf download pipecat-ai/smart-turn-data-v3.2-test --repo-type dataset --local-dir data/pipecat
.venv/bin/python -I bench.py pipecat --root data/pipecat --out results/phone-1 \
--checkpoints runs/phone-1/best.safetensors --versions build/sava-telephony.int8.onnx \
--conditions clean phone gsm
.venv/bin/python -I compare.py results/phone-1 --pairs phone-1:original
# Pipecat's Smart Turn v3.2 on the same clips, for the comparison rows.
hf download pipecat-ai/smart-turn-v3 smart-turn-v3.2-gpu.onnx --local-dir .
.venv/bin/python -I bench.py pipecat --root data/pipecat --out results/smartturn \
--smart-turn smart-turn-v3.2-gpu.onnx --conditions clean phone gsm
.venv/bin/python -I compare.py results/phone-1 results/smartturn --pairs phone-1:original phone-1:smart_turn
# Score on real phone calls. The dataset is gated: accept its terms on its page first.
hf download talkbank/callhome eng/data-00000-of-00005.parquet --repo-type dataset --local-dir data/callhome
.venv/bin/python -I calls.py score --data data/callhome/eng/data-00000-of-00005.parquet \
--checkpoints runs/phone-1/best.safetensors --versions build/sava-telephony.int8.onnx \
--smart-turn smart-turn-v3.2-gpu.onnx --out results/callhome
# The same tests on wideband meetings, as recorded and through both simulated lines.
hf download diarizers-community/ami ihm/test-00000-of-00003.parquet --repo-type dataset --local-dir data/ami
.venv/bin/python -I calls.py score --data data/ami/ihm/test-00000-of-00003.parquet \
--checkpoints runs/phone-1/best.safetensors --smart-turn smart-turn-v3.2-gpu.onnx \
--conditions clean phone gsm --resamples 300 --out results/ami
```
| Script | What it does |
|---|---|
| `finetune.py` | trains a copy of SAVA to answer on phone-line audio as the original answers on clean audio; no labels |
| `channels.py` | the simulated phone lines: the random family used in training, and the fixed `phone` and `gsm` lines used in tests |
| `telephony.py` | the `phone` line: 8 kHz, 300-3400 Hz, G.711 mu-law |
| `bench.py` | scores the original, fine-tuned checkpoints and ONNX files on the pipecat smart-turn and TEN-VAD test sets, on any of the lines; `--smart-turn` scores pipecat's own detector the way its inference code runs it |
| `compare.py` | joins `bench.py` results by clip and prints accuracies and paired differences with bootstrap intervals |
| `calls.py` | scores the same systems on recordings of real phone calls (CallHome English): speech detection against the marked speech times, and the end-of-turn probability at pauses where the other person or the same person speaks next |
| `test_calls.py` | checks which pauses `calls.py` counts as hand-overs and which as the same speaker going on |
| `export.py` | exports a model's one-frame streaming step to ONNX, names its learned linear layers, and strips the exporter's per-node metadata |
| `quantize.py` | makes the 8-bit file by quantizing only those layers |
| `test_parity.py` | checks the exports against the PyTorch models; the tests on the original weights need the upstream repository's `tests/fixtures` copied to `fixtures/`, and `build/sava.onnx` from a plain `export.py` run |
| `test_channels.py` | checks the simulated lines keep the audio's length and timing |
| `speed.py` | times one 40 ms frame of each ONNX file and of the PyTorch streaming step on one CPU thread |
| `check_release.py` | scans a folder, model files included, for the local machine's paths and user name before it is published |
In `results/end-of-turn.txt`, `int8/*` is the 8-bit file of the original weights from
[matthiastl/sava-onnx](https://huggingface.co/matthiastl/sava-onnx); this repository's 8-bit file
is `onnx-telephony.int8/*`, and `phone-1/*` is the fine-tuned PyTorch weights.
`finetune.py` batches clips into six fixed lengths. In a first trial on an Apple GPU, with every
batch padded to its own length, steps slowed from about 1 s to about 7 s within 100 steps; with
fixed lengths a 200-step trial held 0.75 s per step.
The same graph, exported from the original weights, is published with iPhone and browser speed
tests in [matthiastl/sava-onnx](https://huggingface.co/matthiastl/sava-onnx).