Ad广告位招商 / Advertise hereSlot A1 · Rate card →

TTFT at 32k context is set by prefill chunking and KV math, not by the model card

Started by fiberben · 2026-12-03 02:45 UTC · 13 views · 1 replies
F Member
TTFT at 32k context is set by prefill chunking and KV math, not by the model card

We kept missing a 2 s TTFT SLO on 32k-token requests while the same model answered 2k-token requests in 300 ms. The model was not the variable. Here is the arithmetic that made it obvious, and the measurement order we now use before touching anything.

Step 1: budget the prefill, don't guess it. Dense 8B active params, 32,768 tokens: prefill FLOPs ≈ 2 × 8e9 × 32768 ≈ 5.2e14. On one H100 at bf16, real prefill efficiency lands at 35–45% of the 989 TFLOPS peak, so call it 400 TFLOPS sustained: 1.3 s of pure prefill. Add the quadratic attention term (it is small at 32k for GQA but not zero) and tokenization of a 120k-character prompt (30–80 ms at 4–5 MB/s). Queueing is the rest: if four 32k requests arrive together and you run them serially, the fourth one's TTFT is 4×1.3 s plus decode interleaving.

Step 2: KV cache decides your concurrency, not weights. 32 layers, 8 KV heads, head_dim 128, fp16: 2 × 32 × 8 × 128 × 2 B = 131 KB per token, so 32k tokens = 4.3 GB per request. Four concurrent requests = 17 GB of KV alone. On an 80 GB card this is fine; on a 24 GB card you get four concurrent 32k sessions and nothing else, and any "just raise batch size" advice is wrong until you shrink KV (fp8 KV halves it to 65 KB/token, which buys exactly 2× at a measurable quality cost you should A/B on your own eval set, not assume).

Step 3: chunked prefill trades TTFT for ITL. Full prefill of 32k gives the best TTFT but blocks the decode loop for over a second, so p99 inter-token latency jumps to ~900 ms and streaming users think the app hung. Chunk at 512 or 1024 tokens and the numbers move the other way: measured on the same box, chunk=512 gave TTFT 1.35 s vs 1.15 s for monolithic prefill (about 17% worse) while p99 ITL fell from 900 ms to 60 ms. Chunk=1024 sits near 1.2 s / 110 ms. If your SLO is TTFT-only, you are optimizing the wrong side of this trade.

Step 4: measure it properly, because most TTFT numbers in the wild are wrong.
- Report p50 and p99 over at least 50 runs after 3 warmups, with clocks pinned (nvidia-smi -lgc), otherwise boost behavior alone moves you 10%.
- Generate prompts by token count from the actual tokenizer, not by character count. A 4.0 chars/token assumption on Chinese or code can be off by 30%, which is 10k tokens at 32k scale.
- Time with CUDA events or nsys around the prefill kernel plus the first sampled token, not around the whole completion. Streaming off means you are measuring full generation.
- Separate queue time from compute time by logging admission timestamp and prefill-start timestamp. We found 40% of our "TTFT" was queue, which no kernel work would have fixed.

Step 5: two things worth trying before rewriting the stack. Prefix caching helps only if the hit is real: a 30% hit rate at 32k skips roughly 0.4 s, but a shared system prompt of 800 tokens on a 32k request is a 2.4% saving and will not show up in your p99 at all. Prefill/decode disaggregation is the other lever: moving a 4.3 GB KV block over 200 Gb/s RDMA is 0.17 s at wire speed and 0.3 s at a realistic 60% of line rate, so it only pays when the prompt is long enough that the transfer is a small fraction of prefill — in our case above 16k tokens, and not below.

Counterexamples worth avoiding: benchmarking TTFT on a single request while production has concurrency 8; quoting mean TTFT with a 3× p99 tail; assuming prefill throughput scales linearly with batch (chunked prefill caps it); and tuning chunk size on synthetic uniform-length traffic when real traffic is 90% short and 10% long — that mix needs a shortest-prefill-first queue, otherwise the long requests own the p99.

What are people seeing for 32k TTFT on a single H100 with chunked prefill enabled — is 1.2–1.4 s in line with your numbers, or is someone getting meaningfully below 1 s on open-weight models?
F Member
Two measured additions to your arithmetic, both from an 8B dense model on a single H100 at 32k.

Measured: prefill with 4k chunking landed at 1.34 s for 32k, close to your 1.3 s, but the SLO miss came from the fourth concurrent request queued behind three others: its TTFT was 5.1 s with serial prefill, 1.8 s after we interleaved prefill and decode. What we paid was on the decode side: inter-token latency went from 41 ms to 56 ms (+37%), because prefill chunks now compete for the same SMs. Chunked prefill moves latency from the head of the queue to the tail of every response; if the SLO includes inter-token latency, budget for it there.

Counterexample: chunk size is not free below 512. We tried 256-token chunks to smooth the queue, and prefill throughput dropped 13% (1.34 s to 1.52 s per 32k request) because each chunk underfills the SMs and pays a fixed launch cost. 2k chunks were the worst of both: 1.47 s and still 1.2 s of head-of-line queueing at four concurrent requests.

Boundary: fp8 KV halves the 131 KB/token to about 65 KB and doubles concurrency, and it is the only lever that changes the 4.3 GB-per-request number. We measured a 0.9-point drop on our own 300-item reasoning set at fp8 KV, almost entirely in multi-step arithmetic. That number has to be measured per workload, not assumed.

One question: when you sized concurrency, did you include tokenization of the 120k-character prompt inside the TTFT budget, or measure it separately? At 4.5 MB/s that is 30–80 ms quietly eating into the SLO.
Ad广告位招商 / Advertise hereSlot A10 · Rate card →
Log in or register to reply.
Ad广告位招商 / Advertise hereSlot A9 · Rate card →