numerics-explained

/about

About this site

Numerics Explained is about the numbers inside a model: how a format spends its bits, how rounding and accumulation go wrong, and the scaling and quantisation tricks that let 8-, 6- and 4-bit numbers work. Each chapter is built around an animation. It is the fifth of a family of companion sites, with the Transformer Decoder Explainer, LLM Inference Explained, LLM Architectures Explained, GPU Kernels Explained and Systolic Arrays Explained. The chapters link the matching slides of the Local LLM hosting and Google TPU series.

The numerics library

reference/numerics.py is written in plain Python, so that every step is one IEEE double operation, and src/lib/num/model.ts repeats it operation for operation. It implements:

The tiny transformer

Chapters 8 and 9 quantise a real network: the Transformer Decoder Explainer's tiny model (two blocks, 16 wide, a 64-character vocabulary), whose TypeScript is vendored unchanged into this site, with a plain-Python port in reference/tiny.py. It runs in your browser twice, as is and with its weights or its KV cache quantised, and the pages compare the two over four prompts. Its weights are random, rescaled from the explainer's so that its blocks matter; its text is gibberish, its arithmetic real. A test proves the hooked forward pass equals the explainer's exactly, and the Python and TypeScript runs agree to a relative 10⁻¹² (they share exp, log, sin, cos and tanh, which each language may round differently in the last place) and exactly in every top prediction.

How it is checked

What is illustrative

The animations

Every animation has play and pause, step back and forward, a scrub bar, speeds from 0.25× to 4× and reset; with the animation focused, Space plays or pauses and the arrow keys step. Each step has a one-line caption, also announced to screen readers. With reduce motion set in your system, nothing plays by itself. Animations pause when scrolled out of view. Colours come from Okabe and Ito's colour-blind-safe palette, the same in light and dark mode: one colour per bit field (sign purple, exponent sky blue, mantissa green, shared scale orange) and one per method (nearest-even blue, stochastic orange); an error is a warning colour.

Source

The code, the library and the tests are on GitHub (MIT licence). The design system is copied from the companion sites; the README records where each piece came from.