Skip to content

The Toy Box

Forty interactive pieces, out of their boxes

These forty examples come from the series. Adjust a value, step through a calculation, or inspect a diagram. Each one links back to the post that explains its assumptions and use.

Foundations

The math and the hardware everything else stands on.

01

Play with a matrix

from 1.1→

Choose a preset or edit the numbers directly. The columns of the matrix are exactly where the basis vectors land.

02

Matmul, one cell at a time

from 1.1→

Each output cell is one dot product: a row of A against a column of B. Step through the products and their sum.

03

Three optimizers race down a valley

from 1.6→

Compare SGD, momentum, and Adam on the same surface. Their paths depend on the chosen learning rates; this example does not establish a best optimizer.

04

The temperature dial

from 1.3→

Drag T. Low temperature collapses the distribution onto the winner; high flattens it toward uniform. The ranking never changes.

05

The bits inside a float

from 1.7→

Try 65504, 65519, and 65520 to inspect rounding at the fp16 overflow boundary. Compare the exponent range and precision with bfloat16.

Language before transformers

What prediction looked like before attention, and why it worked.

06

Shannon's guessing game

from 1.8→

Inspect hand-chosen character distributions as context grows. The entropy and observed-character loss are calculated from these toy probabilities, not measured from English.

07

king − man + woman

from 2.3→

Select an analogy and inspect the vector arithmetic. These hand-placed two-dimensional points illustrate offsets; they are not trained embeddings.

08

One LSTM timestep

from 2.6→

Step through supplied gate values and calculate the updated cell and hidden states. The forget gate scales old values; the input gate controls what is added.

Tokens

How text becomes the token IDs a model receives.

09

What is a character, anyway

from 3.1→

One family emoji: 1 grapheme, 7 code points, 25 bytes. Choose an example and watch the three layers come apart.

10

Watch a vocabulary grow

from 3.2→

Follow the most frequent adjacent pair through successive merges in a small training corpus.

11

Encoding is a replay

from 3.2→

Apply learned merge ranks to a new input. The base vocabulary determines which initial symbols can be represented.

12

The optimal split

from 3.3→

Use dynamic programming to find the highest-scoring segmentation among the vocabulary pieces available at each position.

Inside the transformer

The machine itself, one block at a time.

13

A whole attention head

from 4.1→

Four tokens, five steps. Select a token and trace its query through the scores, the softmax, and the weighted sum.

14

The triangle

from 4.3→

Toggle bidirectional against causal. Each token sees one more position than the last, and the upper triangle is exactly zero.

15

Position as rotation

from 4.4→

Three dimension pairs, three speeds. The fast pairs encode fine position, the slow pairs encode coarse. That's RoPE.

16

A key–value view of a toy FFN

from 4.5→

Select a neuron: its row of W₁ defines a pattern, and its activation scales the corresponding W₂ column added to the output.

17

Suppress a feature in a toy FFN

from 4.5→

Suppress features and inspect the computed logits in this constructed example. It does not identify where a real model stores a fact.

18

Tokens choose their experts

from 4.9→

Each token routes to a subset of experts, reducing active feed-forward computation. Router and communication costs still matter.

Inference, one token at a time

What actually happens when a model generates.

19

One new token, one new row

from 5.3→

Advance decoding and inspect the new query row over the growing key sequence. Cached keys and values are reused; old attention rows are not the KV cache.

20

Watch the cache grow

from 5.4→

Change the model, KV-head count, and sequence length to calculate cache storage. Head sharing reduces this cost, but weights and other buffers also need memory.

21

The sampling pipeline

from 5.5→

Temperature, top-k, top-p, and min-p on live bars. Set a combination, then select Sample and draw a token.

22

Draft, then verify

from 5.6→

Inspect a draft-and-verify round. Exact speculative sampling preserves the target distribution when implemented correctly; acceptance rates and verification costs determine the speedup.

23

JSON by construction

from 5.9→

Step through allowed choices in a small JSON grammar. Constraining syntax does not guarantee a correct answer, and generation can still stop before completion.

Serving systems

The engineering that turns a model into a service.

24

Refill completed request slots

from 5.7→

Compare a fixed batch with a scheduler that admits waiting requests as slots become free. This toy schedule assumes work is ready to run.

25

Virtual memory for the KV cache

from 6.3→

Three requests scattered through a shared block pool, each holding a tiny block table. This is PagedAttention.

26

Copy a page, not the cache

from 6.3→

Two requests share a system prompt until one writes. Only the written block gets cloned; everything else stays shared.

27

Attention without the N×N matrix

from 6.2→

Inspect score tiles and the running softmax statistics. The full score matrix need not be materialized in HBM.

28

Will it fit?

from 6.4→

Estimate weight and KV-cache storage under explicit assumptions. Leave room for workspaces, activations, and runtime overhead before choosing concurrency.

29

The knee

from 6.7→

Change the batch size under the displayed cost assumptions to compare throughput with per-request latency. The useful operating point depends on the workload and latency target.

Training & post-training

How the weights get made, and made agreeable.

30

Choose which targets contribute loss

from 7.3→

Calculate assistant-only target loss. Gradients can still pass through computations that used the masked prompt tokens.

31

PPO’s clipped surrogate

from 7.4→

Change the probability ratio and compare both advantage signs in the clipped surrogate. Clipping limits part of the objective; it does not guarantee stable training or a hard trust region.

32

Expert collapse

from 4.9→

Explore a constructed routing-feedback example. Its selected rules illustrate collapse; they do not predict that real training must reach the same allocation.

Retrieval & context

Getting the right information in front of the model.

33

One question, eight stages

from 9.6→

Follow a constructed question through the retrieval pipeline and inspect the data passed between stages.

34

Embed the answer, not the question

from 9.6→

HyDE embeds a generated hypothetical document to retrieve source passages. Inspect the example; the generated text is not evidence and may lead retrieval astray.

35

The living summary

from 9.9→

Old turns compact into a running digest while the last few stay verbatim. The model's view stays small as the conversation grows.

Agents & protocols

The loop, and the standards forming around it.

36

The loop is the agent

from 10.3→

Follow generation, runtime dispatch, tool results, and resumption. This example keeps the model’s supplied state in the transcript.

37

Three calls, one wait

from 10.3→

Compare three independent calls under the displayed duration assumptions. Parallel execution can reduce the wait when dependencies and service limits permit it.

38

N×M becomes N+M

from 10.5→

Compare N×M bespoke connections with N+M protocol adapters in this schematic count. Standardization does not remove deployment, compatibility, or authorization work.

39

An MCP initialization and tool exchange

from 10.5→

Step through a schematic initialization, tool discovery, and call. Transport and authorization requirements also matter for a working connection.

40

PKCE in one picture

from 10.6→

Follow the code challenge and verifier in a PKCE exchange. The verifier binds redemption to the client that started it; other OAuth checks are still required.

Every toy here does its real work inside a post, surrounded by the argument it belongs to. If one of them made something click, the series index and the map will take you the rest of the way.