5

Techniques

Select optimization levers by bottleneck, quality budget, and topology.

12 min read

Printed pages: 117–152

Star on GitHub

In one breath

Optimization is a diagnosis problem. Quantization reduces compute and memory work but spends a quality budget. Speculation uses spare decode compute to improve inter-token latency (ITL) and tokens per second (TPS). Caching avoids repeated prefill and improves time to first token (TTFT). Parallelism makes models fit or changes latency and throughput across devices. Disaggregation separates compute-bound prefill from memory-bound decode at sufficient scale. Measure the bottleneck, apply the narrowest suitable lever, and retest the whole system because techniques can reinforce or obstruct one another.

Why it matters

  • Useful constraints create specialization: fixed formats, repeated prefixes, known topology, or separate worker roles let the runtime avoid general work. Real traffic varies, so these constraints must be monitored and adjusted rather than configured once.
  • Traffic volume changes what is economical. Cache-aware routing, many-way model parallelism, and independent prefill-decode pools need enough concurrent work to keep additional hardware and coordination useful.
  • Levers share resources. A smaller key-value cache can ease transfer and increase cache residency; speculation competes with large batches for compute; cross-node parallelism can replace a memory problem with a communication problem. Design and test the complete configuration rather than enabling features independently.
  • Most techniques preserve model semantics, but post-training quantization can change output quality. Performance validation therefore needs a paired quality baseline, especially when lowering precision in recurrently reused attention state.

Mental model

Think in four budgets: compute, memory capacity and bandwidth, communication, and acceptable quality change. Each technique moves pressure between budgets. Quantization stores and moves fewer bits while risking numerical error; speculation spends compute to reduce decode iterations; caching spends memory to avoid prefill; parallelism spends communication to gain capacity or concurrency; disaggregation spends hardware and transfer bandwidth to specialize phases. A good configuration removes the dominant constraint without making the receiving budget dominant.

Choose a lever from the bottleneck

A measured bottleneck branches toward Quantization for compute or memory pressure, Speculation for idle decode compute, Caching for repeated prefixes, Parallelism for device capacity or latency, and Disaggregation for high-volume prefill-decode interference.

  • Measured bottleneckProfile phase, resource, traffic, and quality budget
  • QuantizationReduce value width and memory footprint
  • SpeculationSpend idle compute to accept multiple tokens
  • CachingReuse prior key-value work
  • ParallelismShard model work across devices
  • DisaggregationSeparate prefill and decode worker pools
  • Measured bottleneckQuantization: Compute or memory pressure
  • Measured bottleneckSpeculation: Idle decode compute
  • Measured bottleneckCaching: Repeated prefixes
  • Measured bottleneckParallelism: Capacity or per-user latency
  • Measured bottleneckDisaggregation: Phase interference at scale

Suppose measurement shows compute-bound prefill, bandwidth-bound decode, and too little key-value cache headroom after weights and buffers. A precision change can reduce matrix cost, bytes moved, and cache footprint, but do not lower the whole model at once. First convert less-sensitive linear weights and compare perplexity, public benchmarks, and product evaluations with the original model; then add activations; consider key-value state only when long context or disaggregation is actually limited by cache capacity or transfer. Keep input-output layers, outlier-heavy regions, and attention math at higher precision when needed so recurrent errors do not compound token by token. At each stage measure time to first token, tokens per second, memory, throughput, and quality. The goal is not the fewest bits, but the lowest latency and cost while the quality difference remains within repeated-run noise.

For an interactive coding workload, put the stable system prompt, tool definitions, and repository context before the current edit and new question so prefix caching can skip substantial prefill. Route follow-up requests for the same user or codebase toward a replica with the hot cache, but cap affinity so one replica does not overload. During low-batch decode, repetitive code may yield long accepted n-gram drafts and fewer target-model forward passes. As concurrency and batch consume spare compute, shorten or disable speculation while prefix reuse still saves prefill. Track skipped input tokens, cache hits, draft acceptance, accepted tokens per iteration, and net inter-token latency separately; the techniques act on different phases and should not share one on-off switch or be judged only by total throughput.

When a model exceeds one GPU, include weights, runtime workspace, activations, target batch, and longest-context cache headroom before choosing a parallel label. Tensor parallelism (TP) splits tensors within every layer so GPUs share weight reads and matrix multiplication; fast intra-node links can lower per-user latency, but each layer synchronizes and scaling reverses when communication exceeds saved work. Expert parallelism (EP) places intact experts on devices and routes tokens without a TP-style all-reduce after every layer, so mixture of experts (MoE) throughput can scale farther, including across nodes. Pipeline parallelism (PP) assigns intact layer stages across nodes, introducing sequential bubbles; it is mainly a capacity solution when a dense model cannot otherwise fit. Prove each added device with parallel efficiency and interconnect traces. If the model fits comfortably in one node, another replica is often simpler and serves more independent requests.

Disaggregation becomes plausible when a large, heavily used model receives enough long uncached inputs for compute-bound prefill to disturb memory-bound decode. Send each request first to a decode-side cache check: handle full hits or short prefill locally, and send only long misses to the prefill pool. Prefill workers can use compute-oriented GPU count, TP, and batch settings; after producing the first token and key-value blocks, they transfer state over the chosen interconnect to decode workers tuned for bandwidth, cache capacity, and subsequent tokens. The pool ratio is an operating variable, not fixed one-to-one. A growing prefill queue asks for more front-end capacity; high decode occupancy or eviction asks for memory; slow transfer may require cache quantization, nearer topology, or a higher local-prefill threshold; light traffic may warrant collapsing the split to avoid idle GPUs.

Roll out one lever behind a controlled traffic slice and retain the unoptimized path plus fast rollback. Segment results by input and output length, cache hit or miss, batch, concurrency, hardware, and topology; a mean can hide long-context regressions or mistake a low-load gain for peak capacity. Gates should cover percentile latency, system throughput, GPU memory, unit cost, errors, and quality. Quantization also needs product evaluation, speculation needs acceptance across temperatures, and caching needs tokens skipped rather than hit rate alone. Observe a full peak cycle before increasing traffic. Keep triggers that disable the technique when its premise disappears: high batch stops speculation, a quality breach restores original precision, and an overloaded hot replica reduces cache affinity.

Treat the prefill-to-decode worker ratio as a workload-dependent setting. Long inputs and prefill-heavy traffic need more prefill capacity, while decode-heavy traffic needs more decode capacity. Monitor the prefill queue and decode key-value cache, and change the ratio at runtime as traffic changes instead of fixing one prefill engine to one decode engine. For short inputs or cache hits, conditional disaggregation can keep prefill on the decode engine. At lower traffic, horizontal replicas can be more efficient than disaggregation, whose extra GPUs, queue, and cache transfer add cost.

Document the causal chain for every lever: the measured phase and resource bottleneck, enabling traffic condition, budget receiving pressure, expected user or cost benefit, new failure mode, quality gate, disable threshold, and rollback. For example, 'low-batch decode has spare compute, so enable short-draft speculation and disable it when acceptance or net ITL falls below the gate' is more operable than 'enable EAGLE.' This record turns a configuration into an observable policy and makes the revalidation scope visible when another optimization changes the same compute, memory, or communication budget.

Core ideas

Quantization

Lower precision can accelerate prefill on faster low-precision compute and decode by reducing bytes moved. Start with less-sensitive weights and activations, consider key-value cache carefully, and protect attention operations and sensitive layers unless evaluation proves safety.

Format and granularity

Floating-point exponent range helps preserve outliers. Finer-grained scaling better follows local distributions but stores and applies more scale factors. January 2026 edition snapshot: 8-bit floating-point (FP8) class formats were the flexible production default; Blackwell-specific microscaling and 4-bit floating-point (FP4) paths required current hardware and software validation.

Speculation

A speculator proposes draft tokens, the target validates them in parallel, and an accepted prefix plus one target token advances decode. It improves TPS and ITL, not TTFT. Benefit depends on draft cost, proposed length, acceptance rate, temperature, domain, and spare compute at the active batch.

Speculation methods

Draft-target pairs the model with a much smaller draft model and is easy to start but adds the most model overhead. Medusa adds draft heads to the target. EAGLE trains a small hidden-state-conditioned draft model for broader use. N-gram speculation reuses input sequences and excels for repetitive code, while Lookahead Decoding builds candidates during inference at extra compute cost.

Key-value reuse

Every engine retains key-value state within a request; prefix caching reuses it across requests but skips prefill only from the beginning of an identical token sequence until the first difference. Put stable context first, novel content later, and route related requests toward the replica that owns their hot cache. Non-prefix reuse requires positional correction and selective recomputation, so it remains a specialized path.

Topology-aware parallelism

Tensor parallelism (TP) splits work within layers and favors low latency on fast intra-node links. Expert parallelism (EP) keeps experts intact and can improve mixture of experts (MoE) throughput across more devices. Pipeline parallelism (PP) moves stages between nodes but adds sequential bubbles.

Disaggregation

Separate prefill workers compute the first token and key-value state, transfer that state, and let decode workers generate subsequent tokens. Conditional routing keeps cache hits or short inputs local so transfer is paid only when specialization is useful. January 2026 edition snapshot: the book suggested considering it around 100 million to 1 billion tokens per day, models of roughly 100 billion parameters or more, and prefill-heavy traffic with long inputs.

How it works

  1. Profile production-shaped traffic by prefill, decode, cache behavior, batch, and topology. Preserve latency, throughput, cost, and quality baselines before enabling a technique.
  2. For quantization, choose component and format separately, calibrate post-training conversion, then compare perplexity, public task scores, and product-specific evaluation against original precision. Reduce scope or raise precision when the delta exceeds noise.
  3. For speculation, tune draft method and length against acceptance and cost. Disable or shorten speculation when batch saturation removes spare compute; favor n-gram reuse for repetitive code-like output and trained draft heads for broader workloads when available.
  4. For caching, canonicalize stable prefixes, allocate device memory deliberately, place colder blocks in host or storage tiers, and route on both load and prefix affinity. Test long contexts that can make attention state the main memory consumer.
  5. For parallelism, size weights plus runtime and cache headroom, then map synchronization to links. Use TP within a fast node by default; consider EP for high-throughput MoE serving; cross nodes with lower-communication strategies only when necessary.
  6. For disaggregation, route through a decode-side cache check, send long uncached work to prefill workers, transfer key-value blocks, and scale prefill and decode pools independently. Watch both the prefill queue and decode cache capacity.
Cache, parallelism, and disaggregation flow

A request flows from Cache-aware router to Decode cache check; a miss passes to Parallel prefill workers, the KV transfer crosses to Parallel decode workers, and generated tokens return through the response stream.

  1. Cache-aware routerPrefers a replica with matching prefix state
  2. Decode cache checkHandles a hit or short prefill locally
  3. Parallel prefill workersCompute first token and key-value state
  4. KV transferMoves cache over the selected interconnect
  5. Parallel decode workersGenerate remaining tokens
  6. Response streamReturns accepted output tokens
  • Cache-aware routerDecode cache check: Route by load and prefix
  • Decode cache checkParallel prefill workers: Miss or long uncached input
  • Parallel prefill workersKV transfer: First token plus cache
  • KV transferParallel decode workers: Cross worker boundary
  • Parallel decode workersResponse stream: Subsequent tokens

Metrics that matter

Quality delta

perplexity and eval scores

Compare repeated runs with the original precision and product-specific tasks.

Draft acceptance

accepted tokens per iteration

Interpret with draft generation cost, sequence length, temperature, and batch.

Prefix cache effectiveness

hit rate and tokens skipped

Hit rate alone hides whether matches save two tokens or thousands.

Cache residency by tier

GB and eviction rate

Track hot device state, offloaded state, transfer latency, and churn.

Parallel efficiency

speedup per added GPU

Separate compute gain from synchronization and interconnect cost.

Disaggregated balance

prefill queue and decode occupancy

A growing queue or exhausted decode cache signals the worker ratio is wrong.

Trade-offs

Speed versus quality risk

Narrower formats move and compute less data, while sensitive components and recurrent attention state can compound numerical error. Selective higher precision is often better than an all-or-nothing policy.

Per-user speed versus throughput

Speculation can reduce decode iterations at low batch, but its verification work consumes compute that larger batches would use for more requests.

Cache hit versus load balance

Affinity routing preserves hot prefixes but can overload a popular replica. Global lower-tier storage improves durability and reach, yet remains slower than a local device hit.

Latency versus communication

More devices add capacity and may reduce per-request work, but every synchronization or token route crosses a slower boundary. Extra nodes may be more efficient as replicas.

Specialization versus complexity

Independent phase tuning and scaling can reduce interference at high volume, while queues, transfers, extra replicas, and cache pressure make small deployments slower or more expensive.

Engineering checklist

  • Name the saturated phase and resource before choosing a lever; do not optimize from a feature checklist.
  • Freeze representative traffic, quality, latency, throughput, cost, engine, model, precision, and hardware baselines.
  • Evaluate quantization component by component and compare multiple quality measures to original precision.
  • Measure acceptance and net speed at every expected batch, temperature, and domain; include disable thresholds.
  • Canonicalize prefixes, budget cache tiers, record eviction, and balance affinity against replica load.
  • Exercise long inputs and confirm chunking, paging, and attention kernels prevent one request from monopolizing memory or compute.
  • Document GPU and node links, then choose TP, EP, or PP according to communication and latency goals.
  • Use disaggregation only after proving sufficient model size, traffic volume, and prefill weight; monitor queues, transfer time, and decode cache.
  • Revalidate all January 2026 edition support and threshold statements against current software and unit economics.

Vocabulary

Post-training quantization
Converting finished model values to lower precision using scale factors and calibration.
Quantization granularity
How many values share one scale factor, from a whole tensor to channels or small blocks.
Token acceptance rate
The share of proposed draft tokens that the target model validates before the first rejection.
Prefix caching
Reusing key-value state for an identical starting token sequence across requests.
PagedAttention
Managing key-value state in fixed-size pages to reduce memory fragmentation and duplication.
Tensor parallelism
Splitting operations within each model layer across devices with frequent synchronization.
Expert parallelism
Placing complete experts on different devices and routing tokens among them for scalable MoE throughput.
Disaggregated serving
Running prefill and decode on independently configured and scaled worker pools.

Source map

  • Pages 117-120

    Optimization constraints, scale, interaction, and technique families.

  • Pages 120-129

    Quantization formats, scope, numerical risk, and quality measurement.

  • Pages 129-136

    Speculative decoding mechanisms, algorithms, acceptance, and compute trade-offs.

  • Pages 136-142

    Key-value reuse, cache tiers, routing, and long-context memory handling.

  • Pages 142-148

    Model sizing, TP, EP, PP, and multi-node topology.

  • Pages 148-152

    Prefill-decode separation, conditional routing, thresholds, and dynamic pools.

Optimization principles, traffic scale, interactions, and the five technique families
Printed pages: 117–120; PDF pages: 119–122
Number formats, quantization scope, quality risk, and evaluation
Printed pages: 120–129; PDF pages: 122–131
Speculative decoding mechanism, algorithms, acceptance, and batch trade-offs
Printed pages: 129–136; PDF pages: 131–138
KV cache reuse, storage tiers, routing, and long-context handling
Printed pages: 136–142; PDF pages: 138–144
Memory sizing, tensor, expert, pipeline, and multi-node parallelism
Printed pages: 142–148; PDF pages: 144–150
Prefill-decode separation, conditional routing, scale threshold, and dynamic worker ratios
Printed pages: 148–152; PDF pages: 150–154