Inference Engineering

Serving lab

Set up a language-model server, send it traffic, and see what each engine feature does to latency, throughput, goodput and memory. Everything the course covers meets here.

How to use it. Press Run. Pin the result as A. Change one thing. Run again, and A and the new run sit side by side with the differences marked.

What the numbers are. The lab simulates the engine one step at a time. Each step’s duration comes from the roofline model in lesson 1: for the weight matmuls and for attention, the longer of the time to move the bytes and the time to do the FLOPs. These are floors. Real servers are slower. The two efficiency knobs scale the GPU’s peak bandwidth and FLOP/s down to what real kernels reach, and the overhead knob adds a fixed cost to every step. At their defaults (1, 1 and 0) you see the best case.

What the simulator leaves out
  • Activations, layer norms, sampling and the embedding lookup cost nothing. Weights and the KV cache are the only memory traffic.
  • Kernel groups run one after another; compute and memory overlap only inside a group. Tensor-parallel all-reduces never overlap with compute, and run as a ring (no NVLink SHARP).
  • Each request’s KV blocks are its own: prefix caching skips prefill compute but does not share memory. Preempted requests are recomputed, never swapped to CPU.
  • Static batching reserves KV for each request’s whole output up front, and finished requests keep their slot (padding) until the longest one ends.
  • Whole-prompt prefill runs in its own step, up to 16,384 prompt tokens, and decodes wait for it. Admission keeps 1% of KV blocks free, as vLLM does.
  • Speculative decoding: the draft model’s memory is ignored, and each draft step costs a fixed fraction of a target step. Quality effects of quantization are not modeled.
  • Sliding-window attention limits the keys read, but the cache still allocates every token.

GPU-to-GPU links (per direction; vendors quote the two-direction total):

Set up a server on the left, then press Run.

Results

The lab loop: run, pin the result as A, change one thing, run again. A and this run then sit side by side.

No run yet.

Load sweep

One run shows one load. A sweep reruns the current setup at a range of arrival rates, from light to beyond what the server can take, so you can see where latency turns up (the knee) and the highest rate at which 90% of requests still meet both SLOs (goodput). Sweep runs use open-loop arrivals and last at least 30 seconds of traffic each.

Latency against throughput, and SLO attainment against load

Challenges

Each challenge loads a starting setup and states a goal. The check runs against the simulator, after every run or sweep while a challenge is active. Your progress stays in this browser.

  1. Serve a 70B model on the fewest H100s

    One run

    Serve Llama 3.1 70B at 3 requests/s (about 1,000-token prompts, 256-token answers) with p99 time to first token under 0.5 s and p99 time per output token under 50 ms. Use as few GPUs as you can.

    1. The preset uses 8 GPUs. Run it: the targets are easy.
    2. Lower the tensor-parallel degree. Watch what happens to KV memory when the weights barely fit.
    3. Find a change that makes the smaller setup fit again.

    Tensor and pipeline parallelismQuantizationThe KV cache

  2. Find the batch where decode stops being memory-bound

    One run

    On one H100 with Llama 3.1 8B in BF16, find the smallest max batch size at which the weight matmuls in decode spend most of their time compute-bound. Within 10% counts.

    1. Run the preset (max batch 64). The scorecard shows decode matmuls as memory-bound.
    2. Raise the max batch size and run again. Plenty of users are waiting, so the batch fills up.
    3. Stop at the smallest batch where the line flips to compute-bound.

    The rooflineContinuous batching

  3. Stop long prompts from stalling everyone

    Pin A, then run B

    Show that chunked prefill cuts the worst inter-token latency: the longest pause any user sees between two tokens.

    1. Run the preset and pin it as A. Note the worst inter-token latency.
    2. Turn on chunked prefill. Change nothing else.
    3. Run B. Pass when B’s worst pause is at most half of A’s.

    Chunked prefill and disaggregationPrefill and decode

  4. Make one user’s tokens come twice as fast

    One run

    With a single user (closed loop, concurrency 1), halve the median time per output token using speculative decoding, with a realistic draft model (acceptance rate 0.8 or less, draft cost 0.05 or more).

    1. Run the preset. Batch-1 decode is memory-bound: the GPU reads all the weights for one token.
    2. Turn on speculative decoding and run again.
    3. Afterwards, raise concurrency to 64 and watch the gain shrink.

    Speculative decodingThe roofline

  5. Run out of KV memory, then fix it

    Pin A, then run B

    On an L4 (24 GB), 64 users with long conversations overflow the KV cache, and the engine preempts requests. Get preemptions to zero without lowering the load, and without losing throughput.

    1. Run the preset and pin it as A. Note the preemptions and the KV memory chart.
    2. Change engine settings only: same GPU, model, GPU count and workload.
    3. Run B. Pass with zero preemptions and output tokens/s at least as high as A.

    The KV cachePaged KV memoryQuantization

  6. Reach a goodput of 45 requests/s on one H100

    Load sweep

    Goodput is the highest arrival rate at which at least 90% of requests meet both SLOs (here: TTFT under 0.5 s, TPOT under 30 ms). Run a load sweep with Llama 3.1 8B on one H100 and reach 45 requests/s.

    1. Run a sweep on the preset. Note where SLO attainment falls below 90%.
    2. Change engine features, run the sweep again.
    3. The SLOs and workload shape stay as set.

    Measuring a serving systemQuantizationChunked prefill and disaggregation