Roadmap/Phase 05
PHASE 05 OF 06

Distributed Inference

Run one model across many GPUs and many machines without losing speed, money, or sleep.

0%
12 topics31 lessons99 h
In plain English

Some models are too large for one GPU, and some workloads have too many users for one machine. Distributed inference is the craft of splitting the work so that several GPUs act like one very large one. Think of a restaurant kitchen during a rush. One chef cannot cook every dish, so the head chef splits the menu across stations, agrees on how plates get passed between them, and keeps a board that shows where every order is. This phase teaches the splitting strategies (tensor and pipeline parallelism), the passing of plates (NCCL collectives and network bandwidth), the kitchen manager (Kubernetes), and the dashboard that tells you when a station is on fire.

What you can do afterwards

You can choose and justify a parallelism layout for a given model and GPU budget, implement column/row-parallel layers and a pipeline schedule from scratch with torch.distributed, estimate communication cost from link bandwidth, schedule GPU pods on Kubernetes, and build a monitoring stack that pinpoints the slow rank in a multi-node deployment.

Milestones

  1. M1Splitting a model across GPUs
  2. M2Moving bytes between GPUs and nodes
  3. M3Operating a distributed serving fleet

Capstone projects

Three sizes. The small one is part of finishing this phase (it carries 15% of the phase bar); medium and large are tracked but optional. Each lists what to build, what to leave out, what to measure, and what reviewers will look at.

Small

Build your own tensor-parallel GPT-2 on CPU ranks

CPU · your Mac~10 h
one evening to a weekend · required for phase completion

Take the Phase 1 GPT-2 engine and shard it across 2 and 4 torch.distributed gloo processes with column- and row-parallel linears and head-parallel attention, so every rank holds only its slice of the weights and KV cache and the fleet produces logits identical to the single-process model. You then measure exactly how many bytes cross between ranks per token and show that the count matches the formula. This proves you understand how real engines split a model, not just that you can set tensor_parallel_size.

Scope

  • ColumnParallelLinear, RowParallelLinear and a head-parallel attention module with a per-rank KV cache, each unit-tested against the dense equivalent.
  • A sharded weight loader that reads the Hugging Face GPT-2 state dict and keeps only the rank's slice, splitting the fused c_attn by head.
  • A torchrun entry point that generates 64 greedy tokens for a set of prompts at world sizes 1, 2 and 4 and saves logits per step.
  • A communication accountant that wraps dist collectives and reports calls and bytes per decode step, compared with the closed form.
  • A bench.py that reports tokens per second and communication share per world size, with a README explaining why gloo on CPU does not scale and what would change on NVLink.

Out of scope

  • Pipeline parallelism or combining TP with PP.
  • Any GPU or NCCL code; this is CPU fp32 on one laptop.
  • Training, sequence parallelism or fused kernels.

What to measure

Logit agreement with the single-process model
How · torch.allclose on every decode step for 5 prompts and 64 tokens, atol 1e-4, at world 2 and 4
Target · all pass
Per-rank parameter count
How · sum of numel over the rank's tensors compared with the formula embeddings + (124,439,808 - embeddings) / world
Target · exact match at world 2 and 4
All-reduce bytes per decode step
How · counter on dist.all_reduce during one decode step at batch 1
Target · exactly 24 calls and 24 * 768 * 4 = 73,728 bytes
Per-rank KV cache bytes at 132 tokens
How · sum of cache tensor bytes on one rank
Target · 9,732,096 / world exactly
Tokens per second at world 1, 2 and 4
How · 128 greedy tokens after a 32-token prompt, median of 5, threads pinned per rank
Target · report; explain the trend with the measured communication share

Pay attention to

  • Split c_attn per head, not by contiguous columns; a column split silently mixes Q, K and V across ranks and still runs.
  • Embeddings and layer norms are replicated; do not count them as sharded in the parameter formula.
  • Dropping the all-reduce after the row-parallel layer produces plausible but wrong logits; the logit test must compare every step, not only argmax tokens.
  • Pin torch.set_num_threads per rank so 4 ranks do not fight for the same cores and make the benchmark meaningless.
  • The per-rank KV cache must store only the rank's heads; storing all heads passes the logit test but fails the memory target.

Acceptance (all must pass)

  • ☐pytest passes the logit-agreement, parameter-count and byte-count tests at world 1, 2 and 4.
  • ☐Greedy tokens at world 4 equal Hugging Face generate(do_sample=False) for 3 prompts over 64 tokens.
  • ☐The communication accountant's per-step bytes match the closed form in the README table.
  • ☐README contains the tokens-per-second table and a paragraph on the communication-to-compute ratio on CPU versus NVLink.
Deliverable · A repository with the TP layers, sharded loader, torchrun entry point, accountant, bench.py, tests and a README with the numbers.
Stretch · Add a sequence-parallel layer norm and show the all-reduce turns into reduce-scatter plus all-gather with the same total bytes. · Run the same code on a Colab T4 at world 2 with two processes sharing one GPU and compare the communication share.
Medium

Build your own fleet simulator

CPU · your Mac~24 h
a weekend or two · composes several builds

Compose the pipeline, disaggregation, routing and autoscaling simulators from this phase into one discrete-event model of an inference fleet, calibrated with the prefill and decode step times you measured in Phases 3 and 4, and use it to answer capacity questions with SLO goodput curves. The output is a tool that a capacity planner could run before buying GPUs, plus a report of experiments where you predicted and then checked results.

Scope

  • A replica model with continuous batching, KV memory admission and a step-time model whose coefficients are fitted to your Colab T4 measurements and to one published H100 datapoint.
  • Layout options per replica (TP factor and PP stages) using the planner's memory and communication estimates to derive step times.
  • A router with round-robin, least-outstanding, least-KV and prefix-aware policies and a prefix-cache model for multi-turn agent traces.
  • An autoscaler with queue-depth and KV-pressure signals, cooldown, cold-start delay and graceful drain.
  • A disaggregated mode with prefill and decode pools and KV transfer cost, and a failure model that kills replicas and injects stragglers.
  • SLO goodput curves (TTFT and ITL) against arrival rate for every configuration, and a cost-per-goodput table using hourly prices.
  • A CLI that runs an experiment YAML and writes CSVs and plots, plus a report of at least four experiments.

Out of scope

  • Running any real model server; this is simulation only.
  • Network-level packet simulation; links are alpha-beta models.
  • A graphical interface.

What to measure

Calibration error
How · simulated single-request TTFT and ITL for the small model versus your Phase 3 T4 measurements at prompt lengths 128, 512 and 2048
Target · within 15 percent
Goodput knee per layout
How · bisection on arrival rate for colocated versus 2+2 disaggregated at a 500 ms TTFT and 50 ms ITL SLO
Target · report both knees and the ratio
Routing effect on agent traffic
How · prefix hit rate and p99 TTFT for prefix-aware versus round-robin at N=8 on a 1,000-session trace
Target · hit rate at least 3x and p99 TTFT at least 20 percent lower
Autoscaler response
How · time from a 4x step in arrival rate to goodput recovery with a 60 s cold start
Target · report; show the trade-off against over-provisioning cost
Availability under failures
How · fraction of requests meeting the SLO over a 1-hour trace with one replica killed every 10 minutes, with and without retries and ejection
Target · report both; protected at least 99.5 percent

Pay attention to

  • Validate the single-replica model before composing; a 10 percent error in decode step time becomes a wildly wrong knee after queueing.
  • Keep seeds fixed and run enough requests that p99 is stable; report confidence intervals or repeated runs.
  • Chunked prefill, KV admission and scale-down drain interact; test each in isolation with analytic checks before combining.
  • The cost table must use the same SLO for every layout, otherwise goodput per dollar is not comparable.
  • Record predictions before running experiments and keep the ones that were wrong in the report.

Acceptance (all must pass)

  • ☐pytest passes the analytic unit tests for the replica, router, autoscaler and disaggregation components.
  • ☐The calibration table and all five measurements are in the README with the commands to reproduce them.
  • ☐At least four experiments are documented with a written prediction, the result and an explanation.
  • ☐One command regenerates every CSV and plot from a clean clone.
Deliverable · A simulator package, experiment configs, CSVs and plots, and a report that answers four capacity questions with numbers.
Stretch · Add speculative decoding as a step-time modifier with an acceptance-rate distribution and show its effect on the ITL knee. · Fit the H100 coefficients from a vLLM benchmark run on a rented instance and compare the predicted and measured knee.
Large

Build your own multi-GPU serving stack

Rented multi-GPU~40 h
1-3 weeks · portfolio piece

Stand up vLLM with tensor_parallel_size 2 on a two-GPU cloud instance inside a kind cluster with the NVIDIA device plugin, put your own router and autoscaler in front of it, wire Prometheus, Grafana and alert rules from your metrics pipeline, then run your chaos drill kit against it and write the postmortem. This is the whole phase as one deployable, observable, tested system, the kind of thing a platform team would ask you to walk through in an interview.

Scope

  • A kind cluster on the instance with GPUs exposed through the NVIDIA device plugin (nvkind or an equivalent documented workaround), with GPU nodes tainted and the scheduler placement verified against your simulator.
  • A vLLM Deployment for an 8B model at tensor_parallel_size 2 with readiness and liveness probes, resource requests, a PodDisruptionBudget and a graceful termination period, plus a 1-GPU variant for comparison.
  • Your router and autoscaler running as pods, routing by least-KV with prefix affinity and scaling the 1-GPU variant on queue depth.
  • Prometheus scraping vLLM and router metrics, recording rules, the provisioned Grafana dashboard and tested alert rules with runbook links.
  • A load test with the Phase 3 benchmark client at three concurrency levels, comparing TP=2 against TP=1 on TTFT, ITL and throughput.
  • A chaos drill (pod kill, straggler via CPU throttling, bad rollout) run by your drill kit, and a blameless postmortem for one drill.
  • A cost section converting the measured goodput into dollars per million tokens for both layouts.

Out of scope

  • Multi-node tensor parallelism or RDMA; a single two-GPU node is enough.
  • Fine-tuning, quantisation sweeps or model quality evaluation.
  • A production ingress, TLS or authentication.

What to measure

TP=2 versus TP=1 inter-token latency
How · median ITL at concurrency 1, 8 and 32 from the benchmark client
Target · report; TP=2 at least 1.3x lower ITL at concurrency 1 on an NVLink pair, less on PCIe, with the gap explained
Goodput per dollar
How · requests per second meeting a 500 ms TTFT and 50 ms ITL SLO divided by hourly price, for TP=2 and two TP=1 replicas
Target · report both and name the winner for this workload
Scheduler agreement
How · pod placements from kubectl versus your simulator for the deployed manifests
Target · identical
Alert latency
How · time from the injected straggler to the alert firing in Alertmanager
Target · under 3 minutes
Availability during the pod-kill drill
How · fraction of requests completed without error over the drill window
Target · at least 99.5 percent with retries and ejection on
Time to recover after pod kill
How · seconds until error rate is back under 0.1 percent, from the drill report
Target · report; explain the share due to model load versus probe timing

Pay attention to

  • vLLM with TP=2 needs shared memory sized for NCCL; a pod without a large /dev/shm fails late and confusingly.
  • Readiness must gate on the model being loaded, not on the port being open, or the router sends traffic into a 60-second cold start.
  • Graceful termination must exceed the longest expected generation or every rollout cuts streams; measure the longest and set terminationGracePeriodSeconds accordingly.
  • Scrape intervals and histogram buckets determine what the dashboard can show; 15-second scrapes cannot resolve a 20-second incident.
  • Record instance type, driver version, vLLM version and NCCL topology (nvidia-smi topo -m) in the README; results are meaningless without them.
  • Tear the instance down when done and record the total spend.

Acceptance (all must pass)

  • ☐A clean clone plus one script brings up the cluster, deployments, monitoring and router on a fresh two-GPU instance.
  • ☐All six measurements appear in the README with commands and the Grafana dashboard screenshots.
  • ☐The chaos drill report and the postmortem are committed and the postmortem has at least three action items.
  • ☐Alert rule unit tests pass with promtool and the straggler alert fired during the drill.
  • ☐Scheduler placement matches the simulator and a pod requesting 3 GPUs is shown Pending with the right reason.
Deliverable · A public repository with manifests, router, autoscaler, dashboards, alert rules, drill plans, the benchmark results and a write-up with the cost comparison and the postmortem.
No GPU? · Without rented GPUs, run the whole stack on the Mac with the Phase 3 GPT-2 server split across 2 CPU ranks using your tensor-parallel layers as the 'TP=2' deployment (torchrun inside one pod on kind) and a single-rank pod as 'TP=1', keep the router, autoscaler, Prometheus, Grafana, alert rules and chaos drills unchanged, and report the same six measurements with CPU numbers. If a Colab T4 is available, run the TP=2 case there with two processes sharing one GPU over NCCL and copy the numbers into the same table, clearly labelled.
Stretch · Add a prefill pod and a decode pod with vLLM's KV connector and measure goodput against the colocated TP=2 deployment. · Add a canary rollout with traffic splitting in your router and a burn-rate alert that aborts the rollout automatically.