Model, Workload and Request Arithmetic

Serving decisions start with the model, request distribution and user contract. Exact units and request-state ownership prevent attractive optimizations from solving the wrong bottleneck.

Section 1 of 9 · 13 units · about 50 hours

0/13

By the end you can Trace successful, cancelled, timed-out and failed requests end to end, reconcile model and KV arithmetic with an observed baseline, and prove that the load generator preserves offered load and output semantics.

Units

Build it

Mini project · about 12 to 16 hours

Request arithmetic and workload harness for servelab

Build the servelab foundation with an analytical request and memory model, a retained workload corpus with replayable manifests and validated load generators. Trace one request through a minimal reference path and score throughput against goodput for a model that fits your GPU, grounding every later optimization.

  1. 1Create servelab with manifests/, workload/, model/, engine/, harness/, sim/, gateway/, tests/ and reports/, and record model, tokenizer, template and engine identity in manifests/ checked against config.json with digests kept in reports/.
  2. 2Build the analytical planner in model/ for weight bytes, KV bytes per token and prefill and decode work in dense form, checked against the TensorTonic capacity planner with derivations kept in reports/.
  3. 3Collect a retained corpus in workload/ with length, reuse and media-token distributions, write immutable workload and environment manifests with digests and a tuning versus final split, and prove deterministic replay preserves order and outputs with lineage kept in reports/.
  4. 4Implement open-loop and closed-loop generators in workload/ validated against a deterministic fake server, reconcile concurrency with and offered against completed rates, keeping raw event logs and outputs in reports/.
  5. 5Trace one request through a minimal reference path in engine/ from API through tokenizer, queue, scheduler and sampler with abort at each phase, checked against the Hands-On companion streaming lab with per-request traces kept in reports/.
  6. 6Sweep offered load through saturation with the generators, derive TTFT, TPOT and ITL percentiles with from retained timestamps, track queue depth and recovery, score throughput against goodput with quality and energy per accepted token, and reconcile the knee with the planner estimate keeping the report in reports/.
What you hand in
  • Analytical planner in model/ with derivations and capacity fits checked against an independent worksheet.
  • workload/ corpus, manifests, replay proof and validated generators with raw event logs.
  • engine/ reference path with lifecycle, abort and per-request traces plus goodput and energy report.
How to check it
How it's graded

Arithmetic planner

Pass: Planner derivations match an independent worksheet and the TensorTonic checks with stated conventions.

Great: You sweep prompt and output shapes and show where the first-order estimate breaks with evidence.

Workload and replay

Pass: Double replay gives identical IDs and outputs, manifests reject changed configs, and raw logs yield percentiles.

Great: Tuning and final traces stay disjoint with lineage, and a second operator reproduces the replay.

Reference path

Pass: Lifecycle and abort histories show single terminal marks with no held blocks against your ledger.

Great: You inject aborts at every phase and trace each TTFT and gap to queueing or execution with evidence.

Resources

  • How to Scale Your Model - InferenceJAX Team

    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.

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

    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

    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

    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: From scratch, one token at a time - Modules 01, 02 and 04Tushar Amrit

    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.

  • Stanford CS336 - Inference LectureStanford University

    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

    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

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

  • LLM Inference Systems Laboratory - Workload and BaselineRoadmap-Final

    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.

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

    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).

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

    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).

  • Inference EngineeringPhilip Kiely (Baseten Books)

    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.

  • LLM Inference Handbook - Key metrics for LLM inferenceModular

    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.

  • AI Performance Engineering - Minimum Mental ModelWafer

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

  • Hugging Face Transformers - model configuration and revisionHugging Face

    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

    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.

  • Nano-vLLM tiny serving engineGeeeekExplorer

    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

    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.