LLMs & Applied NLPAdvanced20 min read5 questions

LLM Inference: Decoding, Quantisation & Serving Economics

The half of LLM engineering that decides whether your product is profitable: decoding strategies, quantisation trade-offs, and how to get 10× throughput from the same GPU.

Covers: Sampling parameters, KV cache, continuous batching, quantisation, speculative decoding, latency and cost

Training an LLM is a one-off cost. Serving it is a cost you pay on every request, forever. Any company running LLMs in production cares enormously about inference, and interviews for those roles go deep on it.

Filter
0/5 mastered
IntermediatesamplingdecodingtemperatureAsked at OpenAI, Anthropic

30-second answer

Temperature divides logits before softmax: below 1 sharpens the distribution, above 1 flattens it. Top-k keeps the k highest-probability tokens; top-p (nucleus) keeps the smallest set whose cumulative probability exceeds p, so it adapts to how confident the model is. For code: temperature 0–0.2 with top_p 0.95 for determinism. For creative writing: temperature 0.8–1.0 with top_p 0.9–0.95.

Expertkv-cachebatchingvllmAsked at vLLM/Anyscale, Together AI

30-second answer

The KV cache stores past keys and values so each decode step is O(n) instead of O(n²) — mandatory, but it consumes enormous memory. Static batching wastes GPU time because the whole batch waits for its longest sequence. Continuous batching evicts finished sequences and admits new ones every step. vLLM adds PagedAttention, which stores the cache in fixed-size blocks like OS virtual memory, eliminating the fragmentation that otherwise wastes 60–80% of cache memory.

AdvancedquantizationgptqawqAsked at NVIDIA, Neural Magic

30-second answer

Weight-only INT8 is essentially lossless and halves memory. INT4 with a good method (GPTQ, AWQ) typically costs 1–3% on benchmarks while cutting memory ~4×. GPTQ minimises layer-wise reconstruction error using second-order information; AWQ identifies the ~1% of salient channels by activation magnitude and scales them to protect them. Since decode is memory-bandwidth-bound, quantisation usually improves latency proportionally to the memory saving.

Expertspeculative-decodinglatencyinferenceAsked at Google DeepMind, Together AI

30-second answer

A small draft model proposes k tokens autoregressively; the large model verifies all k in one forward pass (parallel, so nearly the cost of one token). A modified rejection-sampling rule accepts each draft token with probability min(1, p_target/p_draft) and, on rejection, resamples from the normalised residual distribution. That rule guarantees the output distribution is exactly the target model's, giving 2–3× lower latency with zero quality change.

Advancedcost-optimizationlatencyproductionAsked at AI product startups, Ramp

30-second answer

Measure first: break cost down by prompt tokens, output tokens and call volume, and split latency into time-to-first-token and inter-token latency. Then attack in order of ROI: semantic and prefix caching, prompt compression, model routing so easy requests hit a cheap model, streaming to fix perceived latency, output-length limits, and batching for anything non-interactive. Most teams find 60–80% savings without changing the model.

Showing 5 of 5 questions for llm-inference-decoding-and-serving.

Check your understanding

5 questions · no sign-up, nothing stored

0/5 answered
Question 1

1.Top-p (nucleus) sampling is usually preferred over top-k because:

Question 2

2.PagedAttention improves throughput primarily by:

Question 3

3.In 4-bit quantisation, per-group scales (e.g. group size 128) are essential because:

Question 4

4.Speculative decoding produces output that is:

Question 5

5.The highest-ROI change for perceived latency in an LLM chat product is usually:

Hands-on challenge

Build it — this is what you talk about in a deep-dive round.

Build an LLM serving cost and latency dashboard

Instrument a real or simulated LLM workload and demonstrate measurable improvement on both axes.

Requirements

  • Per-request logging of input/output/cached tokens, TTFT, total latency and model used.
  • Cost breakdown by prompt component (system, retrieved, history, user) with a chart.
  • Implement a two-tier cache (exact + semantic) and report hit rate and savings.
  • Implement model routing with a difficulty heuristic; report cost saving and a quality comparison on a held-out eval set.

Stretch goals

  • Implement the KV-cache capacity calculator and validate it against measured concurrency on a real server.
  • Implement prompt-lookup speculative decoding and measure the acceptance rate on a summarisation workload.