Skip to content

Inference Optimization Boundaries: When Batching, KV Management, and Speculative Decoding Actually Pay Off ​

1. Scenario: Every Optimization Has a Range ​

vLLM is fast, KV quantization saves memory, speculative decoding accelerates — all with boundaries. This article uses the three ledgers from Part 1 to compute when each works and when it doesn't, so you don't blindly copy parameters. Engine measurements live in Chapter 12 (vllm-principles, vllm-production-deployment, speculative-decoding).

2. Continuous Batching: Amortizing the Bandwidth Ledger ​

Decode reads all weights per token; a single request is bandwidth-bound. Batching lets requests share one weight read:

B_per_token≈N×bytesbatch_sizeB\_per\_token \approx \frac{N \times bytes}{batch\_size}

batch70B FP16 weights read/tokenTheoretical TPOT floor (3TB/s)
1140 GB~47 ms
817.5 GB~5.8 ms
642.2 GB~0.7 ms

Boundary: bigger batches amortize bandwidth better, but memory (KV grows per request) and scheduling overhead rise. Continuous batching's value: it doesn't wait for the whole batch — requests enter/leave dynamically, keeping "effective batch" high. When is the gain largest? Dense arrivals and long outputs. In idle periods (sparse arrivals) there is almost no gain. Quantitative check: if effective batch < 4 and concurrency cannot rise, upgrading bandwidth or switching to MoE beats tuning batch parameters.

3. KV Quantization and Prefix Caching: Saving Memory and First-Token Latency ​

  • KV quantization (INT8/INT4): drops the bytes term in Part 1's KV formula from 2 to 1/0.5 — saves memory and KV read bandwidth, at some precision cost. When it works: long context/high concurrency where KV dominates (70B 32K ctx KV≈5.2GB → ≈1.3-2.6GB); short contexts gain little.
  • Prefix caching: requests sharing a common prefix reuse computed KV — saves duplicated prefill compute. When it works: fixed system prompts, RAG with shared document prefixes, multi-turn context — the higher the hit rate, the more valuable; random per-request prefixes gain almost nothing. The site's vllm-production-deployment already measures prefix-caching TTFT gains; this article adds the boundary: gain ceiling = duplicated prefill FLOPs / total FLOPs.

4. Speculative Decoding: Profitable Only When Verification Beats Autoregression ​

Speculative decoding drafts N tokens with a small model (or single-token predictor) and verifies them in one forward pass of the target model. Whether it pays off depends on two timings:

speedup≈N×tdraft+ttargettverify+tdraftspeedup \approx \frac{N \times t_{draft} + t_{target}}{t_{verify} + t_{draft}}

Intuition: verifying a batch of tokens costs the same compute as generating one token but with more parallelism — under small batches and bandwidth limits, a verification batch uses bandwidth better than one-by-one autoregression. Therefore:

  • Works: large target model (clear decode bandwidth bottleneck), high draft hit rate (code/structured text), small batch (compute to spare, bandwidth short).
  • Useless or negative: small target model (bandwidth not saturated), low draft hit rate (verification wasted), large batch (bandwidth already amortized, autoregression near the limit).

The site's speculative-decoding article gives the measurement workflow; this article adds the decision formula: measure target single-token latency tt and draft hit rate pp; if pp is low or batch already high, skip it when speedup <10%.

5. Optimization Applicability Quick Reference ​

TechniqueLedger savedEffective whenIneffective when
Continuous batchingbandwidthdense arrivals, long outputssparse arrivals, low effective batch
KV quantizationmemory + cache bandwidthlong context / high concurrencyshort context
Prefix cachingprefill computehigh prefix hit raterandom prefixes
Speculative decodingdecode latencylarge model + small batch + high hit ratesmall model / large batch / low hit rate
Weight quantizationmemory + weight bandwidthacceptable precisionprecision-sensitive tasks

6. Deployment Checklist ​

  • [ ] Measure current effective batch and bandwidth utilization before adding batch vs switching techniques
  • [ ] Compute KV share (KV/total memory) before KV quantization; below ~10% the gain is limited
  • [ ] Evaluate prefix caching by hit rate; don't enable blindly
  • [ ] Use the formula before speculative decoding; measure draft hit rate and single-token latency first
  • [ ] Recheck every optimization against Part 1's three ledgers — avoid "optimizing into a corner"

Method note: the boundary-condition quantification framework follows the open-source book Understanding AI Infra (Li Bojie, Apache-2.0); formulas and boundaries here are the site's own.

AI-HPC Expert · Contact: openaihpc@gmail.com