Roadmap/Phase 06
PHASE 06 OF 06

Production Engineering and Specialization

Read the engines line by line, write your own kernels, and ship work that other engineers can see.

0%
12 topics30 lessons162 h
In plain English

Up to now you have been learning to drive the car and tune its engine. This phase is about opening the hood, reading the manufacturer's blueprints, and machining your own parts. You will read the real source code of vLLM, SGLang and TensorRT-LLM, write GPU kernels in Triton and CUDA, design a full production serving system on paper with the math to back it, and then step outside your own machine by contributing a fix to an open-source engine and publishing what you learned. The goal is to turn private understanding into public, verifiable work.

What you can do afterwards

You can navigate the vLLM, SGLang and TensorRT-LLM codebases to answer a question in under an hour, write and benchmark a Triton or CUDA kernel that beats or matches PyTorch for a specific shape, produce a capacity-planned design document for a production inference cluster, and point to a merged pull request, two technical blog posts and a portfolio page as proof.

Milestones

  1. M1Reading production engines
  2. M2Writing your own kernels
  3. M3Shipping and being seen

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 Triton attention kernel and ship it as a torch custom op

Colab T4 · free~10 h
one evening to a weekend · required for phase completion

Write a fused attention forward kernel in Triton (online softmax, causal mask, fp16 inputs with fp32 accumulation), register it as a torch.library custom operator with a fake implementation, prove it runs under torch.compile with no graph breaks, and benchmark it against F.scaled_dot_product_attention on a T4. This is the Phase-6 kernel loop in miniature, from blank file to installable package with numbers.

Scope

  • A Triton kernel attn_fwd with BLOCK_M query tiles, a loop over BLOCK_N key tiles, running max and sum, and a causal flag.
  • An autotune config list over block sizes, num_warps and num_stages, with the winning config logged per sequence length.
  • A torch.library.custom_op registration (schema, CUDA implementation, fake implementation, explicit non-differentiable) and torch.library.opcheck in the tests.
  • A pytest suite comparing against SDPA at N in (128, 512, 1024, 2048, 4096), heads 8, d 64, causal and non-causal, fp16 and fp32.
  • A torch.compile(fullgraph=True, dynamic=True) test over three sequence lengths with TORCH_LOGS=graph_breaks captured.
  • A bench.py producing a latency and TFLOP/s table and plot versus SDPA, plus a pip-installable package.

Out of scope

  • Backward pass or training.
  • Paged KV or block tables (the medium and large capstones and the custom-attention build cover those).
  • Hopper-only features such as TMA or wgmma.

What to measure

Numerical agreement with SDPA
How · torch.testing.assert_close over all test shapes, fp16 atol 2e-2, fp32 atol 1e-4
Target · all pass
Peak memory scaling
How · torch.cuda.max_memory_allocated at N 2048 versus 4096
Target · less than 2x growth (no materialized N by N scores)
Speed relative to SDPA on T4
How · CUDA-event median of 50 runs at N 2048 and 4096 fp16, batch 4, heads 8
Target · 0.5x to 1.2x of SDPA; report the ratio
torch.compile integration
How · count of graph breaks in TORCH_LOGS=graph_breaks for the compiled wrapper module
Target · 0 graph breaks
Clean-environment install
How · pip install the package in a fresh Colab runtime and run pytest
Target · exit 0

Pay attention to

  • The rescaling factor exp(m_old minus m_new) must be applied to both the running sum and the accumulator; a kernel that is right for one tile and wrong for two is the classic bug.
  • Causal masking must be applied before the running max update, and tiles entirely above the diagonal should be skipped, not masked.
  • T4 (sm_75) has fp16 tensor cores but no bf16; use fp16 inputs and fp32 accumulators and do not quote bf16 numbers.
  • The fake implementation must return the output shape from symbolic sizes, not from running the kernel; opcheck will catch this.
  • Warm up and lock clocks as far as Colab allows; report medians, not minimums.

Acceptance (all must pass)

  • ☐pytest passes all correctness shapes for causal and non-causal in fp16 and fp32.
  • ☐torch.library.opcheck passes and the compiled module shows zero graph breaks at three lengths including one unseen at compile time.
  • ☐Peak memory at N 4096 is less than 2x that at N 2048.
  • ☐README has the benchmark table with the SDPA ratio and the chosen autotune configs.
  • ☐A fresh runtime can pip install the package and pass the tests.
Deliverable · A repository with the Triton kernel, custom op registration, tests, bench.py, results.csv, plot and a README with the numbers.
No GPU? · Use a Kaggle T4 if Colab has no GPU. Without any GPU, run the tests under TRITON_INTERPRET=1 on the Mac for correctness and the compile integration, and mark the speed and memory rows of the table as not measured.
Stretch · Add a paged-KV decode variant that reads through a block table and compare with the custom-attention build. · Add sliding-window attention and measure the saving at N 8192.
Medium

Build your own Rust inference gateway

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

Extend the Rust router build into a production-shaped gateway: OpenAI-compatible routing across several engine backends with prefix-aware and least-loaded policies, SSE streaming, request coalescing, retries with budgets and circuit breakers, admission control, Prometheus metrics and tracing, a config reload path, and a load test that proves the latency overhead and failure behaviour. The backends are the Phase 5 stub engine and, optionally, a real vLLM on Colab exposed through a tunnel.

Scope

  • An axum or hyper service implementing /v1/chat/completions and /v1/completions (streaming and non-streaming), /healthz, /readyz and /metrics.
  • Backend pool with health checks, least-in-flight and prefix-affinity routing (hash of the first 256 prompt tokens or characters), drain on shutdown.
  • Retries with a per-request budget and backoff for errors before first byte, a per-backend circuit breaker, and request timeouts that cancel the upstream stream.
  • Coalescing of identical deterministic requests and a bounded in-flight limit returning 503 with Retry-After.
  • Prometheus metrics (requests by backend and status, TTFT and e2e histograms, in-flight, queue depth, breaker state) and tracing spans with request ids propagated to upstreams.
  • A chaos harness that kills, slows and errors stub backends mid-load, and an oha or k6 load test with a report.
  • A TOML config with hot reload of the backend list via SIGHUP or a file watcher.

Out of scope

  • Authentication, billing or multi-tenant quotas beyond a static API key check.
  • Running real GPUs as backends (optional via a Colab tunnel, not required).
  • A Kubernetes deployment (document how it would be deployed instead).

What to measure

Added latency
How · oha at 200 and 1000 concurrent streaming requests against stubs directly and through the gateway, p50 and p99
Target · under 5 ms p50 and under 25 ms p99 added at 1000 concurrency
Failover correctness
How · kill one of three backends during a 60-second run and count client errors
Target · zero client errors for requests that had not received a first byte; all post-first-byte failures surface as a single error event
Prefix affinity
How · 1,000 requests sharing 10 system prompts, measure the share routed to each prompt's preferred backend
Target · at least 90 percent while backends are healthy
Coalescing
How · 100 identical deterministic requests in flight at once, count upstream requests
Target · exactly 1
Resource usage
How · RSS and CPU of the release binary at 1000 concurrency
Target · under 150 MB RSS; report CPU
Overload behaviour
How · 2x the configured max in-flight, count 503s and successful requests
Target · successes equal the limit within 5 percent and every rejected request carries Retry-After

Pay attention to

  • Streams must be cancelled upstream when the client disconnects; check /stats on the stub for orphaned streams after a client abort test.
  • Retrying after the first byte duplicates output; the retry budget must apply only to connection errors and pre-first-byte status codes.
  • Backpressure needs bounded channels; an unbounded channel hides a slow client until the process is out of memory.
  • Circuit breakers need half-open probes or a dead backend never recovers; test the recovery path explicitly.
  • Histogram buckets must cover 10 ms to 60 s or the p99 figures are meaningless; pick them before load testing.
  • cargo clippy with -D warnings and no unsafe blocks; reviewers will grep for unwrap on request paths.

Acceptance (all must pass)

  • ☐cargo test passes including the failover, coalescing, affinity, overload and client-abort integration tests.
  • ☐The load test report shows the added-latency and overload targets met and is reproducible with one script.
  • ☐/metrics exposes every listed metric and a Grafana dashboard JSON (or a text description of panels) is included.
  • ☐Hot reload adds a backend without dropping in-flight streams (asserted by a test that reloads mid-stream).
  • ☐README documents the architecture, the config file, the failure matrix and how it would run under Kubernetes.
Deliverable · A public repository with the Rust gateway, stub engine, integration tests, chaos and load scripts, load test report, dashboard and README.
Stretch · Point one backend at a real vLLM on Colab through a tunnel and repeat the latency measurement with real token timing. · Add KV-utilization-aware routing by polling vLLM's /metrics and compare queueing against least-in-flight. · Add a gRPC backend protocol alongside HTTP and measure the per-token overhead difference.
Large

Build your own end-to-end inference platform

Colab T4 · free~60 h
1-3 weeks · portfolio piece

Assemble the whole course into one system you can demo: your Phase-3 mini-vLLM engine with the Phase-4 optimizations (Triton or CUDA paged attention, fp8 or int8 weights, CUDA Graphs or torch.compile for decode, speculative decoding optional), two engine replicas behind your Rust gateway, Prometheus and Grafana observability with SLO dashboards, a load test and chaos drill, and a public write-up with a recorded demo. It is the portfolio piece a hiring team can read in ten minutes and verify in an hour.

Scope

  • The mini-vLLM engine (Qwen2.5-0.5B or TinyLlama, fp16 on the T4) with continuous batching, chunked prefill, paged KV and prefix caching, exposed as OpenAI-compatible HTTP with SSE and a /metrics endpoint.
  • At least two kernel-level optimizations from Phase 4 and 6 integrated and measured before and after (a custom paged attention kernel from this phase, int8 or fp8 weights, CUDA Graphs or torch.compile on the decode step).
  • Two engine replicas (two Colab or Kaggle sessions through tunnels, or two processes on one GPU with a memory split) behind the Rust gateway from the medium capstone with health checks, routing and failover.
  • Prometheus scraping gateway and engine metrics, Grafana dashboards for TTFT, ITL, throughput, KV utilization, queue depth and error rate, and alert rules for the SLOs you define.
  • A capacity plan from the planner build predicting throughput and max concurrency for the T4 setup, compared with the measured numbers.
  • A load test suite (your Phase-3 load generator) at three concurrency levels and one chaos drill (kill a replica mid-run) with recorded results.
  • A public write-up (blog post or long README) with architecture diagram, numbers, what went wrong, and a 5-minute recorded demo.

Out of scope

  • Multi-node tensor parallelism or disaggregated prefill/decode (Phase 5 covered them in simulation).
  • Models larger than 1.5B parameters; the point is the system, not the model.
  • Authentication, billing or a web UI beyond a curl example and the demo script.

What to measure

Engine correctness
How · greedy tokens for 20 prompts versus Hugging Face transformers in fp16 on the same GPU
Target · identical for at least 32 tokens on 18 of 20 prompts; document the divergences
Optimization gain
How · decode tokens per second at batch 16, context 1024, before and after each optimization, median of 5
Target · at least 1.5x cumulative over the unoptimized engine; report per-optimization gain
Engine throughput versus plan
How · planner prediction versus measured tokens per second at batch 1 and 32 and max concurrency at 2048 context
Target · within 30 percent or explained by a named mechanism
End-to-end SLOs under load
How · load generator at 3 concurrency levels through the gateway, p99 TTFT and p99 ITL
Target · report the levels; state the highest concurrency at which p99 TTFT is under 2 s and p99 ITL under 100 ms on the T4
Failover
How · kill one replica at the midpoint of a 5-minute run and count client-visible errors and recovery time
Target · zero errors for not-yet-started requests; recovery under 10 s; report the streams interrupted
Observability coverage
How · list of SLO dashboards and alert rules, each tested by inducing the condition
Target · every alert fires in the drill and clears afterwards

Pay attention to

  • Keep the engine's correctness suite running after every optimization; a 1.5x speedup that changes tokens is a regression, not a win.
  • Prefix caching and paged attention interact; a block freed while still referenced shows up as rare garbage tokens under load, so test with high concurrency and shared prefixes.
  • CUDA Graph capture requires static shapes; pad batch sizes to a small set of buckets and prove the padded path matches.
  • Two sessions through tunnels add tens of milliseconds; measure gateway overhead against the tunnel baseline, not against localhost.
  • Prometheus histogram buckets and scrape interval decide what the dashboards can show; set them before the load test.
  • Reviewers will run your demo script; it must work from a clean clone with pinned versions and clear instructions for the Colab part.

Acceptance (all must pass)

  • ☐A clean clone plus the documented Colab steps brings up engine, gateway, Prometheus and Grafana and serves a streamed completion through the gateway.
  • ☐Engine correctness and optimization-gain measurements are in the README with reproduction commands and raw CSVs.
  • ☐The load test and chaos drill reports exist with plots, and every alert rule has a recorded firing in the drill.
  • ☐The capacity plan versus measurement table is present with explanations for the largest gaps.
  • ☐A public write-up and a recorded demo video are linked from the README.
  • ☐All source for engine, kernels, gateway and dashboards lives in the repository with tests that pass in CI (CPU parts) and in a documented Colab run (GPU parts).
Deliverable · A public repository (engine, kernels, Rust gateway, dashboards, load and chaos scripts, results), a published write-up and a 5-minute demo recording.
No GPU? · If no GPU is available for a stretch of time, run the engine on CPU with GPT-2 small (the Phase-1 engine extended with the Phase-3 scheduler) behind the same Rust gateway, keep every gateway, observability, load test and chaos deliverable identical, and mark the kernel optimization and GPU throughput rows as not measured with the CPU numbers in their place.
Stretch · Add speculative decoding with a smaller draft model and show the acceptance rate and tok/s change on the dashboard. · Replace the stub replicas with real vLLM for one backend and compare your engine with vLLM on the same dashboard. · Add KV-utilization-aware autoscaling of replicas using the Phase 5 autoscaler build against a simulated fleet.