Inference Kernels and Graph Execution

Inference uses unusual shapes, changing sequence lengths and repeated small decode steps. A kernel or graph optimization matters only when its numerical contract, dispatch coverage and engine-level effect all hold.

Section 5 of 9 · 12 units · about 48 hours

0/12

By the end you can Integrate one oracle-backed kernel or graph path, pass the serving shape and dtype matrix, explain its measured hardware bottleneck, and either demonstrate or honestly reject endpoint benefit under replayable load.

Units

Build it

Mini project · about 12 to 18 hours

Serving kernels with oracles, graphs and endpoint translation

Build independent CPU oracles for residual, attention, paged KV and sampling paths in engine/, with shape ledgers and a timing harness. Capture graphs, log compilation, wire one path through dispatch with fallback, and translate the win or keep the loss.

  1. 1Write double-precision CPU references for fused residual-add plus norm and online-softmax merges in engine/, checking retained residuals and activations through repeated calls with empty-partition and overlap policies stated.
  2. 2Derive prefill, cached-chunk and decode shape ledgers with FLOP and byte predictions for your workload matrix, plus stride and alignment dispatch cases with a fusion ledger that keeps conversion and retained-output costs.
  3. 3Build a page-gather and head-mapping oracle independent of backend scheduling, and prove appends across page boundaries with absolute RoPE positions under reorder, remap, compaction, cancellation and slot reuse with poisoned tails.
  4. 4Implement masked greedy and filtered stochastic selection with a declared filter order and tie policy, keep grammar and random state per request across slot changes, time mask work apart from selection, and pass the CS336 forward attention tests.
  5. 5Trace a two-stream producer and consumer dependency with completion events and buffer lifetimes, time completed serving steps with warmup and interleaved medians, and check cancellation-safe buffer reuse in a CPU event simulation with profiler ranges.
  6. 6Capture and replay a static-shape decode step with bucket, padding and miss accounting, log compile breaks with recompile counts and a tested eager fallback, check state reset after both, then translate one kernel win to endpoint TTFT, TPOT and goodput with per-phase dispatch logs, keeping the losing regime.
What you hand in
  • CPU oracles with shape ledgers, paged-KV lifecycle checks and the sampling oracle with per-request state tests.
  • Timing harness with warmup, interleaved medians, profiler ranges and the stream dependency trace.
  • Graph and compile evidence with dispatch logs, endpoint translation and the preserved losing regime.
How to check it
  • Self-grade with the rubric below
  • CS336 Assignment 2 attention tests

    Pass test_flash_forward_pass_pytorch, plus the Triton cases on your GPU; keep serving tolerances apart from the assignment contract.

How it's graded

Oracle independence

Pass: Oracles share no indexing, mask or reduction code with the candidate, and seeded shift and mask defects fail visibly.

Great: The matrix spans odd lengths, partial pages, empty rows and remapped allocations under stated per-dtype tolerances.

Lifecycle correctness

Pass: Append, gather, RoPE positions and sampler state survive reorder, compaction and slot reuse with poisoned tails inert.

Great: A stale-offset defect and a grammar-state leak are both caught by the request-identity tests.

Honest timing

Pass: Medians come from interleaved synchronized trials with stated boundaries, and profiler evidence backs the bottleneck call.

Great: Graph and compile wins translate to endpoint goodput by share math, or the negative result ships with its regime.

Resources