The Art of Inferencing
Six controlled experiments, one 13 MB culprit, and the serving stack behind Sarj's Urdu voice. How we run a 4-billion-parameter speech model with a 4-bit backbone in a live product.
This is the story of a 4-billion-parameter language model that speaks. Since October 2026 it has been the Urdu voice on Sarj’s platform. For a single request on an idle server with one NVIDIA L4, the first sound streams in 0.36 seconds. In a load test that doubled traffic from 60 to 120 requests a minute, a client in another region received the first sound in 0.52 seconds at the median and 0.94 seconds at the 95th percentile, while the service added servers on its own.
The hard part was not shrinking the model. It was finding out, through controlled experiments, which parts could be compressed and which could not. The main culprit behind broken speech turned out to be one 13 MB file.
This post is for teams putting a large speech model behind a live product. It covers what we measured, what broke, the ideas that did not survive testing, and the serving stack we built around the answers.
Every number is our own measurement, and its limits are listed near the end of the post. Three of the faults can be heard, before and after the fix, in Listen for yourself.
Results first
- 9 of 10 test sentences end naturally in an offline run of the final settings, up from 4 of 10 in the first compressed build. Through the deployed streaming path, 8 of the same 10 end naturally and the loop guard stops the other 2 at about their natural end. The test set is ten sentences, so these are counts and not rates.
- Seamless streaming: chunk boundaries went from 7–14 dB to 46–52 dB signal-to-noise against a full decode.
- 6× smaller deployable image: 29.9 GB down to 4.9 GB.
- 11× faster cold start: about 37 minutes down to about 3.3.
- 0.36 s to the first sound for a single request on an idle server, timed on the server, on one NVIDIA L4 with 300 GB/s of memory bandwidth. This is the best case. On the RTX PRO 6000 that already serves our omni TTS, we estimate about 0.13 s; the Urdu model has not run on that card yet.
- 2.3× faster than real time: a second of speech takes under half a second to generate, on the same L4.
- 120 requests a minute through the public endpoint in a 2,730-request load test, while the fleet grew from 4 to 9 servers. Measured at a client in another region, first audio was 0.52 s at the median and 0.94 s at p95, and 98.6% of requests were served on the first attempt.
A 4-billion-parameter model that has to talk
What it takes to say one second
The model reads text and writes speech as tokens, the way a chat model writes words. Each step writes eight tokens, one in each of eight streams the codec calls codebooks. The streams are staggered, each one a step behind the last, so a single 40-millisecond frame of speech takes eight steps to finish.
Figure 1: One frame of speech is eight tokens. Each step of the model writes one token in every row; the highlighted diagonal is a single frame.
A separate codec turns the finished tokens into a 24 kHz waveform. The model writes 25 frames for every second of audio. To keep up with a live call it must finish a step every 40 milliseconds, and each step is a full pass through all 4 billion parameters.
Five demands at once
For a live voice agent, that model has to meet five demands at once:
- Start fast. Every few hundred milliseconds before the first sound is silence the caller hears.
- Stay ahead of playback. Generation must beat real time, or the audio stutters.
- Never glitch. No loops, no buzzing, no clipped words, one steady voice.
- Serve many calls at once on the same hardware.
- Scale with demand without paying for idle capacity.
Our first version served the full-precision model on a general-purpose serving stack. It became our quality reference, but its image was 29.9 GB and a new server took about 37 minutes to come up. A system that needs 37 minutes to add capacity cannot follow live traffic, so we set out to compress the model without the listener noticing.
Figure 2: Container image size, and the time for a new server to become ready. Cold start is about 37 minutes before and a median of 3.3 after.
Hunting the loop: six experiments, one 13 MB culprit
We ran six controlled experiments to find out exactly which parts of the model survive 4-bit compression. The main culprit was one 13 MB file. Behind it sat a second problem that only showed once the first was fixed.
The model ships as five separate graphs: a text embedding, an audio embedding (the bridge that feeds generated audio tokens back into the language model), the language-model decoder, the audio heads (which pick the next audio tokens), and the codec.
The test bench: ten sentences, fixed seeds, one reference
- 10 Urdu sentences, from about 3 to 30 seconds of speech, each with a fixed random seed so every run is repeatable.
- A reference: the full-precision model’s output for the same sentences.
- Four measures per clip: does it end naturally or get stopped by the loop guard, how long it runs against the reference, how loud it is, and how it sounds to a listener.
Experiment 1: fast, and broken
The public 4-bit export was fast, with first audio in 0.32 s. But only 4 of 10 sentences ended naturally. The loop guard stopped the other 6, and 3 of those were cut mid-sentence: one stopped at 3.8 s of an 11.6 s sentence. That sentence is the first clip in Listen for yourself.
The guard is a last resort. It stops a sentence when the first codebook repeats one token for 32 frames, about 1.3 seconds of sound stuck in place.
Figure 3: Length of each test sentence from the first 4-bit build, against the full-precision reference. Each run picks a new speaker, so lengths vary; only an early stop is a fault.
Experiment 2: can we sample our way out?
A cheap fix would have been a setting. On the 6 failing sentences, we tried other seeds, a narrower token pool, and both a higher and a lower temperature.
Figure 4: The failing sentences that ended naturally under each sampling change.
No setting fixed it, and a lower temperature made it worse. The export’s own published validation pointed the same way: the 4-bit decoder matches full precision at a cosine similarity of 0.998, but the 4-bit audio heads pick the same top token only 87% of the time.
Experiment 3: is it us, or the model?
A loop could come from the model or from our own code. To separate the two, we ran the publisher’s reference script, unmodified, with the 4-bit and the 16-bit exports and the same seeds. The 4-bit export hit the loop guard on 3 of the 6 sentences we ran, one of them mid-sentence. The 16-bit export ended naturally on all 4 we ran.
So the loops were in the compressed model: the reference script contains none of our serving code. One result did not fit, though. The script finished a sentence that our server had cut, so something in our own path differed too. We come back to that in the parity section.
These are small samples, enough to find a cause and not enough to estimate a loop rate.
Experiment 4: swap one file, lose the loops
We kept the 4-bit decoder and swapped in only the 16-bit audio heads, a 42 MB file. All 3 sentences that had looped now ended on their own. The loops followed the 13 MB heads, not the 4-billion-parameter backbone.
Figure 5: The three looping sentences under four builds. Each cell shows the audio length and how the sentence stopped.
One of the three came out shorter than the reference, a reminder that a clean ending is not proof of a complete sentence. That is why every change also had to pass a human ear.
Experiment 5: real-world settings
At the sampling we serve (temperature 0.8, top-k 50, top-p 0.8), the hybrid build ended naturally on 8 of 10 sentences, with no mid-sentence cuts. Two problems remained.
- Narrower sampling loops more easily. With fewer tokens to choose from, the model is more predictable, and a predictable model can lock onto one sound. One sentence ran to 19 s where the reference took 11, and another came out nearly silent.
- The speaker was random. Each request came out in a different voice, and loudness swung from −13 to −55 dBFS.
Experiment 6: finding its voice
We gave the model one fixed reference voice: a short clip and its transcript, which add 392 positions to every prompt. The clip is the full-precision model’s own speech, not a recording of a person.
Natural endings rose to 9 of 10, both problem sentences from experiment 5 now ended on their own, and loudness held between −21 and −24 dBFS. One long sentence still hit the loop guard.
Figure 6: Natural endings and loudness for each build. The first build ran on the server; the other two are offline runs with the same seeds.
The clip is encoded offline, so the audio encoder never ships with the server.
What we ship: a 4-bit brain with a 16-bit voice
Natural endings went from 4 of 10, to 8 of 10, to 9 of 10. The build that got there keeps the backbone at 4 bits and spends precision only where the listener hears it:
| Part | What it does | Precision served |
|---|---|---|
| Language-model decoder (4B) | Predicts the speech, step by step | 4-bit |
| Audio heads | Pick each next audio token | 16-bit, swapped in |
| Audio embedding (the bridge) | Feeds each new token back into the decoder | 4-bit weights, 32-bit output |
| Text embedding, codec | Read the text; turn tokens into sound | As exported |
Figure 7: The build we serve, by the precision of each part.
Each new audio token loops back through the bridge into the 4-bit decoder. Only the heads, which pick what the listener hears, run at 16-bit.
The deployed build then faced the same ten sentences through the full streaming path. Eight ended naturally, and two hit the guard at about their natural end. A wider check on 30 sentences then found one that lost its last word, which sent us back to the guard itself, as we describe below.
Sixty-three ties: chasing bit-for-bit parity
Before optimising anything, we made our server produce exactly the tokens the reference produces. Every later speed-up could then be checked against known-good output instead of judged by feel.
At first, the same seed drifted from the reference within 6 to 20 steps. We logged 63 divergence events, and every one was a tie: with 16-bit scores, tokens of equal probability often sit right on the top-p cut-off, and our sort broke ties in a different order.
Figure 8: Why equal scores drifted from the reference. Both sorts see the same probabilities, but keep a different token.
We rewrote the sampler with the reference’s exact operations (descending argsort, normalised inverse CDF). Scores and tokens then matched the reference bit for bit, and our server’s audio matched the approved clips to within 1–2 least-significant bits.
Where the 97% hides: making streaming seamless
We stream audio in small chunks while the model is still writing. We measured exactly where chunking hurt the sound, then fixed it with settings taken from data.
Finding the error
We encoded full-precision reference clips into tokens, then decoded them twice: once whole, and once in our streaming chunks. 97% of the error energy sat in the last 4 frames before a seam, and 78% in the very last frame. The codec looks at future tokens as well as past ones, so a chunk decoded without its future smears its last ~40 ms at every seam, a little more than twice a second.
Figure 9: Where chunked decoding differs from a full decode, by frames before the seam.
Sizing the fix
Each chunk now waits for a few future frames before it is decoded, then discards the audio it made for them. A caller hears the first chunk after 18 frames: 10 to play and 8 to look ahead. Each later chunk plays 12 frames and is decoded with 8 frames that were already played and 8 of lookahead, 28 in all.
Figure 10: The first three chunks of a stream. A chunk decodes 18 frames the first time and 28 after that.
Longer chunks alone do not solve it. 25-frame chunks without lookahead scored only 13–20 dB, while an 8-frame lookahead reached 46–52 dB. A chunked decode and a whole decode of the same tokens are side by side in Listen for yourself.
Figure 11: Signal-to-noise of the streamed audio against a full decode, for each chunk setup.
The lookahead costs about 0.2 s of first audio, a trade we made on purpose.
Thresholds from data, not guesses
A buzz before a loop stops is as bad as the loop, so we needed a rule for when to stop trusting the audio. In natural speech, the first codebook repeats one token for at most 7 frames at the 99th percentile. Past 7, frames are held instead of streamed, and a real loop is cut with a 20 ms fade, so the listener never hears a buzz or a click.
The word that went missing
On the deployed build, one sentence lost its last word in every run we tried. The guard had done its job too well. After the last word, the model can sit on a silence token instead of writing its end-of-speech token. Our guard counted those frames as a loop, and its trim cut into the end of the word.
We found 29 tokens that decode below −55 dBFS. Natural pauses repeat one of them at most 4 times, so a run of 16 (0.64 s) now ends the sentence, with nothing held back and nothing trimmed. The end of the missing word came back, and trailing silence fell from 2.1 s to 0.6 s. Both versions are in Listen for yourself.
Figure 12: How the server treats a token that the first codebook repeats.
Every change was checked by ear on fixed prompts and seeds before it shipped.
A server with exactly one job
We wrote our own inference server on ONNX Runtime instead of using a general-purpose engine. Serving one model let us remove every step that did not need to happen. It speaks an OpenAI-style speech API and streams 24 kHz audio.
- The model’s working memory stays on the device. Each request slot’s attention cache is allocated once at startup and updated in place. Memory use is fixed from the first second, and only the next-token scores cross back to the host each step.
- Measured admission. We cap concurrent streams per server at the highest count that never stalls audio, found by measurement. On one L4 that count is three; a fourth stream stalled playback. A request over the cap waits up to 0.5 s for a slot, then gets a clean “busy, retry” response.
- A warmed codec session per chunk size. The first codec call dropped from 65 ms to 4 ms, cutting first audio by 56 ms with byte-identical output.
- The voice prompt is computed once. The 392-position voice prompt is pre-filled into every slot at startup, so a request processes only its own text. Prefill fell from 113 ms to 55 ms, and first audio by 58 ms. We confirmed by ear that this did not change how sentences end before switching it on.
- Together: first audio for a single request went from 0.473 s to 0.357 s, on one NVIDIA L4.
- A hang-up frees the slot. When a caller disconnects, generation stops at the next step.
Figure 13: First audio for a single request on one server with one NVIDIA L4, before and after each change.
We also measured batching several streams through the decoder at once. Each extra stream added about 5.2 ms per step, which left too little extra capacity at this model size to justify the complexity, so we left it out for now.
The 300 GB/s speed limit
What the L4 allows
Every serving time in this post was measured on an NVIDIA L4, a 24 GB card with 300 GB/s of memory bandwidth. Bandwidth matters here because every step reads the decoder’s 2.05 GB of weights once. At 300 GB/s that read takes at least 6.8 ms, and our measured decoder step is 10.7 ms. Most of each step is the card reading the model.
What an RTX PRO 6000 would change
Our omni TTS, another speech model we run in production, already runs on an RTX PRO 6000: 96 GB and 1,597 GB/s, 5.3 times the L4. Before we moved it, we sent the same 40 prompts to both cards, one at a time. Median first audio, timed on the server, fell from 284 ms to 88.5 ms, 3.2 times faster.
The Urdu model has not run on that card yet, so we estimated it from the L4’s own step timings, under three assumptions:
- Best case: all work on the card speeds up by the full 5.3× of bandwidth.
- Expected: it speeds up by the 3.2× we measured on omni TTS.
- Cautious: only reading the weights gets faster.
In all three, the work outside the card, such as sampling, stays as slow as it is today.
Figure 14: Time to process a request on the L4 (measured) and on the RTX PRO 6000 (estimated; this model has not run on it yet).
Omni TTS is a different kind of model, so its gain is a guide and not a promise. Before a caller hears Urdu from the faster card, it has to pass the same single-server check and listening test as every other change.
Measure, simulate, then hammer it
The service adds and removes servers on its own, driven by what the model is doing rather than by CPU load.
- Model-aware autoscaling. Two signals from the model server drive it: requests in flight, and the rate of busy responses.
- We tested our assumptions. Our first design counted on the load balancer to retry a busy request. The load test showed it never retries this kind of request: 45 busy responses at the client matched exactly 45 at the server. We moved that job into a short wait inside the server and the caller’s own retries.
- We tuned with a simulator. A discrete-event model of slots, queues, routing and the autoscaler reproduced the first load test: 44 busy responses predicted, 45 observed. We used it to choose the autoscaler settings before running the second test.
Both tests ran against the public endpoint from a client in another region, with one NVIDIA L4 per server. The first climbed from 10 to 60 requests a minute with the fleet capped at four servers. It sent 716 requests, with a p95 first audio of 1.17 s and 93.7% served on the first attempt. It showed us that capacity has to be there before the ramp, and that our first autoscaler settings would hold too few servers at a steady load.
Before the second test we shipped both latency changes, retuned the autoscaler, and started from four warm servers. Traffic then doubled from 60 to 120 requests a minute over 2,730 requests.
Figure 15: The second load test, minute by minute: requests sent, servers ready (one L4 each), and p95 first audio.
The test held a p95 first audio of 0.94 s (0.91 s at the steady 120 requests a minute), and 98.6% of requests were served on the first attempt, with no other errors. A new server was ready in about 3.3 minutes (median).
This is a modest load. 120 requests a minute is two a second, served at the peak by nine L4s with up to three streams each. The test shows that the service follows a doubling of traffic on its own. It does not show high volume.
Built to run while we sleep
The service was built to run unattended from day one.
- Reproducible builds. Model weights are pinned to an exact upstream revision and verified by checksum before they enter an image. Every image traces back to a source commit.
- Health checks that mean something. A server takes traffic only after the model has loaded, its outputs pass sanity checks, and a warm-up request succeeds. A failed engine restarts itself.
- Rollouts that drop no calls. Servers drain before they stop, and new ones must prove healthy before they take traffic.
- Least privilege. Each server gets only the access it needs to serve the model.
- Observable. Model-level metrics for requests in flight, time to first audio, duration, speed and how each utterance ended feed our monitoring and alerting.
The process mattered as much as the code. Every phase ended at a review gate, every change got an independent review, and nothing went live until it passed a single-server check and a listening test.
The scorecard
| What | Result | How it was measured |
|---|---|---|
| Natural sentence endings, offline | 4 of 10 → 9 of 10 | Fixed Urdu test set of ten sentences, fixed seeds |
| Natural sentence endings, deployed | 8 of 10, and 2 stopped at about their natural end | Same ten sentences through the streaming server |
| Loudness spread | −13…−55 dBFS → −21…−24 dBFS | Same test set, before and after the reference voice |
| Streaming seam quality | 7–14 dB → 46–52 dB | Signal-to-noise vs a full decode |
| Deployable image | 29.9 GB → 4.9 GB (6× smaller) | Built images |
| Cold start | ~37 min → ~3.3 min (11× faster) | New server to ready |
| First audio, one request, idle server | 0.36 s | Server timing, one NVIDIA L4 (300 GB/s) |
| First audio, one request, RTX PRO 6000 | about 0.13 s (0.09–0.22 s) | Estimate, not yet measured on this model |
| Generation speed | 2.3× faster than playback | Real-time factor 0.44 (p95), one stream, one L4 |
| Load test | 60 → 120 requests/min, 2,730 requests | Public endpoint, 4 → 9 servers, one L4 and up to three streams each |
| First audio under load | p50 0.52 s, p95 0.94 s | Same test, remote client |
| Served on first attempt | 98.6% | Same test |
What these numbers do not show
- The test set is small. The experiments use ten sentences and the wider check uses 30. “9 of 10” is a count on those sentences from an offline run, not a failure rate. Through the deployed streaming path the count is 8 of 10.
- One test sentence is also the voice prompt. The transcript of the reference voice clip is one of the ten test sentences. That sentence already ended naturally in experiment 5, before the voice was added, so it does not change the step from 8 to 9.
- Quality was judged by ear. We measured how each sentence ends, its length, its loudness and the seam signal-to-noise. We did not measure listener scores, word error rate or speaker similarity.
- 0.36 s is the best case. It is one request on an idle server, timed on the server. Under load and measured at a remote client, first audio is 0.52 s at the median and 0.94 s at p95.
- First audio covers the speech step only. A voice-agent turn also spends time on speech recognition, turn detection and the language model.
- The load is modest. The largest test peaked at two requests a second on nine L4s.
- The RTX PRO 6000 figure is an estimate. The Urdu model has not run on that card.
- Nothing here has been reproduced outside Sarj. Every number is our own measurement on our own test set. The audio clips let you hear three of the faults. They do not prove the counts.
What we would do again
A model that speaks is a chain of parts with different tolerances. Treating precision, streaming, serving and scaling as one measured system let us keep the backbone at 4 bits and spend precision where it is heard. Each experiment stayed small: ten sentences, one change, one ear. That is the part we would reuse on the next model.
Next: every millisecond counts
- Lower first audio still. A faster card, serving closer to callers, and batching full decoding steps across streams are the next levers. We have not yet measured the first or the last on this model.
- The same method for every model. Isolate each part, verify against the reference, listen, simulate, then load-test. Our deployment steps are written into an internal runbook, so the next model starts from this one.
Acknowledgments
Thank you to the engineers across modelling and platform at Sarj who built, reviewed and listened to every version of this. We build on a publicly released speech model, and on the public ONNX exports and published validation that made the part-by-part experiments possible.
References
- ONNX Runtime.
- NVIDIA, L4 specifications.
- NVIDIA, RTX PRO 6000 Blackwell Server Edition specifications.
Listen for yourself
Three faults from this post, before and after the fix. Every clip is the model's own output for a fixed sentence and seed, and none is a recording of a person. The clips are compressed to AAC for the web.
A sentence cut mid-way
The first 4-bit build stopped this sentence a third of the way in. With the 16-bit audio heads swapped in, it ends on its own.
السلام علیکم، آپ کی مرمت کا وقت کل صبح دس بجے طے ہو گیا ہے، اور ٹیکنیشن آنے سے آدھا گھنٹہ پہلے آپ کو فون کر کے وقت کی تصدیق کرے گا۔
Peace be upon you. Your repair is booked for ten o'clock tomorrow morning, and the technician will call you half an hour before arriving to confirm the time.
A seam, with and without its future
The full-precision reference clip, encoded into tokens and decoded twice. The deployed clip above is streamed with 8 frames of lookahead.
السلام علیکم، آپ کی مرمت کا وقت کل صبح دس بجے طے ہو گیا ہے، اور ٹیکنیشن آنے سے آدھا گھنٹہ پہلے آپ کو فون کر کے وقت کی تصدیق کرے گا۔
Peace be upon you. Your repair is booked for ten o'clock tomorrow morning, and the technician will call you half an hour before arriving to confirm the time.
The word that went missing
The loop guard counted the silence after the last word as a loop, and its trim cut into the word.
آپ کا اکاؤنٹ اب مکمل طور پر فعال ہو چکا ہے۔
Your account is now fully active.