I once reported that a text-to-speech model took 31 seconds to say five Chinese characters.
The real number is 2.2 seconds.
Same machine, same model, same checkpoint, same input string. One constructor argument was different. I had already written 31 seconds into a design document and started planning around it — a queue, a pre-generation cache, a fallback to a smaller model. All of that was solving a problem that did not exist.
This article is about the measurement mistakes that produced that number, and the shape of the data that would have caught it immediately.
Everything below comes from one machine: an RTX 5060 with 8 GB of VRAM, PyTorch 2.8.0 with CUDA 12.8, IndexTTS2 running in bf16. The numbers are small and the hardware is modest, which is exactly why they are useful — the same structural problems show up on an H100, just with different constants.
1. The number that made me rewrite the benchmark
The argument I got wrong was use_fp16 versus use_bf16.
My first harness passed use_fp16=False. That reads like "don't use half precision, use full precision, be safe." On an 8 GB card it means the fp32 weights do not fit alongside the activations. PyTorch does not fail loudly. It falls back to a slower path, shuttles tensors between host and device, and every single inference pays that cost again.
Five characters: 31 seconds.
Then I copied the constructor flags out of the service code that was already running in production — use_bf16=True, device="cuda", use_cuda_kernel=False, use_deepspeed=False, use_accel=False, use_torch_compile=False — and measured again.
Five characters: 2.20 seconds.
A factor of 14, from a flag I had set to be careful.
The lesson is not "use bf16." The lesson is that you are not measuring the model. You are measuring the model plus every decision in the call path, and the call path is invisible in the output. A benchmark that does not record its own configuration is not a benchmark, it is an anecdote with a decimal point.
2. Fixed cost and marginal cost are two different things
Here is the corrected measurement, warm, bf16, one line per input:
| Characters | Latency (s) |
|---|---|
| 5 | 2.20 |
| 14 | 3.49 |
| 22 | 4.47 |
| 45 | 8.51 |
Character count grows by 9×. Latency grows by 3.87×.
That gap is the whole story. If latency were proportional to work, 45 characters would take about 19.8 seconds. It takes 8.51. Something in there does not scale with input length, and it is not small.
Fit a line through the four points — ordinary least squares, nothing clever:
latency ≈ 1.258 + 0.1586 × characters R² = 0.995 Two terms, and they mean completely different things.
1.258 seconds is a floor. It does not care how long your input is. It is the text frontend, the phonemizer, the fixed number of acoustic decoder steps, the vocoder's fixed window, the Python dispatch, the kernel launches. You pay it whether you say "hi" or recite a paragraph.
0.1586 seconds per character is the actual work. This is the part that responds to a faster GPU, a smaller model, a better kernel.
On a 5-character line the floor is 61% of the total. On a 45-character line it is 15%. Same floor, wildly different weight, because the denominator changed.
3. Which makes "average latency" a meaningless number
Take that one machine. Change nothing. Change only the distribution of input lengths you send it.
If your traffic is short conversational turns — 5 characters — the average is 2.05 seconds.
If your traffic is reading a document aloud — 45 characters per line — the average is 8.40 seconds.
A 4.1× difference in the headline number, with zero change to the system.
This is not a subtle statistical point. It is the reason two engineers can benchmark the same service, both be honest, and publish numbers that disagree by 4×. One tested a chat interface, the other tested a reader. Neither one wrote down the input length distribution, so neither number can be reproduced or compared.
Latency without an input-length distribution is not a measurement. Report the fit, or report latency at several fixed lengths, or report both. A single mean over an undocumented mix is noise dressed as precision.
4. Warm-up is not optional, and it is not what you think
Model load on this machine takes 22.3 seconds. That is reading 3 GB of weights off disk and building the module tree, and it is genuinely separate from inference.
But "warm" means more than "loaded."
The first actual inference pays for things the load did not: CUDA context creation on first kernel launch, cuDNN algorithm search, the allocator carving its first blocks out of a fresh pool, and — if you enabled torch.compile — graph capture and compilation. On some stacks the first call is 5–10× the steady-state cost.
I have seen three ways people get this wrong, all in the same week:
- Report the first call as if it were steady state, and publish a number that is 8× too slow.
- Warm up once with a three-word input, then measure a 500-token input that triggers a different code path and a different memory shape.
- Warm up, measure, and forget to note in the results that a warm-up happened, so nobody can reproduce it.
The minimum defensible procedure: run at least one input as long as your longest test case, discard it, then start timing. Record in the output that you did this.
5. Percentiles need enough samples to exist
Four data points cannot produce a p95. Twenty samples can produce a p95 that means something. A p99 needs a hundred or more.
This matters more on GPUs than on CPUs because of the shape of the tail. Steady-state inference is remarkably consistent — the four numbers above fit a line with R² = 0.995. But occasionally a request lands while the allocator is consolidating memory, or another process grabs the device, and that one request takes ten times as long.
That bimodal tail is invisible in a mean and invisible in a p50. It is the reason a service can have a beautiful average and still feel broken to users, because users remember the one request that took twelve seconds.
If you only have budget for a handful of runs, report the minimum, the maximum, and the count. Do not compute a percentile you cannot support.
6. What "it feels fast" is actually measuring
The 8.51 seconds above is time to completion — the whole 45-character clip, encoded to a file, done.
That is not what a user experiences.
If the service streams, the first audio chunk can be ready long before the last one. On this model the first chunk typically lands in the first second or so; the remaining eight seconds are generation, not waiting. If the service batches, the user hears nothing for 8.51 seconds and then gets everything at once.
Same service, same hardware, same 8.51 seconds — and one feels instant while the other feels broken.
So before measuring anything, decide which quantity your product is actually constrained by:
- Time to first chunk, if audio or tokens are streamed and the user starts consuming immediately.
- Time to completion, if the output has to be assembled before it is used — a file, a subtitle track, a batch job.
- Time to first usable result, which for a pipeline is often neither of the above.
Benchmark the one your users are waiting on. Measuring completion time for a streaming product will tell you to optimize the wrong half.
7. A minimal harness that reports both terms
The whole fix is about forty lines. Measure at several lengths, fit the line, report the intercept and the slope alongside the raw samples.
import json, statistics, time def measure(fn, inputs, warmup=1): """fn(text) -> None. Returns per-length latency samples.""" # Warm up on the longest input so the first-call costs land here, # not in the measurement. for _ in range(warmup): fn(max(inputs, key=len)) samples = {} for text in inputs: t0 = time.perf_counter() fn(text) dt = time.perf_counter() - t0 samples.setdefault(len(text), []).append(dt) return samples def fit(samples): """Least squares of latency on input length. Returns (intercept, slope, r2).""" xs, ys = [], [] for n, dts in samples.items(): for dt in dts: xs.append(n) ys.append(dt) k = len(xs) mx, my = sum(xs) / k, sum(ys) / k sxx = sum((x - mx) ** 2 for x in xs) sxy = sum((x - mx) * (y - my) for x, y in zip(xs, ys)) slope = sxy / sxx intercept = my - slope * mx ss_tot = sum((y - my) ** 2 for y in ys) ss_res = sum((y - (intercept + slope * x)) ** 2 for x, y in zip(xs, ys)) r2 = 1 - ss_res / ss_tot if ss_tot else float("nan") return intercept, slope, r2 samples = measure(tts_infer, ["你好啊", "你是谁", "今天天气不错我们出去走走", "..."]) intercept, slope, r2 = fit(samples) print(json.dumps({ "fixed_cost_sec": round(intercept, 3), "marginal_sec_per_char": round(slope, 4), "r2": round(r2, 3), "samples_per_length": {str(n): len(v) for n, v in samples.items()}, "raw": {str(n): [round(x, 3) for x in v] for n, v in samples.items()}, "warmup_runs": 1, "config": {"precision": "bf16", "device": "cuda"}, }, ensure_ascii=False, indent=2)) Three things in that output do the real work. fixed_cost_sec is the number that decides whether you need streaming. marginal_sec_per_char is the number that responds to hardware. r2 tells you whether a line was even the right model — if it comes back at 0.7, you have a knee in the curve and a two-term fit is hiding it.
The config field looks like boilerplate. It is the field that would have saved me the 31-second detour.
8. Reading the output: three shapes
Once you have the fit, the shape tells you what to fix.
Large intercept, modest slope. Fixed cost dominates. This is my machine: 1.258 s of floor against 0.159 s per character. Buying a faster GPU barely moves the number for short inputs. What helps is removing work from the frontend, batching the small requests together, or — most effective — streaming so the floor is paid in parallel with generation instead of before it.
Near-zero intercept, steep slope. Pure compute. You are limited by FLOPs or memory bandwidth and the fix is hardware, quantization, or a smaller model. This is the good failure mode, because the scaling is predictable.
A knee. Latency tracks a line up to some input length and then jumps. On a memory-constrained card this is usually the point where the KV cache or the activation buffer stops fitting in the remaining VRAM and the allocator starts evicting. Below the knee, adding characters is cheap; above it, each one costs several times more. A single linear fit will report a mediocre R² and you will be tempted to blame measurement noise. Do not — the knee is the finding.
9. What this does not tell you
The harness above answers one question: how long does one request take, as a function of its length, on one device, at concurrency one.
It does not tell you:
Whether the output is any good. Speed and quality trade against each other here. My model produces noticeably flatter prosody on long inputs — the pitch variance collapses past roughly 30 characters. Nothing in the latency table shows that, and optimizing for the table alone would push toward longer inputs that sound worse.
Anything about throughput. Single-request latency and requests-per-second under load are different curves. On 8 GB, concurrency two already starts to queue, and the second request's latency is not the first request's latency. If your product serves more than one user, measure at the concurrency you actually run at.
Anything about the real input distribution. My four test strings are ones I wrote. Real traffic has a distribution, and if that distribution is bimodal — a lot of very short turns and a few very long ones — the mean is a number that describes almost no actual request.
Whether the floor is avoidable. 1.258 seconds might be irreducible for this architecture, or it might be a synchronous call that could overlap with something else. The fit tells you the floor exists and how big it is. It does not tell you what is inside it. For that you need a profiler, not a stopwatch.
That last point is the one I keep relearning. A latency table is not an explanation. It is a constraint you have to design around, and the most useful thing it can do is tell you which of your assumptions about where the time goes is wrong — as it did for me, at 31 seconds that were never real.
