Skip to content

Add end-of-turn detection (TURN role): Smart Turn v3.2 and SAVA - #269

Draft
cjpais wants to merge 22 commits into
mainfrom
turn-detection
Draft

cjpais wants to merge 22 commits into
mainfrom
turn-detection

Conversation

@cjpais

@cjpais cjpais commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds end-of-turn detection as a new role, TRANSCRIBE_ROLE_TURN (include/transcribe/turn.h), with two models:

  • Smart Turn v3.2 (Pipecat): clip model; scores the last 8 s of the current turn. Reuses the Whisper encoder.
  • SAVA (Inworld): streaming model (40 ms frames, Mamba-2 + attention); per-frame turn and speech scores; also serves the VAD role.

API (docs/turn.md, draft 6): transcribe_turn_run (clip → p, ended, per-frame scores for streaming models), transcribe_turn_stream_feed/flush/reset, transcribe_turn_stream_feed_batch (many live users in one compute, bit-identical to separate feeds). Live decisions stay with the caller. vad.h changes are comments only (a model may judge frames late).

Scope

  • include/transcribe/turn.h, include/transcribe.h (role bit, ABI ids), vad.h comments
  • src/transcribe-turn.{h,cpp}, src/arch/smart_turn/, src/arch/sava/; Whisper weights loader split for reuse (behaviour unchanged)
  • converters, reference dumpers, scripts/envs/{smart_turn,sava}, validate.py TURN role, golden manifests, tolerances
  • bindings: Rust, Python, TypeScript, Swift (TurnSession), Swift ABI pin
  • CLI turn driver, examples/turn_live, tools/transcribe-turn-eval, scripts/turn/
  • catalog (turn-publication-v1), model pages, HF card specs, porting docs
  • note: commit be19a14c also contains the scripts/audit_gguf_metadata.py VAD/TURN exemption

AI Assistance

Implemented with AI assistance (Claude), directed and reviewed by the author.

Validation

  • validate.py all --family smart_turn: 8/8 cases, 16/16 tensors, p within 1e-4 (max 3.3e-6), same decisions
  • validate.py all --family sava: 8/8 cases incl. a 306 s stream, 32/32 tensors, p within 1e-4 (max 2.7e-6), same decisions
  • Pipecat test set (31,527 clips): Smart Turn F32 93.71%, AUC 0.98252, decisions identical to the fp32 ONNX; SAVA F32 93.36%, AUC 0.97946 (= Inworld's published AUC); F16 / Q8_0 in the catalog
  • ctest: 96/96 with real-model smokes; binding suites pass; checked on Apple M1 and Ryzen 7 PRO 4750U

- include/transcribe/turn.h: TRANSCRIBE_ROLE_TURN; clip scoring
  (transcribe_turn_run: p, ended, per-frame tracks, turn segments) and
  live streams with an optional speech track; stream_feed_batch for
  several live sessions in one compute. Design: docs/turn.md.
- vad.h: lookahead_frames and the model's recommended threshold
  (params.threshold defaults to the model's; Silero unchanged).
- smart_turn arch (Whisper encoder reused) and sava arch (Mamba-2 +
  attention, streaming, VAD | TURN), converters, reference dumpers,
  golden manifests, finalized tolerances, smokes and real smokes.
- validate.py TURN role; transcribe-cli turn driver; examples/turn_live;
  tools/transcribe-turn-eval + scripts/turn/eval_cpp.py.
- Catalog and model docs (speed rows pending a turn bench profile).
stream_step_batch steps one frame for each of N sessions in one graph
(weights read once); per-session state-dependent work keeps each
session's results bit-identical to its own feed. F16 on ARM CPU noted
as slower than F32 in the model docs.
…Turn and SAVA

Publication tooling for the TURN role, as vad-publication-v1 and
langid-publication-v1 were added for theirs:

- catalog/_benchmark_profiles.json: profile turn-publication-v1 (roles.turn).
  Accuracy: Pipecat's smart-turn-data-v3.2-test, every shipped quant, CPU,
  a clip complete when p > 0.5. Speed: jfk-8s (transcribe_turn_run on 8 s)
  for every TURN model, plus, for streaming models only (new
  speed.streaming_samples), jfk-40ms (one stream feed) and jfk-40ms-x8 (one
  8-user stream_feed_batch tick); a -1t suffix is one thread, otherwise the
  library default. Target: machine "m1" (Apple M1, slug alias apple-m1), a
  proxy for the unreachable M4 reference machine.
- catalog/_schema.json: additive, scoped to TURN accuracy rows: a `turn`
  object (threshold, n_complete, fp_pct, fn_pct as shares of all clips, auc)
  and agreement.max_abs_p_delta; db.py columns to match.
- scripts/turn/bench.py (raw C ABI through the Python binding; waits for a
  quiet machine and records the load), scripts/turn/score.py (accuracy with
  bootstrap CI, FP/FN, AUC, optional agreement with a reference column),
  ingest_accuracy.py TURN branch; eval_cpp.py records engine_sha, backend,
  threads and refuses a dirty engine tree.
- render.py `turn` block and TURN recipe/labels; the HF card template shows
  the TURN table; generate.py writes the card where the GGUFs are.
- README: the TURN family index. Smart Turn forward map (Stage 4 artifact,
  written from the finished port).

Speed rows: 24 cells on the M1 at 8f97ab5 (load 1.5-2.8 at cell start).
Validation pins: validate.py all --family smart_turn / sava pass at 8f97ab5.
Accuracy rows follow once the Pipecat runs at 8f97ab5 finish.
The TURN speed cells run on the x86 reference host as well as the M1 proxy,
from the same driver: scripts/turn/bench.py benches whichever profile target
the machine's CPU maps to, waits for Tctl below the target's cooldown_tctl_c
(55 C on ryzen-4750u, as in the other profiles) and records Tctl beside the
load averages; the busy-process gate copes with Linux's 15-character comm.
CPU only: the TURN models resolve AUTO to the CPU, the validated path. The
publication check now requires the 24 ryzen-4750u cells.
24 turn-publication-v1 cells from the Ryzen 7 PRO 4750U rig (CPU, engine
8415e8e, Tctl below 55 C and load below 3 at every cell's start), measured
on rig-built GGUFs that differ from the canonical files only in the
converter's last-bit constants (recorded in both porting logs; ingest keys a
cell by quant, not by hash).

Model pages: a perf table per machine, and the speed advice follows the
measurements: F16 and Q8_0 are not faster than F32 for a whole clip on one
Ryzen thread, Q8_0 is the fastest streamed SAVA frame on both machines, F16
is 1.6-2.0x slower than F32 on the M1.
All six GGUFs re-run on pipecat-ai/smart-turn-data-v3.2-test (31,527 clips)
at 8f97ab5. The old rows predated any commit, and SAVA's scores had moved
at 6b130f9. Scored by scripts/turn/score.py and ingested. The headline is
accuracy at p > 0.5 on the Pipecat set.

- Smart Turn: F32 93.71%, F16 93.70%, Q8_0 93.68%; AUC 0.98252, 0.98252,
  0.98249. Decisions equal to the fp32 ONNX on 31,527, 31,525 and 31,478
  clips.
- SAVA: 93.36% for all three quants; AUC 0.97946, 0.97946, 0.97935.

Model pages render the TURN table and the recipe. SAVA's hand table keeps
only what the catalog does not hold: accuracy at 0.9, the best threshold,
and Inworld's published figures.

eval_cpp.py --engine-sha names the commit a prebuilt tool was built at,
after checking that the engine sources match HEAD.
…ecks

general.languages and the slug streaming heuristic are transcription
assumptions. The catalog schema already exempts the vad and turn roles from
languages, and SAVA and Silero are language-agnostic. For silero_vad, sava
and smart_turn the audit drops both checks; sync_capabilities --check still
holds the streaming flag to the catalog. All six TURN GGUFs now audit clean.
The Mac-built GGUFs are canonical. A rebuild on another platform matches
every upstream weight and the metadata, but the converter-computed mel
filterbank (both models) and SAVA's ssm.a = -exp(A_log) can differ in the
last f32 bit, because libm exp/log round differently across platforms.
On the Ryzen 4750U this moves outputs by about 1e-7. Cross-platform byte
reproducibility is not a goal.
…ribe_vad_params_init

Rust and Swift defaulted to 0.5; Python and TypeScript already left the
native default and only change their docs. Silero is unchanged (0.5).
…g transcribe_vad_params_init"

This reverts commit 4a4f6f8.
- vad.h: drop transcribe_vad_info::lookahead_frames and ::threshold and keep
  the 0.5 default (no ABI change); only the feed / flush wording changes.
- turn.h: transcribe_turn_params is {struct_size, threshold, family}.
  SAVA's segment rule moves to the SAVA family extension
  transcribe_sava_turn_ext (include/transcribe/sava.h, kind SVTN, slot
  TURN_RUN); TurnOps::apply_run_ext validates and applies it.
- Tests, docs/turn.md (draft 5), extension registry, regenerated FFI.
…turn_live learns the lag from feeds only; SAVA per-clip PyTorch reference script
…unt fixes, dispatcher guards and ops checks, binding CI fixtures and docs, SAVA per-clip reference agreement, doc corrections

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant