Skip to content

Unsloth Studio: deterministic end-to-end voice-pipeline latency benchmark (reconstruction of #6527, part B) - #12385

Closed
LeoBorcherding wants to merge 24 commits into
unslothai:mainfrom
LeoBorcherding:voice/pr-b-benchmark-harness
Closed

LeoBorcherding wants to merge 24 commits into
unslothai:mainfrom
LeoBorcherding:voice/pr-b-benchmark-harness

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Replaces #10374, which closed automatically when its head fork was deleted. The commits are unchanged (head cab481c5).

This is the benchmark half of #6527 by @BardiaKoopah and @LeoBorcherding, rebuilt on current main by @donaldfilimon. It doesn't depend on the voice mode PR, and the two can land in either order.

What this PR adds or changes

Everything is new, under studio/benchmarks/voice/. No existing code is touched.

  • voice_bench.py: a deterministic latency benchmark covering STT, the LLM turn, and TTS, so a slowdown in turn latency shows up as a number rather than a feeling
  • conversation.json: the fixed conversation it replays
  • mint_token.py: mints an auth token for running it against a local Unsloth Studio
  • test_voice_bench.py: tests for the harness
  • README.md: how to run it and how to read the output

Test plan

  • Lint and frontend green; backend green apart from the 135 failures that also fail on the merge base
  • Run the benchmark with a voice loaded and sanity-check the numbers

donaldfilimon and others added 22 commits September 4, 2026 03:22
…enchmark

Split out of PR unslothai#6527 so the voice conversation path can be reviewed on its own.

Orpheus synthesizes the input utterances (cached), fed through STT -> LLM -> TTS
against a running Studio backend. Records per-stage wall clock and a
length-normalized rate (STT/TTS real-time factor, LLM tok/s) so a longer
utterance isn't counted as slower, with first-audio latency as the headline. It
also gates on accuracy -- STT word error rate, topical coverage, LLM determinism
-- so a speedup that hurts the answers is caught rather than celebrated.
Reasoning-aware: times the first SPOKEN token, and --think measures what a chat
model's chain of thought costs first audio. Writes JSON reports and diffs against
a baseline. Tokens, reports and fixtures are gitignored.

Independent of the voice-slot branch: STT and TTS go through
/v1/audio/transcriptions and /v1/audio/speech, which main already serves, and the
/api/inference/voice/status probe degrades to empty when that route isn't there.

Co-authored-by: LeoBorcherding <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01TSaSnTn9AUf4wPbCaTTykW
…erminism, or --repeats < 1

summarize() silently dropped any turn whose stage errored (its metric was None),
so a run with a broken stage could total *lower* than its baseline and still exit
0. It now reports `complete` plus the (pass, turn) gaps; print_report lists them,
diff_baseline refuses to compare an incomplete run (or an incomplete baseline),
and main exits 1. A determinism check that ran and found the two seeded replies
different (or could not run at all) also exits 1 instead of only printing.
`--repeats` is validated as a positive integer at parse time; 0 or a negative
value used to reach summarize() and raise IndexError after the warmup and
determinism requests had already been spent. Exit codes are documented.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…o their utterance

speak() now sends the benchmark --seed as AudioSpeechRequest.seed on every
/v1/audio/speech call (fixtures, warmup, reply synthesis). The README claimed a
fixed TTS seed while the request carried none; it now says where the seed is
honoured on main (the transformers TTS path) and where it is not (a GGUF voice,
an external connection).

The fixture cache was keyed on the turn id alone, so editing a turn's text or
pointing --conversation at another script with the same ids kept feeding the old
turn_N.wav to STT. A turn_N.json sidecar records the utterance and whether the
wav was synthesized or supplied: a synthesized fixture whose text changed is
re-synthesized; a hand-supplied recording is adopted on first use and never
overwritten, raising FixtureMismatch instead so the turn fails visibly.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…unk streams in; run determinism last

first_audio_latency summed stt + llm_ttft + tts_first, but speak() is only called
once the LLM stream has finished, and a clause-first streaming TTS could not
start on a single token either: the tokens between the first one and the end of
the opening clause are real waiting the formula dropped. chat_stream now records
(cumulative chars, seconds) per content delta, first_chunk_span() computes how
many streamed characters the first synthesizable chunk plus its closing boundary
occupy (a "." followed by "5" is a decimal, not a sentence end), and the new
llm_first_chunk_s is the arrival time of that span. The headline is now
stt_s + llm_first_chunk_s + tts_first_s; llm_ttft_s stays reported, and the
README states that turn_wall_s is the pipeline as implemented while
first_audio_latency is the streaming projection.

The determinism check ran before pass 1, so --no-warmup alone still measured an
LLM warmed by two full generations. It now runs after the measured passes (it
uses its own message list, so the result is unaffected), and all input fixtures
are materialized in a prepare step before any timed turn instead of being
synthesized mid-turn on a first run. The README documents the order and what a
genuinely cold pass needs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…xternal TTS connection

On origin/main Studio serves one resident model: _generate_tts_wav is reload-only
and returns 400 unless the resident model is a TTS model, while
/v1/chat/completions against a resident TTS model returns speech instead of
text. The harness needs a chat model and a voice at once, which only the voice
slot in the conversation-mode backend (PR unslothai#10373) provides; the README presented
that as a plain prerequisite ("Speak-with picker") without naming the PR, and on
main every speak() call would have 400'd after the chat stage. (Codex's
mechanism was auto-switch; that setting defaults off, but the outcome is the
same: the speech route never switches the resident model.)

resolve_tts_route() now decides before anything runs: a resident TTS model, or no
loaded voice slot and no external connection, exits 2 with the remedy named. New
--tts-provider-id/--tts-model/--tts-voice route every /v1/audio/speech call to a
saved external TTS connection via the [x-unsloth] provider_id field, which the
speech route proxies without touching the resident model, so the benchmark runs
on main alone (with the remote round trip in its TTS numbers). The README names
PR unslothai#10373 as the prerequisite for the local-TTS path, attributes the
leading-silence trim and GGUF TTS seed to that PR rather than to main, and
documents the audio-gallery side effect: the local speech route persists every
clip with no opt-out (9 clips per default run, 25 for --repeats 3), pruned at
UNSLOTH_AUDIO_GALLERY_MAX_CLIPS/MAX_BYTES; a non-persisting option is a backend
follow-up outside this benchmark-only PR.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…rk's pure parts

Covers the pieces the review fixes touched: first_chunk_span/first_chunk_arrival
and chat_stream's first-chunk timing over a synthetic SSE stream, speak() sending
the seed and provider fields, summarize() completeness and the baseline-diff
refusal on an incomplete run, --repeats validation, resolve_tts_route on main
(no route), a resident TTS model, a loaded voice slot, and an external
connection, and the fixture sidecar (cache hit, re-synthesis on text change,
supplied recordings adopted and never overwritten, corrupt sidecar). Runs with
unittest or pytest; FIXTURES/DOWNLOADS are redirected to a temp dir so nothing
touches ~/Downloads.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…te the recorded findings' formula

The per-turn table gained a `chunk` column, so its rules now match the 84-char
header. The measured findings in the README were recorded under the earlier
stt_s + llm_ttft_s + tts_first_s definition and say so, since llm_first_chunk_s
is larger than llm_ttft_s by construction.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… review-added code

scripts/run_ruff_format.py (ruff format + enforce_kwargs_spacing.py) would
rewrap the _REQUIRED_METRICS tuple, the resolve_tts_route call, and three
over-long lines in the new tests; apply exactly those. The pre-existing kwarg-
spacing drift that plain `ruff format --check` reports on this directory (and
repo-wide) is the house style and is left alone.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…quest

A --conversation with an empty turns list crashed determinism_check at
turns[0] after the passes, and under --no-determinism summarized zero
turns as complete: true with null totals and exit 0. load_conversation
now refuses a conversation with no turns, a turn without an integer id
or a non-empty text, or a repeated id (the fixture cache is keyed on the
id, so twins would share one recording); main exits 2 before contacting
Studio.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…model work

Only the fixed reports/ directory was created, so an --out under a
directory that did not exist yet raised FileNotFoundError after every
pass had run. prepare_report_path now resolves the report path right
after argument parsing, creates its parent (and reports/, where
latest.json goes), and rejects an --out that names a directory; main
exits 2 before contacting Studio.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…-loopback Studio

get_token minted (or reused) a key for the local auth database whatever
--base-url / UNSLOTH_BASE_URL pointed at, then sent that reusable local
secret to the remote host as a bearer. A non-loopback base URL now
requires --token or UNSLOTH_BENCH_TOKEN (a credential issued by that
server); otherwise main exits 2 before importing mint_token. Loopback
means 127.0.0.0/8, ::1, or "localhost"; an unparseable or host-less URL
counts as remote.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…sidecar hash

Replacing a synthesized turn_N.wav with a real recording, as the README
invites, left the sidecar saying source: "synthesized", so a later text
edit re-synthesized over the recording instead of raising
FixtureMismatch. The sidecar now records the sha256 of the bytes it
describes; a wav whose hash no longer matches is adopted as "supplied"
(pinned to the current text, like a sidecar-less drop-in) and is never
overwritten. A sidecar from before hashes existed is backfilled on the
next read; it cannot see an earlier replacement, and the README says to
delete it in that case.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
… time

The server's ChatCompletionRequest rejects a temperature outside 0..2 and a
max_tokens below 1, but argparse accepted them, so the error surfaced on the
first measured pass, after the warmup and fixture synthesis had already run
(and possibly paid for external TTS), as an incomplete report rather than a
setup failure. Same bounds, applied where --repeats already applies its own.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…anything

status.is_audio describes only the resident model. With OpenAI auto-switch on,
an explicit --model naming a TTS model made every chat_stream() request switch
the main slot to it and answer with speech, which this client reads as an empty
completion -- an incomplete report after warmup and fixture work, with Studio
left on the voice model.

Two checks, because neither covers everything alone. explicit_model_is_audio
rejects a model /api/models/list reports as audio, before warmup; that
catalogue carries only default and loaded models, so a downloaded-but-unlisted
one is caught by warmup_produced_text, which stops the run between warmup and
fixture synthesis. Under --no-warmup neither can fire, and the README says so
rather than implying the gap is closed.

Co-Authored-By: Claude Opus 5 <[email protected]>
…ones

The harness synthesizes the opening clause and then the whole reply, so it
makes two TTS calls per turn, but turn_wall_s summed only the second. The
printed "TOTAL full-pipeline wall" was therefore below what the run actually
spent, by one first-chunk synthesis per turn.

The arithmetic was right for what it models and wrong for what it was called.
stt_s + llm_total_s + tts_full_s is a non-streaming client that synthesizes
once after the reply has streamed; such a client never makes the first-chunk
call, so folding tts_first_s in would have made the model wrong to fix a label.
Instead harness_wall_s records real elapsed across every request the turn made,
the two derived numbers are labelled as the models they are, and the README
tables all three with which one is measured.

The timer starts once the input fixture is in hand: fixture synthesis is
one-time setup, and charging it would make a cold first run read a third slower
than a warm one for no reason the pipeline controls.

pipeline_wall_s keeps its key and its meaning, so baselines recorded against it
stay comparable, and diff_baseline skips the new row for a report that predates
it (test). Tests cover both ends of the measured span; verified by mutation --
starting the timer before the fixture, and folding tts_first_s into turn_wall_s,
each fail a test.

Co-Authored-By: Claude Opus 5 <[email protected]>
…by noise

The first version of these two tests slept the same amount in every client
call, so the fixture-exclusion bound sat 100ms from the passing value and the
fake reported stage times unrelated to what it had actually spent. Both are
the same defect: a timing assertion is only worth the margin it clears, and a
fake whose reported cost is fiction cannot say how two measurements compare.

The fixture call now sleeps 20x the calls on the measured path, so excluding it
is visible in the magnitude rather than in a hundred milliseconds. And every
fake call reports exactly what it slept, matching the real client, which times
its own requests with perf_counter and returns that; the modelled wall is then
three stage times and the measured one clears it by a whole fourth call.

Still fails under both mutations (timer before the fixture; tts_first_s folded
into turn_wall_s). studio/benchmarks is not collected by any workflow, so this
is about a maintainer running it locally.

Co-Authored-By: Claude Opus 5 <[email protected]>
Unsloth Studio only hands a saved connection's key to a sign-in session, never
to an sk-unsloth API key, so with the auto-minted key every /v1/audio/speech
call through --tts-provider-id reached the connection with no credential. That
route now mints a 12-hour session token for the local Unsloth Studio, and an
sk-unsloth key passed through --token or UNSLOTH_BENCH_TOKEN is refused up
front. Tests added.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants