Unit 3 of 11 · about 3 hours · derive
Weight and KV sharding and per-rank memory ownership
Aggregate memory is not admission capacity. One rank can run out of KV space while other ranks have free memory, and replicated state can erase an expected sharding gain.
You'll be able to
- Derive each rank's weight and KV bytes from the actual layer, head and position ownership rather than dividing everything by device count.
- Explain KV-head replication when TP exceeds the number of KV heads in a head-sharded GQA layout.
- Reject a plan whose busiest rank exceeds memory after runtime buffers, page waste and reserve are included.
Covers
Read
In this order, only the parts listed
0 of 2 done
- Head sharding and the GQA ceilingLLM Inference: From scratch, one token at a time - Module 09
Module 09, What TP degree actually does to your numbers - Weights per GPU and KV cache per GPU stops shrinking at TP-8
Use the head-ownership argument only. Skip the hardware speed table and Code lab planner: evenly divided weights are an approximation, and its PP latency estimate does not sum the dependent stage service times.
- Layer and expert ownershipAI Systems Performance Engineering - Chapters 15 and 17, distributed and disaggregated inference
Chapter 15, Tensor Parallelism, Pipeline Parallelism, Expert Parallelism and Data Parallelism
Revisit only which weights each rank holds. Carry forward the runtime-memory categories from Weight memory by dtype and the runtime memory categories.
Focus on
- Reuse Per-layer KV layouts and the cache consequences of attention variants. For ordinary full-attention K and V, a rank owning layers, KV heads and cached positions holds logical bytes, where is head dimension and is bytes per element.
- PP assigns KV to the ranks that own its layers. Head-sharded TP assigns local KV heads; if there are more TP ranks than KV heads, a supported layout may replicate heads instead of shrinking each cache further.
- EP partitions expert weights, not automatically attention weights or KV. Sum shared, expert, embedding and output weights according to the chosen layout; include replicated tensors explicitly.
- Admission uses the maximum per-rank allocation, including page rounding, workspace, graphs, communication buffers and reserve. Distinguish logical unique KV from physical copies across ranks.
Common mistakes · 3
- Dividing all memory by the product of TP, PP and EP sizes. Only the tensors actually partitioned along those axes get that divisor.
- Treating a head-count ceiling as a universal limit on usable devices. Position sharding can reduce cache further, but requires its own layout and communication contract.
- Checking total free memory instead of each rank's budget. The first exhausted rank can stop the whole serving group.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.In the four-way TP example, how many physical KV bytes exist across ranks?Answer
262,144 bytes, twice the unique KV. Each of the two KV heads has two physical copies.
2.Does expert parallelism alone divide dense attention KV by expert count?Answer
No. Experts belong to the MoE feed-forward path. Attention KV follows attention layer, head and position ownership.
3.How does two-way PP change each TP rank's KV in this equal-layer example?Answer
It halves local KV to 32,768 bytes because each stage owns four of the eight layers. Aggregate physical KV stays unchanged for the same TP replication pattern.
4.Why is weight bytes divided by rank count insufficient to prove a plan fits?Answer
Some weights are replicated or unevenly placed, and KV, temporary tensors, communication buffers and runtime reserve also consume local memory.
You're done when
Your ledger reconciles unique and physical KV bytes for TP, PP and their combination, and rejects a plan that fails any local memory budget.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 11 more in the section
- AI Systems Performance Engineering - Chapters 15 and 17, distributed and disaggregated inferenceChris Fregly (O'Reilly) · required
Read the disaggregated prefill and decode architecture and the MoE parallelism strategies in Chapter 15, then Chapter 17 on disaggregated pools, routing policies and scalability. Reproduce every communication and KV-transfer estimate for a small declared topology.
- LLM Inference: From scratch, one token at a time - Module 09Tushar Amrit · support
Work the Distributed Inference module's communication arithmetic before the tensor and pipeline parallel units.
Also in this section
- DistServe: Disaggregating Prefill and Decoding for Goodput-Optimized LLM ServingPeking University and Microsoft Research · primary
Read the interference model, independent phase parallelism, placement, KV transfer and goodput evaluation. Reuse the break-even method with your workload and topology; do not transfer the paper's speedups to different hardware.
- AI Systems Performance Engineering companion code - Chapters 15 and 17Chris Fregly · required
Use the single-device KV-handoff and simulation paths before the multi-GPU pairs. Then choose one disaggregation, routing or MoE target compatible with available hardware and keep bundled results separate from newly captured evidence.
- Hands-On LLM Serving and Optimization - Chapter 7, multi-GPU and disaggregationChi Wang and Peiheng Hu (O'Reilly) · support
Read "Multi-GPU and Multi-Node Inferencing" (data, tensor, pipeline and expert parallelism) and "Prefill-Decode Disaggregation" (architecture, KV transfer, when to use it) in Chapter 7.
- NVIDIA Dynamo - Disaggregated Serving and KV-Aware RoutingNVIDIA · required
Trace frontend, prefill router, prefill worker, KV transfer, decode routing and decode worker. Record how load, cache overlap, worker discovery and transfer metadata affect placement; implement only a small simulated or available-hardware slice.
- TensorRT-LLM Disaggregated Serving and KV Cache ExchangeNVIDIA · required
Study the KV exchange abstraction, unique request identity, layout conversion, overlap and fleet-worker model. Use its reproducible benchmark sections only on supported hardware and pin the release.
- SGLang documentation - PD DisaggregationSGLang Project · support
Use the transfer backends, router integration, heartbeat, timeout and cleanup behavior as a second engine's view of the same handoff.
- Mooncake: A KVCache-Centric Disaggregated Architecture for LLM ServingMoonshot AI · support
Read the KV-centric architecture, transfer engine and scheduling sections to understand remote cache pools. Compare its assumptions with DistServe and your simpler handoff; defer reproduction requiring a large cluster.
- 100 Days of LLM Inference - Days 12, 17 and 18Elizabeth Thomas · support
Use the Dynamo, model-parallelism and disaggregation notebooks for a compact topology simulator and request-handoff trace. Label notebook outputs as local analytical or simulated evidence unless real devices were used.
- TensorTonic Language Modeling from Scratch - Route Cache-Aware Prefill RequestsTensorTonic · support
Solve after the routing unit and compare its cost rule with your own placement model.
- AI Performance Engineering - Distributed InferenceWafer · reference
A curated index. Use Section 5 only to find a distributed-serving paper the other entries lack.
- Python 3.14 hashlib - byte digests for KV integrity checksPython Software Foundation · reference
Usage and Hash Objects only: compute and compare a SHA-256 digest over a declared canonical KV payload. Add request/version checks separately; a byte digest is not cache compatibility or authentication.