Lion Cipher Lab

Build an autograd engine from scratch, and prove its gradients with a numerical check

Why it matters

Every model in security tooling, from a phishing classifier to an LLM, is trained by gradients that an automatic differentiation engine computed. You never see that engine. You call backward() and trust it. In Part 1 you derived backprop by hand for one small network. That works once and does not scale, because every new layer means new calculus and new chances to slip. This lab builds the machine that does the calculus for you, in about 100 lines, so the frameworks stop being magic. Then it teaches the habit that separates engineers from tutorial-followers: you do not trust a gradient you…

What you'll learn

Steps in this lab

  1. What you are building, and Part 1 in one paragraph
  2. Set up: a terminal, Python, and a lab folder
  3. Write the engine: a Value that remembers how it was made
  4. Prove it: a numerical gradient check on 200 random graphs
  5. Check all 121 MLP parameters, then find the right epsilon (the U-shaped curve)
  6. Plant two classic bugs and watch the check catch them
  7. Train it on synthetic login events: before and after
  8. Honest negative 1: a passing gradient check does not mean a good model
  9. Honest negative 2: the relu kink, where correct code fails the check
  10. Honest negative 3: float32 vs float64, and how slow scalar autograd really is
  11. Do it better: how a professional uses gradient checks

Open the full interactive lab →