Lion Cipher Lab

Implement speculative decoding with two tiny language models, and prove it changes nothing but speed

Why it matters

Large language models write one token at a time, and every token needs a full pass through the big model. That makes generation slow and expensive, and it is why every serious inference stack (the software that runs models for you) now offers speculative decoding: a small, cheap model guesses a few tokens ahead and the big model checks all the guesses in a single pass. The promise is unusual. It is not 'faster but a bit worse'. The maths says the text comes out with exactly the same probabilities as if the big model had written it alone. If you work on AI systems, including AI tools in a SOC,…

What you'll learn

Steps in this lab

  1. The words first: target, draft, decode step, speculative decoding - and the fact that both models here are tiny
  2. Set up: a terminal, Python, numpy and a lab folder
  3. Make the synthetic corpus: SOC log lines, runbook sentences, and some recipes
  4. The two models and the meter: a slow, better target and three cheap drafts
  5. Read the algorithm: draft, verify once, accept with min(1, p/q), resample from the residual
  6. Prove it changes nothing: compare against the EXACT target distribution
  7. Greedy: byte-identical output, fewer target calls
  8. Measure the speedup for k = 1..8, and check it against the paper's formula
  9. Honest negative 1: a bad draft makes it slower than not speculating, and you could have predicted it
  10. Honest negative 2: the 'accept if it matches the target's top choice' shortcut silently changes the output
  11. Honest negative 3: large k wastes work, and the best k moves when verifying is not free
  12. When to use it, when not to, and how a pro switches it on

Open the full interactive lab →