Module deck

Inference engineering flashcards

Reviewing needs JavaScript. You can read every card in the list below.

Loading your cards...

Back to the module90 cards in this deck

Read all 90 cards as a list

Request lifecycle, metrics and the roofline

  1. Front
    List the steps of one request and say which sets TTFT and which sets ITL.
    Back
    Tokenize, queue, prefill, decode loop, stream. TTFT is queueing plus prefill (plus network, as a client sees it). ITL is the decode step time.
  2. Front
    How do you compute inter-token latency and end-to-end latency?
    Back
    ITL = (e2e latency − TTFT) ÷ (output tokens − 1). End-to-end latency = TTFT + generation time.
  3. Front
    Why is a throughput figure alone not a result?
    Back
    It needs the token type (input or output), the concurrency, and the TTFT and ITL users saw at that load. Bigger batches raise throughput and can lengthen each wait.
  4. Front
    What is goodput?
    Back
    Requests per second that meet the latency targets. 30 req/s with 90 percent on target gives 27 good req/s, more than 40 req/s with 60 percent on target (24).
  5. Front
    Cost per million tokens formula, and what moves it?
    Back
    GPU price per hour ÷ (tokens per second × 3600) × 10⁶. It falls as utilization rises: a quarter of the load gives four times the cost per token.
  6. Front
    How many FLOPs and bytes does one decode token need for P parameters?
    Back
    About 2P FLOPs (a multiply and an add per weight, attention aside) and P × bytes-per-weight bytes read from memory each step.
  7. Front
    Define arithmetic intensity and the ridge point.
    Back
    Intensity is FLOP per byte moved. The ridge is peak FLOP/s ÷ peak bandwidth. Below it a workload is memory-bound, above it compute-bound.
  8. Front
    What is decode intensity at batch B with b bytes per weight?
    Back
    About 2B ÷ b, so exactly B for BF16. It reaches the ridge at B* = ridge × b ÷ 2.
  9. Front
    Is prefill always compute-bound?
    Back
    No. Prefill intensity is about the prompt length n for BF16 weights. Compare n with the ridge: a 4,000-token prompt is compute-bound, a 30-token one is not.
  10. Front
    Which datasheet number do you use for the ridge, and what is the trap?
    Back
    The dense tensor-core figure. Listed numbers are often "with sparsity", about twice the dense figure. Take bandwidth and FLOPs from the datasheet of the exact part.
  11. Front
    How do you bound batch-1 decode speed?
    Back
    Step time ≥ weight bytes ÷ (bandwidth × number of GPUs). Example: 16 GB over 3.35 TB/s gives 4.8 ms, so at most about 209 tokens per second.
  12. Front
    What does the weights-only ceiling ignore?
    Back
    The KV-cache read (grows with context and batch), inter-GPU communication, quantization scale overhead, and kernels that reach only part of peak bandwidth.
  13. Front
    Name the four families of serving techniques.
    Back
    Do less work, move fewer bytes, use hardware better, run reliably. Each answers a roofline question: bytes cut decode time, batching raises intensity, caching skips prefill.

Memory and the KV-cache

  1. Front
    KV-cache bytes per token?
    Back
    2 × layers × KV heads × head dimension × bytes per value. Use KV heads, not query heads. Llama 3 8B in 16-bit: 128 KiB; 70B: 320 KiB.
  2. Front
    How do you turn memory into concurrency?
    Back
    KV budget = GPU memory × utilization − weights − overhead. Divide by (bytes per token × tokens per sequence). Store the cache in FP8 and the count roughly doubles.
  3. Front
    What does "fits is not serves" mean?
    Back
    Weights can fit in GPU memory while nothing is left for the cache and overhead, so the server cannot hold even one sequence. Fix with smaller weights, more GPUs or shorter contexts.
  4. Front
    How does the KV-cache limit decode speed?
    Back
    Each step reads the weights once for the batch and every sequence's own cache. At large batch and long context the caches can outweigh the weights, lowering the throughput ceiling.
  5. Front
    What problem does PagedAttention solve?
    Back
    Fragmentation and over-reservation. The pool is split into fixed blocks (16 tokens by default in vLLM) with a block table per sequence, so waste is at most part of one block.
  6. Front
    What does PagedAttention not change?
    Back
    The bytes a token's keys and values need, and the attention arithmetic. Its gains come from larger batches and from enabling block sharing and preemption.
  7. Front
    How does prefix caching find a match?
    Back
    Each full block is hashed from its parent hash, its tokens and extras such as a LoRA ID or cache salt. A new prompt's blocks are looked up; used blocks are reference-counted; least recently used are evicted.
  8. Front
    What makes a prefix cacheable?
    Back
    It must be identical and at the start of the prompt (static first, dynamic last), computed by the same model and adapter, and the request must reach the engine that holds it.
  9. Front
    Prefix cache versus response cache?
    Back
    Prefix caching reuses intermediate keys and values for a shared prompt start and still runs the model. A response cache returns a stored whole answer for a repeated request.
  10. Front
    GQA versus MQA versus MHA?
    Back
    MHA: a KV head per query head. MQA: one KV head, smallest cache, can lose quality. GQA: groups share a KV head, in between; 8 KV heads against 32 query heads is a 4 times smaller cache.
  11. Front
    What is MLA and what did DeepSeek-V2 report?
    Back
    Multi-head latent attention caches a compressed latent vector and expands it at use. DeepSeek-V2 reports a 93.3 percent smaller KV cache than DeepSeek 67B, a model-to-model comparison.
  12. Front
    What do you do before shipping a quantized KV-cache?
    Back
    Evaluate on your own set, including long contexts. Docs give no accuracy figures and recommend calibrated scales.
  13. Front
    What happens when the KV pool is full?
    Back
    Queue (TTFT rises), preempt (recompute or swap), or shed load. A preemption storm shows as high utilization with falling goodput. Watch the preemption count.

Model and kernel optimization

  1. Front
    What does FlashAttention change, and what stays the same?
    Back
    It tiles attention with an online softmax so the n × n score matrix never goes to HBM: fewer memory accesses. The result is exact attention.
  2. Front
    Why does FlashAttention help prefill more than decode?
    Back
    Prefill has an n × n score matrix per head; decode has one query row, so its traffic is dominated by reading weights and the KV-cache.
  3. Front
    What does quantization store?
    Back
    x ≈ scale × q, with the scale per tensor, channel or group. Group size 128 with a 16-bit scale averages 4.125 bits per 4-bit weight.
  4. Front
    Why do activation outliers hurt per-tensor 8-bit?
    Back
    The largest value sets the scale, so small values round to zero or lose precision. Weights are better behaved than activations.
  5. Front
    LLM.int8() in one line?
    Back
    W8A8 with outlier feature dimensions multiplied in 16-bit and the other 99.9 percent of values in 8-bit.
  6. Front
    GPTQ and AWQ in one line each?
    Back
    GPTQ: layer-wise weight-only quantization using approximate second-order information. AWQ: weight-only, protects about 1 percent salient channels chosen from activation statistics by scaling them.
  7. Front
    SmoothQuant and FP8 in one line each?
    Back
    SmoothQuant: moves quantization difficulty from activations to weights offline for W8A8. FP8: 8-bit floats (E4M3, E5M2) with wider range; needs supporting hardware.
  8. Front
    Which quantization for memory-bound decode?
    Back
    Weight-only low-bit (W4A16, W8A16, FP8 weights): fewer bytes per step, and idle arithmetic hides unpacking. A 4-bit step floor falls toward a quarter of BF16, less in practice.
  9. Front
    Which quantization for compute-bound work?
    Back
    W8A8 or FP8, because 8-bit matrix hardware runs faster. Weight-only gains little past the ridge and adds unpacking work.
  10. Front
    What is the hardware catch for FP8 W8A8?
    Back
    Support depends on the GPU generation. vLLM's table (2026-10-21) lists it for Ada and Hopper, not Ampere. Check the table for the version you run.
  11. Front
    How do you validate a quantized model?
    Back
    Perplexity first (coarse), then task evals against the 16-bit baseline with slices, production-like calibration data, a canary and a rollback. Perplexity alone misses task regressions.
  12. Front
    What do CUDA graphs and fusion remove?
    Back
    Graphs: per-kernel CPU launch overhead, by replaying a recorded sequence with one launch (padded to captured batch sizes). Fusion: round trips to memory between adjacent operations.
  13. Front
    Why can temperature 0 vary between runs?
    Back
    Floating-point addition is not associative and kernels change reduction order with batch size. Batch-invariant kernels fix it at a speed cost (one write-up: 26 s became 42 to 55 s).

Scheduling and decoding

  1. Front
    Static versus continuous batching?
    Back
    Static: wait for N, run until all finish; short requests wait for the longest. Continuous: re-form the batch every step; finished sequences leave, waiting ones join. Needs on-demand cache allocation.
  2. Front
    Why does a large prefill freeze streaming?
    Back
    It occupies a whole step. 16,000 tokens on an 8B model is at least about 259 ms at peak, so every running decode waits that long for its next token.
  3. Front
    How does chunked prefill work, and what does the budget trade?
    Back
    Each step holds one token per running decode plus a chunk of the waiting prompt up to a token budget. Smaller budget: smoother ITL. Larger: faster TTFT for long prompts. Prefill compute is unchanged.
  4. Front
    State Little's law and use it for capacity.
    Back
    L = λW: requests in flight = arrival rate × time in system. Sustainable rate = concurrency limit ÷ time a request holds a slot (queue wait excluded). 20 sequences held for 8 s each is 2.5 requests per second.
  5. Front
    What do you do when demand exceeds capacity?
    Back
    Admission control (reject early with 429 or 503 and a retry hint), priority for interactive traffic, per-tenant quotas, preemption of lowest priority, and cancel on disconnect. Queues alone do not help.
  6. Front
    How does speculative decoding work?
    Back
    A cheap draft proposes γ tokens; the target scores all of them in one pass. Accept each with probability min(1, p/q); on a rejection resample from norm(max(0, p − q)) and stop.
  7. Front
    Speculative speedup formula?
    Back
    Expected tokens per step = (1 − α^(γ+1)) / (1 − α). Speedup = that ÷ (γc + 1), with c the draft step time over the target step time. α = 0.8, γ = 4, c = 0.05 gives about 2.8.
  8. Front
    Is speculative decoding lossy?
    Back
    No. With correct accept and reject sampling the output distribution equals the target's for any draft; a poor draft only lowers speed. Hardware numerics can still cause small variation.
  9. Front
    When does speculative decoding stop helping?
    Back
    Verification processes about (γ + 1) × B tokens per step. Past the ridge it is no longer free, so gains shrink at high batch or load. Low acceptance rate also kills the gain.
  10. Front
    Name draft sources for speculative decoding.
    Back
    Separate small model; Medusa heads (tree attention); EAGLE head over target features; multi-token prediction built into the base model; n-gram or prompt lookup (training-free, good when output repeats input).
  11. Front
    What is prefill and decode disaggregation?
    Back
    Separate pools: prefill machines compute the KV-cache and send it over a fast link to decode machines. Each pool is tuned for its own target. Costs: transfer, two pools, capacity waste.
  12. Front
    How big is the KV transfer, and when is disaggregation worth it?
    Back
    4,096 tokens on a 70B model is about 1.34 GB, about 27 ms at 400 Gb/s line rate. Worth it at high volume with strict TTFT and ITL targets and long prompts; chunked prefill first for small deployments.

Distributed serving, engines and hardware

  1. Front
    What is the layout rule of thumb?
    Back
    Use the smallest parallelism that fits and meets the target, then scale out with replicas. Fewer GPUs means less communication, so consider quantization before adding GPUs.
  2. Front
    TP, PP, DP, EP: what is split and what is communicated?
    Back
    TP: matrices in each layer, all-reduces inside layers. PP: groups of layers, activations between stages. DP: nothing split, no per-request traffic. EP: experts, all-to-all token routing.
  3. Front
    Where should TP and PP live?
    Back
    TP inside a node on fast links (NVLink). PP across nodes. Without NVLink, vLLM's guidance prefers pipeline parallelism. A token still crosses every pipeline stage.
  4. Front
    How much does TP communication add?
    Back
    Two all-reduces per layer per token in the standard split (252 for a 126-layer model). They are small messages, so latency dominates; at an assumed 10 µs each, about 2.5 ms per step.
  5. Front
    Do the layout arithmetic for a 405B model.
    Back
    Cache 504 KiB per token. 8-bit weights 405 GB on 8 H100: about 139 GB of cache, about 32 sequences of 8,192 tokens, step floor about 15 ms. BF16 (810 GB) needs larger-memory GPUs such as H200.
  6. Front
    Active versus total parameters in MoE?
    Back
    Compute per token follows active parameters; memory and, at larger batches, bandwidth follow total. Mixtral 8x7B: 47B total, 13B active. DeepSeek-V3: 671B total, 37B active.
  7. Front
    How much of an MoE layer does a batch touch?
    Back
    With top-2 of 8 uniform routing, 1 − (3/4)^B: 25 percent at batch 1, 90 percent at 8, 99 percent at 16. A step then reads nearly all expert weights.
  8. Front
    Why do MoE deployments show p99 spikes?
    Back
    Expert parallelism waits for the slowest GPU, and hot experts (imbalanced routing) create stragglers. Mitigate with expert replication, balanced routing and routing-aware batching.
  9. Front
    How do you serve many fine-tunes on one GPU?
    Back
    Keep one base model resident and load small LoRA adapters on demand, batching across adapters. A rank-16 adapter on four projections of an 8B model is about 27 MB, 0.17 percent of the base.
  10. Front
    What are the costs of multi-LoRA serving?
    Back
    Adapter load latency, cache pressure, separate prefix caches per adapter (the adapter changes keys and values), and wasted memory from an oversized maximum rank setting.
  11. Front
    How do you choose an engine?
    Back
    Support for your model, quantization, adapters and structured output; performance on your own length distribution at your target latency; operational maturity; hardware lock-in. Check status: TGI was archived 2026-03-21.
  12. Front
    Which four hardware numbers matter?
    Back
    Memory capacity (what fits), bandwidth (decode speed), low-precision compute (prefill and large batch), interconnect (TP and EP scaling). Compare numbers on the same basis; datasheet peaks are often "with sparsity".
  13. Front
    Why is self-host cost at full load misleading?
    Back
    Cost per token scales with 1 / utilization. $2.50 per hour at 2,500 tokens per second is about $0.28 per million at full load and about $0.93 at 30 percent (illustrative).

Production operations: capacity, scaling and failure

  1. Front
    How many replicas do you need?
    Back
    Peak load ÷ per-replica goodput capacity ÷ target utilization (about 0.6 to 0.7), rounded up, plus spares for failures and deploys. Example: 7,500 tokens/s ÷ 2,000 ÷ 0.65 = 5.8, so 6 plus 1 spare.
  2. Front
    What is the Little's law check on a capacity plan?
    Back
    In flight = arrival rate × time in system. Divide by replicas and compare with the KV pool. 20 req/s × 9 s = 180; over 5 replicas is 36 each; a pool of 30 means cache is the constraint.
  3. Front
    Which autoscaling signals lead?
    Back
    Queue or waiting depth, KV-cache utilization, running sequences against benchmarked limits, TTFT p95, tokens per second against capacity. Not CPU, and not GPU utilization alone.
  4. Front
    What makes up cold start?
    Back
    Image pull, weight load (70 GB at 2 GB/s is 35 s), CUDA-graph capture and warm-up, in sequence. Mitigate with pre-pulled images, local weight caches, streamers, warm pools and scaling ahead of ramps.
  5. Front
    How do you scale up and down?
    Back
    Up fast, down slowly. Drain on scale-in: stop new requests, let streams finish up to a maximum generation time, then terminate. Minimum replicas for latency-sensitive tiers.
  6. Front
    How should requests be routed?
    Back
    Least loaded by queue depth or cache usage (cost varies 100 times), prefix-aware where it helps hits, session affinity for chat, adapter-aware, priority tiers, and a router that is itself evaluated.
  7. Front
    When is a retry safe, and what does hedging cost?
    Back
    Retry idempotent requests that failed before the first token, with jitter and the propagated deadline. Hedging sends a second copy of slow requests and doubles GPU load for the hedged share.
  8. Front
    Why does closed-loop load mislead?
    Back
    Clients wait for replies, so offered load drops when the server slows. A server with capacity 8 req/s looks stable. Use open-loop arrivals (Poisson at a set rate) to see queues and tails.
  9. Front
    What goes in an honest benchmark?
    Back
    Realistic length distributions, open-loop arrivals, TTFT and ITL at p50/p95/p99 and goodput at the target across load levels, warm-up discarded, cache hit rate controlled, hardware and precision fixed.
  10. Front
    What do repeated runs on one server do?
    Back
    They can reuse prefix-cache entries and inflate throughput. Vary the seed, restart, or use a sweep mode that resets caches.
  11. Front
    How do you debug a latency regression?
    Back
    What changed? TTFT up: queue, KV full or preemption, longer prompts, lower prefix hit rate, routing, cold replicas. ITL up: batch or context, prefill interference, throttling, interconnect. Reproduce, bisect, profile, fix, add an alert.
  12. Front
    Symptoms or causes: what do you page on?
    Back
    Page on symptoms (TTFT and ITL percentiles, errors, goodput, saturation). Put causes (KV use, queue, hit rate, preemptions, acceptance rate) on dashboards for diagnosis.
  13. Front
    How should a service degrade?
    Back
    Shed low-priority load, cut max tokens, switch to a smaller model, serve cached answers where valid, return clear 429 or 503 with a retry hint. Health checks must generate a token.

Inference engineering: interview drills

  1. Front
    Give the 90-second answer: why is decode memory-bound?
    Back
    Each step reads all weights for about 2 operations each, so intensity is near the batch size (for BF16), far below the ridge (about 295 on an H100). Batching raises intensity almost for free.
  2. Front
    What limits concurrency per GPU?
    Back
    The KV pool left after weights and overhead, divided by bytes per sequence. 2 × layers × KV heads × head dim × bytes per token, times tokens per sequence.
  3. Front
    Which levers move TTFT, and which move ITL?
    Back
    TTFT (queue plus prefill): prefix caching, chunked prefill, shorter prompts, capacity. ITL (decode step): fewer bytes (quantization), smaller batch or context, speculative decoding, parallelism.
  4. Front
    Batch-1 decode bound, worked.
    Back
    Step ≥ weight bytes ÷ aggregate bandwidth. 14B in 8-bit on 1.5 TB/s: 14 GB ÷ 1.5 TB/s = 9.3 ms, about 107 tokens per second. Ignores cache, communication and overhead.
  5. Front
    KV bytes and concurrency, worked.
    Back
    40 layers, 8 KV heads, 128, FP8: 81,920 bytes per token. A 4,096-token sequence is about 0.34 GB, so a 30 GB pool holds about 89.
  6. Front
    Speculative speedup, worked.
    Back
    α = 0.85, γ = 5, c = 0.08: expected tokens (1 − 0.85⁶)/0.15 = 4.15; speedup 4.15 ÷ 1.4 = about 2.97.
  7. Front
    Cost and replicas, worked.
    Back
    $2.80 per hour, 2,200 tokens/s at 50 percent: $0.71 per million. 18 req/s × 300 tokens = 5,400 tokens/s ÷ (1,500 × 0.65) = 5.5, so 6 plus 1 spare.
  8. Front
    What are the seven parts of a platform design answer?
    Back
    Clarify targets, estimate (Little's law, weights, cache), choose the stack, architecture, evaluation and rollout, failure modes and operations, cost and trade-offs.
  9. Front
    What marks a strong design answer?
    Back
    Numbers with assumptions, interactive and batch separated, cache arithmetic driving concurrency, autoscaling on queue or cache, a cold-start plan, a quality gate for quantization, failure modes raised unprompted.
  10. Front
    What do you do when the interviewer changes a constraint?
    Back
    Re-cost the design aloud: say what changes in the arithmetic, what you would add or give up, and what quality or operational risk you accept.
  11. Front
    Why does a reasoning model change serving cost?
    Back
    Hidden reasoning tokens are generated like output, so decode time, cache per request and cost all grow. Cap, budget or route by difficulty.
  12. Front
    What can explain a production TTFT four times worse than the benchmark?
    Back
    Fixed short prompts, closed-loop clients and a hot prefix cache in the benchmark. Replay real traces with open-loop arrivals and control the cache.
  13. Front
    Why scope KV-cache quantization by context length?
    Back
    Its accuracy risk grows with context. Evaluate by input length and keep 16-bit cache where long inputs matter.