Sampling Primitives
Implement the decoding-time math: stable softmax, temperature scaling, top-k/top-p filters, and stochastic vs greedy token selection.
Construct sampling, tokenization, KV caching, paged allocation, continuous batching, streaming, and benchmarking.
Every source step is its own lesson with intuition, concepts, correctly rendered MathJax mathematics, implementation, tests, mistakes, and a checkpoint.
Implement the decoding-time math: stable softmax, temperature scaling, top-k/top-p filters, and stochastic vs greedy token selection.
Build a tiny vocabulary plus encode/decode utilities to move between strings and token id sequences.
Implement embeddings, linear projections, a basic KV cache, causal attention, and the prefill/decode forward passes.
Design a block-based KV allocator with allocation/free, paged appends, gather, paged attention, and usage accounting.
Model per-request sequence state, drive single-sequence generation, then batch multiple sequences through synchronized decode steps.
Add capacity checks, priority queues, admission, preemption, and a scheduler that mixes prefill and decode across in-flight requests.
Expose a request/response interface with streaming chunks, submission, a driver loop, output collection, and completion responses.
Measure TTFT, inter-token latency, throughput, and latency percentiles with an end-to-end benchmark runner.