Unit 5 of 13 · about 4 hours · explain, measure

Length, reuse and media-token distributions of a workload

Averages hide the shapes that set cost. Spread, reuse and image tokens decide which batch, cache and SLO hold.

You'll be able to

  • Describe a workload by input and output length medians plus spread, not points.
  • Describe prompt reuse and cache-locality distributions and state when reuse helps outcomes.
  • Budget media tokens for a multimodal input with encoder and longer-context effects.

Covers

Input and output length distributionsPrompt reuse and cache-locality distributionsMultimodal encoder and media-token budgeting
1

Read

In this order, only the parts listed

0 of 4 done

  1. Length spread and day-long variationEtalon: Holistic Performance Evaluation Framework for LLM Inference Systems

    Section 3.1 with Figures 1 and 2 (Yi-34B on 2 H100 prefill versus length; Arxiv-Summarization at 1.5 QPS with 60% over 25 s scheduling and 228 median decode tokens); Section 4.1 (LMSys-Chat-1M 417 median and 1418 p90 prefill tokens; prefill deadline fitted from 10 isolated repeats); Section 5.1 (hourly runs over 24 hours, 256 to 8k prefill with 256 gen)

  2. Prefix reuse and median lengthsHow to Scale Your Model - Inference

    Designing an Effective Inference Engine: Prefix caching with the dogs and cats example, chat append, few-shot and system prompts, affinity routing, LRU trie and host DRAM

  3. Cache reuse and fragmentationLLM Inference: From scratch, one token at a time - Modules 01, 02 and 04

    Fragmentation: the waste nobody budgets for with 20.4-38.2% useful; Cache reuse: the free win hiding in chat with 30x TTFT example from 3000 to 100 tokens

    Treat the 30x as the author's workload result, not your target. Your target is the reuse distribution and the TTFT move on your corpus.

  4. Benchmark dimensions and vision tokensInference Engineering

    Sections 4.5 with 4.5.1 for sequence lengths, traffic volume and pattern, request contents and input params; Section 6.1 for vision encoders, about a thousand visual tokens per high-resolution image, and longer prefill, decode and KV effects

2

Focus on

  • Report medians with spread: 417 median against 1418 p90 prefill tokens, 256 to 8k sliders, 228 median decode tokens, hourly runs over 24 hours. Points hide padding, blocking and queueing.
  • Prefill grows about quadratically, so a static TTFT target is slack for short prompts and impossible for long ones. Fit the prefill deadline from the isolated curve per length.
  • Reuse is a distribution with routing and eviction costs. Affinity routing, LRU trie and DRAM decide whether shared prefixes move TTFT and goodput.
  • A high-resolution image adds about a thousand visual tokens to prefill and KV. The encoder is small but fragmented runtime support makes engine choice matter.
Common mistakes · 3
  • Sweeping batch at fixed length and calling it a workload. Prompts spread widely and decode lengths vary as much, so fix both axes.
  • Reading hit rate as outcome. Low reuse with lookup, routing, reservation or eviction can lose even at high hit rate; check TTFT and goodput.
  • Treating image tokens as free. They are prefill tokens with KV that live for the whole decode; budget them as input length.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the workload card with medians 417 and 1418, decode median 228 with spread and , a reuse line and an image-token line at 1000 per high-resolution image. Add the steady-state illustration for , , , labeled fixed-length only: sequences finishing per step , tokens evicted per step .
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Which spreads does this unit cite, and why medians plus spread?Answer

    LMSys-Chat-1M 417 median with 1418 p90 prefill tokens, 256 to 8k sliders, 228 median decode tokens, hourly runs over 24 hours. Points hide the padding, blocking and queueing that spreads cause.

  2. 2.Why must the prefill deadline be fitted per length?Answer

    Prefill grows about quadratically (Figure 1), and scheduling delay mixes with processing. A static target is slack or impossible across 417 to 1418 tokens.

  3. 3.At , , , how many tokens leave the cache per step?Answer

    96: sequences finish per step, each evicting , so .

  4. 4.When does prefix reuse lose despite hits?Answer

    When lookup, routing, reservation, eviction or low reuse costs more than recompute. Hit rate alone does not establish TTFT or goodput gain.

You're done when

Your workload card states medians, spread, reuse and image-token lines with n, and you can defend the fitted prefill deadline against a static one.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 14 more in the section
  • How to Scale Your Model - InferenceJAX Team · primary

    Read the complete inference chapter for model, KV, batching, parallelism and capacity arithmetic. Reproduce every equation for one fixed model and workload, then use the public serving companion and book overview to connect the quantities to the request lifecycle.

  • LLM Inference: From scratch, one token at a time - Modules 01, 02 and 04Tushar Amrit · support

    Work the "Math by hand" and checkpoint parts of The Autoregressive Loop, The KV Cache and Metrics and the Roofline. Redo each worked number for your own model before reading the solution.

  • Etalon: Holistic Performance Evaluation Framework for LLM Inference SystemsAgrawal et al. · support

    Read Sections 2.2, 3.1 and 4.1 with Algorithm 1 and Figures 1 to 3 for TTFT, TBT, TPOT, normalized latency, capacity and fluidity-index; Section 4.2 for black-box and capacity recipes; Section 5.1 for hourly runs over 24 hours and LMSys-Chat-1M medians (417 median, 1418 p90 prefill tokens).

  • Inference EngineeringPhilip Kiely (Baseten Books) · support

    Read Sections 1.4 to 1.4.2 for TTFT, TPS, percentiles and end-to-end versus inference-only time; Section 4.5 with 4.5.1 for benchmark dimensions, tooling and eval inputs; Section 6.1 for vision encoders, image tokens and longer-context effects.

Also in this section

  • Hands-On LLM Serving and Optimization - Chapters 2 and 5Chi Wang and Peiheng Hu (O'Reilly) · required

    Read Chapter 2 for the decoder walk-through, the KV cache and the prefill and decode phases, and the Chapter 5 sections that estimate model size and KV-cache size. Run the Chapter 2 companion notebooks on a small model and redo every size estimate for the model you will serve.

  • Transformer Inference ArithmeticKipply · required

    Re-derive weight bytes, KV bytes per token, prefill work, decode work and arithmetic intensity with explicit units. Replace every example constant with your model configuration and compare the estimates with the book.

  • Machine Learning Engineering Open Book - InferenceStas Bekman · required

    Use inference/README.md for the prefill/decode distinction, memory formulas, MHA/GQA/MQA/MLA comparison and current glossary. Treat unfinished sections as a reference boundary, not as the main course.

  • LLM Inference Handbook - Key metrics for LLM inferenceModular · reference

    Use the TTFT, TPOT and ITL definitions, and the difference between request-weighted average TPOT and token-weighted average ITL, when you define your own metrics.

  • Stanford CS336 - Inference LectureStanford University · support

    Watch the inference lecture once after the arithmetic reading. Pause to reproduce its model-memory and phase-bottleneck calculations; advanced serving mechanisms are routed to their later stages.

  • 100 Days of LLM Inference - Days 1, 2, 5 and 6Elizabeth Thomas · support

    Run only the four named notebooks for request anatomy, model configuration, KV sizing and roofline orientation. Verify every formula independently because this public learning journal is a useful practice supplement, not the authority.

  • TensorTonic Language Modeling from Scratch - Plan KV-Cache CapacityTensorTonic · support

    Solve after the KV-bytes unit, then check the answer against your own worksheet for the same configuration.

  • AI Performance Engineering - Minimum Mental ModelWafer · reference

    A curated, dated index. Use Start Here only to find a primary source the other entries lack.

  • LLM Inference Systems Laboratory - Workload and BaselineRoadmap-Final · support

    Start the immutable workload manifest, deterministic fake server, request-state trace and arithmetic planner. Keep this same repository through INF-9 so later comparisons preserve the contract.

  • Hugging Face Transformers - model configuration and revisionHugging Face · reference

    Read PreTrainedConfig common attributes (vocab_size, hidden_size, num_attention_heads, num_hidden_layers) and from_pretrained revision (branch, tag or commit id, default main). Use the saved config.json as the identity record beside the book config dumps.

  • Hugging Face Transformers - chat templatesHugging Face · reference

    Read apply_chat_template with role and content dicts, the Mistral versus Zephyr control-token examples, and add_generation_prompt for starting an assistant reply. Compare the template output token count with the raw prompt count.

  • DistServe: Disaggregating Prefill and Decoding for Goodput-optimized LLM ServingZhong et al. (OSDI 2024) · support

    Read Section 1 with Figure 1 for per-GPU goodput: the highest request rate served while a target share of requests meets the TTFT and TPOT SLOs (13B model on one A100 reaches about 1.6 requests per second at 90% attainment).

  • Nano-vLLM tiny serving engineGeeeekExplorer · reference

    Read nanovllm/engine/sequence.py for request state, scheduler.py for waiting and running sets, block_manager.py for allocate, append, deallocate and prefix-hash reuse, model_runner.py for prefill and decode steps, and llm_engine.py for the generate path. Trace one request through these files only; do not adopt the engine for load measurement.

  • Gil Tene - How NOT to Measure Latency (talk)Strange Loop Conference via YouTube · reference

    Use for coordinated-omission vocabulary only: closed-loop testers that wait for each reply, the missing samples under queueing, and the correction concept of recording intended send time. Do not adopt wrk, hey or ab; write the small Python generator in the load-generator unit instead.