Practice track

LLM inference

Tokenizers, sampling, beam search, the KV cache and LoRA. 11 problems, about 320 minutes. Do them in order: each problem uses ideas from the problems before it.

0 / 11 solved

  1. 01
    Sweep the sampling temperature

    Sweep the temperature on fixed logits, measure entropy and top 1 probability, find where entropy crosses 2 bits, and count the tokens top p keeps.

    From GPT — Causal Language Modeling

    LabEasy20 min
  2. 02
    LoRA linear layer

    Forward pass of a linear layer with a low rank adapter, merge of the adapter into the weight, and the trainable parameter count.

    From Fine-Tuning with LoRA & QLoRA

    ImplementEasy15 min
  3. 03
    Train a character bigram language model

    Train a table of next-character logits with gradient descent until the held-out negative log-likelihood beats a unigram model.

    From Text Generation Before Transformers — N-gram Language Models

    TrainMedium40 min
  4. 04
    Fixed-capacity KV cache

    Append keys and values to a preallocated cache, attend one query over the valid prefix, and reject an append past the capacity.

    From KV Cache, Flash Attention & Inference Optimization

    ImplementMedium25 min
  5. 05
    Temperature, top-k and top-p sampling

    Scale logits by temperature, keep the top k or the top p mass, renormalize, and draw one token with a seeded rng.

    From GPT — Causal Language Modeling

    ImplementMedium30 min
  6. 06
    Symmetric int8 quantization

    Absmax int8 quantization with one scale per tensor and one scale per row, with dequantization and a zero-row rule.

    From Quantization: Making Models Fit

    ImplementMedium20 min
  7. 07
    Sweep the quantization bit width

    Sweep symmetric absmax quantization from 2 to 8 bits on weights with outliers, compare one scale per tensor with one scale per row.

    From Quantization: Making Models Fit

    LabMedium30 min
  8. 08
    Read an SGLang sweep on an L4

    Use real SGLang runs on an NVIDIA L4 to find the saturation point, the SLO limit, the FP8 gain and the effect of a smaller prefill chunk.

    From Inference Metrics — TTFT, TPOT, ITL, Goodput, P99

    LabMedium30 min
  9. 09
    BPE pair counts and merges

    Count weighted adjacent pairs, pick the best pair with a fixed tie rule, merge it without overlap and train a BPE merge list.

    From BPE Tokenizer From Scratch

    ImplementMedium30 min
  10. 10
    Beam search with EOS and length normalization

    Keep the best beam_width partial sequences over a step function, finish beams at EOS, and rank them with a length penalty.

    From Sequence-to-Sequence Models

    ImplementHard45 min
  11. 11
    Speculative decoding: accept, reject and resample

    The min(1, p/q) acceptance rule and the residual distribution that keep speculative decoding exactly equal to the target model.

    From Speculative Decoding — Draft, Verify, Repeat

    ResearchHard35 min