Lab 01 — Platform Capstone: the End-to-End Multimodal Agentic Serving Model
Phase: 19 — Capstone: Production Multimodal Agentic Serving Platform Difficulty: ⭐⭐☆☆☆ (the arithmetic reuses Phase 00; the integration judgment is ⭐⭐⭐⭐⭐) Time: 4–6 hours
The finale. Every earlier lab built one mechanism in isolation — the attention block, the LoRA delta, the PagedAttention block table, the ReAct loop, the eval harness. This lab composes them into one design you can score, SLO-check, and defend. You build a
PlatformDesignwhose knobs are the whole track (model size + quant from P00/P06, KV-cache from P00/P02, RAG retrieval from P11, the agent loop from P12, speculative decoding from P09, guardrails + verification from P16/P14), then the functions that turn those knobs into memory (weights + KV-cache + fit), latency that composes additively across stages, cost per 1k requests, quality/safety scores, an SLO check that returns the exact violations, and the decision:choose()filters to SLO-meeting designs, ranks them by weighted score, and names the deciding dial — and the winner flips when the workload's priorities change. That flip, and the additive composition, are the two souls of the lab.
What you build
PlatformDesign— one dataclass holding every knob the track exposes:n_params,quant_bytes_per_param,n_layers,d_model,seq_len,batch,bandwidth,peak_flops,gpu_hourly_usd, and the stage flagsuse_rag/use_agent(agent_steps) /use_speculative(accept_rate), plus the quality/safety component scores. Range-validated.- Memory —
weights_bytes,kv_cache_bytes(the Phase 00 formulas, unchanged),total_gpu_bytes, andfits_on_gpu— where the KV-cache is the swing factor between a design that just fits and one that just OOMs. - Latency —
prefill_latency_ms(compute-bound),decode_tokens_per_sec(bandwidth-bound; speculative multiplies by the accept-rate factor),ttft_ms(prefill + RAG retrieval),tpot_ms, ande2e_latency_ms= TTFT +output_tokens·TPOT+ agent-loop overhead — latency composes additively across stages. - Cost —
cost_per_1k_requestsfrom throughput and GPU price; falls with batch because batching amortizes the weight read. - Quality / safety / SLO —
quality_score(RAG bumps grounding, agent bumps capability, quant dings it),safety_score(guardrails + verification compound, defence in depth),meets_sloreturning the exact ordered violation list. - The decision —
DIALS,score_design, andchoose: filter to SLO-meeting designs, rank by the weighted dial score, report the deciding dial — and watch the winner flip.
Key concepts
| Concept | What to understand |
|---|---|
| Composition over invention | the capstone invents nothing new — it plugs each phase's mechanism into a slot and asks "does the whole thing meet the SLO?" |
| KV-cache is the swing factor | weights are fixed; fits_on_gpu flips from True to False when batch × context grows the cache, not the weights (P00 Ch 4) |
| Latency is additive | RAG + prefill + decode + agent loop are independent stages that sum — adding a stage adds exactly its milliseconds |
Speculative ≈ 1/(1−accept) | verifying several draft tokens per weight read raises tokens/sec by the accept-rate factor (P09) |
| Batching amortizes the read | one weight read serves batch sequences ⇒ $/request ∝ 1/batch (P00 Ch 7) |
| Defence in depth | guardrails and verification compound: safety = 1 − (1−g)(1−v) (P16/P14) |
| Filter then rank | choose drops SLO-violators first, then optimizes among the feasible — constraints before objective |
| The deciding dial | "best platform" is a category error; best for these weights is engineering, and the winner flips |
Files
| File | Purpose |
|---|---|
lab.py | skeleton with # TODO markers — your implementation |
solution.py | complete reference; python solution.py runs a worked example |
test_lab.py | the proof — run it red, make it green |
requirements.txt | pytest only (pure stdlib otherwise) |
Run
pip install -r requirements.txt
pytest test_lab.py -v # against your lab.py
LAB_MODULE=solution pytest test_lab.py -v # against the reference
python solution.py # the worked example
Success criteria
- All tests pass against your implementation (and
LAB_MODULE=solution). - You can explain why
test_fits_on_gpu_boundary_kv_is_the_swingflips on the KV-cache and not the weights — and why that is the #1 capacity mistake in a serving design. - You can explain why
test_e2e_adding_rag_increases_by_exactly_retrieval_msandtest_e2e_agent_loop_adds_steps_worthare the composition soul: a real platform's latency is a sum of stage budgets, and you size each stage independently. - You can explain why speculative decoding multiplies throughput by
1/(1−accept_rate)and why that does not change the FLOPs, only the bytes-moved efficiency. - You can read
meets_slo's violation list and say which subsystem to fix for each tag. - You can explain why
test_choose_winner_flips_with_prioritiesis the tradeoff soul — the same Phase 00 lesson, now over a full composed platform. - Given a "design a multimodal agentic assistant" prompt, you can populate a
PlatformDesign, compute its memory/latency/cost, check it against an SLO, and name the deciding dial — on paper.
How this maps to the real stack
| The miniature | The production mechanism | Where to verify it |
|---|---|---|
PlatformDesign | the capacity/architecture spec a serving team writes before provisioning | vLLM/TensorRT-LLM launch config; your design-review doc |
weights_bytes / kv_cache_bytes / fits_on_gpu | the GPU-count and gpu_memory_utilization decision (KV blocks reserved up front) | vLLM gpu_memory_utilization, max_model_len, max_num_seqs |
prefill_latency_ms / tpot_ms / ttft_ms | the TTFT/TPOT split every latency SLO is written in | vLLM/TGI latency logs; load-test p50/p99 TTFT & TPOT |
decode_tokens_per_sec (+ speculative) | continuous-batching throughput and the speculative-decoding speedup | vLLM throughput metrics; --speculative-model acceptance logs |
e2e_latency_ms (additive stages) | the request trace: retrieve → prefill → stream → tool-loop, each a span | OpenTelemetry/Langfuse trace waterfall; the per-span budget |
cost_per_1k_requests | the unit-economics number in the build-vs-buy and pricing decision | cloud GPU $/h ÷ measured tok/s; the FinOps dashboard |
quality_score / safety_score | the composed eval + guardrail score the deploy gate reads | your eval harness (P16) + guardrail pass rate |
meets_slo | the eval/SLO gate in CI/CD that blocks a bad rollout | the deploy pipeline's gate step (P17) |
choose | a scored, SLO-filtered architecture decision with the deciding dial in the ADR | your architecture decision record template |
Limits of the miniature (be honest in the interview): latency here is a clean additive
model — real systems have queueing delay, prefix-cache hits, batch-formation jitter, and p99
tails that a mean stage budget hides; the cost model charges by produced tokens at the decode
ceiling and ignores prefill GEMM time and idle GPUs at low traffic; quality_score /
safety_score are stand-ins for real eval suites and red-team results; and the dial
normalization in choose is relative to the candidate pool, so adding a candidate can shift
scores. The point is the structure of the decision, not five-decimal precision.
Extensions (build these on real hardware)
- Add queueing: model TTFT as
prefill + queue_wait(batch, arrival_rate)and find the arrival rate where p99 TTFT breaks the SLO (the real autoscaling trigger). - Add a prefix-cache hit rate that discounts prefill for shared system prompts (P09), and show how it changes the cost/latency of a high-traffic chat workload.
- Add a multi-GPU branch: tensor-parallel splits weights and KV across
tpGPUs; recomputefits_on_gpuand the$/1kwith the extra GPUs (P10). - Replace
quality_score/safety_scorewith the outputs of the real Phase 16 eval + guardrail labs, and wiremeets_slointo the Phase 17 CI/CD gate so a bad design literally fails the pipeline. - Run the chosen design on a real GPU with vLLM and check
decode_tokens_per_secand$/1kagainst measured throughput — then write the ADR with the deciding dial.
Interview / resume
- Talking points: "Design a multimodal agentic assistant under a TTFT/TPOT/cost SLO — walk the stages and where each phase's mechanism lands." "Why is the KV-cache, not the weights, your capacity number?" "How does speculative decoding change throughput without changing FLOPs?" "Two candidate platforms — defend the choice with the deciding dial." "How does the eval/SLO gate block a bad rollout?"
- Resume bullet: Built an end-to-end serving-platform model that composes weight + KV-cache
memory, additively-composed TTFT/TPOT/agent-loop latency, speculative-decoding throughput,
$/1k-request cost, and composed quality/safety into an SLO-gated, priority-weighted architecture decision with an explainable deciding dial — the design-review artifact for a multimodal agentic LLM platform.