Forward Pass
ModelAgentsAbout
MachineAnatomyScale
loading model
Live in your browser · nothing pre-recorded

Inside a language model, as it writes.

A real neural network is running in this tab. Give it a prompt and follow every step it takes to choose each next word: the tokens it reads, where its attention goes, and the odds it gives every word it knows. Every number on this page is computed live, on your device.

Parameters
15.2M
Layers
6
Attention heads
6
Vocabulary
32K
Last token
–ms
Work per token
–M ops
Prompt
This small model was trained on short, simple stories, so it writes in that style. To train one like it yourself, on text you pick, try Nanotech, a GPT training lab in your browser that the makers of Forward Pass also run.
Enter to run · Shift + Enter for a new line
Speed
Next token
Waiting for the model…
The machine

Six layers, unrolled over the text

One column per token. Information climbs through six layers; each cell shows the model's best guess so far, and the curves show which earlier tokens it read. Click any cell to take it apart below.

Loading 15.2 million parameters
0.0 / 16.5 MB

The weights download once; after that everything runs locally, in a background thread. No server does any of the thinking.

Anatomy · 10 stages

One token, step by step

The machine above does ten things to produce each token. Each gets its own instrument below, showing the real numbers for whichever token you select, in the bar or by clicking the machine.

01tokenize

Text becomes tokens

The model never sees letters. A tokenizer chops the text into pieces from a fixed vocabulary of 32,000 (the same one Llama 2 uses), and each piece becomes a number.

It starts from single characters, then keeps merging the adjacent pair that forms the most common known piece. That order was learned in advance from a large body of text: ␣t was the very first merge learned, ␣upon the 2,242nd.

Common words end up as one token. Rarer ones are spelled from parts, which is why this model sees the name “Lily” as ␣L + ily. A space belongs to the word after it (shown as ␣).

Every text also starts with a special <s> token that marks the beginning of a document.

Byte-pair encoding, replayed
69 characters → 0 tokens
Type anything: a word you made up, another language, an emoji.
merge 0/0
Start: one symbol per character, plus the leading space the tokenizer adds.
02embed

Each token becomes 288 numbers

A token id is just a row number. It selects one row of a table with 32,000 rows and 288 columns. That table is 9.2M of the model's 15.2M parameters.

Nobody wrote these numbers. They started random and were nudged, billions of times during training, until the model predicted text well. Tokens used in similar ways drifted toward similar rows.

So meaning becomes geometry. The neighbours listed here are computed right now: the cosine similarity of this row against all 32,000 others.

The galaxy squeezes the 288 dimensions down to 3 (a UMAP projection), so distances are only roughly kept. Drag it to turn it; click a point to inspect that token.

Embedding row
row
Nearest tokens
03position

Where each token sits

Attention (next) compares tokens with each other, and on its own it would not know their order. This model marks position by rotating vectors: each pair of numbers in a head turns by an angle proportional to the token's position.

Each head works on 48 numbers, taken as 24 pairs. Pair 1 turns a full radian per position; each later pair turns more slowly, down to about one ten-thousandth of a radian for pair 24. Fast pairs track nearby order, slow pairs track long distances.

The trick (rotary position embedding, used by Llama and most modern models) is that when two rotated vectors are compared, only the difference of their angles survives. So attention sees how far apart two tokens are, not where they are in absolute terms.

Query pairs of head 1, layer 1
position 0
before rotation after rotationArrow length is the pair's size; rotation never changes it.
Rotation angle of every pair at every position
Rows: pairs 1 to 24 (fast to slow). Columns: positions 0 to 0. Color: cosine of the angle (blue +1, pink -1). The fast pairs cycle quickly; the slow ones barely move over a whole story.
04attention

Tokens look back at each other

This is how context gets in. Each token asks a question (its query), every earlier token offers a label (its key) and a message (its value). The better a key matches the query, the more of that token's message is copied forward.

Match = dot product of query and key, divided by √48. A softmax turns the matches into weights that add up to 100%, and the token receives the weighted mix of values. A token can only look backward: the future does not exist yet.

Each layer runs 6 of these heads side by side, each with its own learned questions. Below are all 36 of them on your text. Some settle into clear jobs, like always looking at the previous token; many park unused attention on <s>, a well-known habit called an attention sink.

All heads (rows: layers, columns: heads)
h1h2h3h4h5h6L1L2L3L4L5L6
Each square is a head's full pattern: row = the token asking, column = the token looked at, darker = more attention. Labels are measured from the pattern on this text.
Layer 1, head 1:
The dark triangle is the causal mask: a token cannot see what comes after it. Click a row to select that token.
Selected token
05neurons

Then each token thinks alone

After attention mixes in context, each token goes through a small network on its own: its 288 numbers are expanded into 768 neurons, filtered, and folded back into 288. About two-thirds of each layer's weights live here.

Every neuron computes two things from the token's vector: a gate and a value. The gate goes through a curve called SiLU that is close to zero for negative inputs and passes positive ones almost unchanged; the neuron's output is gate × value. This design (SwiGLU) is what Llama uses.

Researchers find that individual neurons often respond to recognizable things: a word, a grammatical role, a topic. Pick any neuron to see where in your text it fires.

All 768 neurons, layer 1
click one to trace it
The gate: SiLU(x) = x · sigmoid(x), with every neuron on it
Each dot is one neuron at its gate value. Dots on the flat left part are nearly shut; dots on the right pass their value through. Color shows the sign of the final output (gate × value).
Strongest neurons for this token
Where neuron #0 fires in your text (layer 1)
06residual stream

Six layers, one running sum

Attention and the neurons never overwrite a token's vector: each one adds its result to it. The vector that flows up through the layers, collecting these additions, is called the residual stream.

Because the stream keeps the same 288-number shape all the way up, you can stop it after any layer and ask the final read-out “what would you predict from this?”. That trick is the logit lens, and it is what the cells of the machine above show.

Straight after the embedding the stream still mostly says “I am this token”. Layer by layer it turns into “the next token is probably…”.

Logit lens: the prediction after each layer
How much each part writes (vector lengths)
The residual stream itself: 288 numbers after each step (each row scaled to its own size)
Each row is scaled to its own typical size, so patterns stay visible as the stream grows.
07predict

A score for every token it knows

The final vector is compared with every row of the embedding table from step 02 (the same table, reused on the way out). Each comparison is one dot product, so the model produces 32,000 scores, called logits.

A softmax turns logits into probabilities: raise e to each score and divide by the total. Big scores win by a lot, because the exponential stretches differences.

Temperature divides every logit before the softmax. Below 1 the leader pulls further ahead (more predictable text); above 1 the field flattens (more surprising text). Move the slider and watch the curve bend; nothing is re-run, it is the same 32,000 scores.

All 32,000 logits for the next token
How many tokens got each score (log scale). Almost the whole vocabulary sits in the big hump on the left; the few plausible next tokens are the lonely outliers on the far right.
Probability of the top 60 tokens
Temperature
0.80
Top-p
0.95
08sample

Rolling the dice

The model does not simply take the top token. It draws one at random, in proportion to the probabilities. That is why the same prompt can tell a different story every time.

First, top-p keeps only the most likely tokens until their probabilities add up to p (here 0.95), which removes the long tail of nonsense. The survivors are rescaled to add up to 100% and laid end to end on a line from 0 to 1.

Then a random number between 0 and 1 is drawn, and whichever token's stretch of the line it lands on is written. Temperature 0 skips the dice and always takes the top token (“greedy”), which tends to loop and repeat.

1,000 rolls of the dice for this position
09repeat

And again, one token at a time

Once a token is picked it is appended to the text, and the whole machine runs again to pick the next one. A language model writes by predicting, one token at a time, until it decides the story is over.

Rerunning everything for every new token would be wasteful, so the model keeps each earlier token's keys and values in a KV cache. A new token only computes its own query, key and value, then reads the cache. The two panels show that cache for layer 1: one row per token, growing as the story does.

The cost numbers are measured on your device, per token. Notice what dominates in a model this small: scoring the whole vocabulary at the end.

Key cache, layer 1 (0 × 288)
Value cache, layer 1 (0 × 288)
Work for one token at position 0: 15.2M multiply-adds
attention projections (q, k, v, out)2.0M (13%)
attention over 1 cached positions3.5K (0%)
neurons (3 matrices per layer)4.0M (26%)
scoring all 32,000 tokens9.2M (61%)
This whole story so far: 0 multiply-adds with the cache, versus 0 if every token re-ran the full text. Cache size: 0 KB.
Time per forward pass on this device
Average 0.0 ms per token (– tokens per second of pure compute), in a background thread, in plain JavaScript.
10scale

The same machine, much bigger

The chatbots you know run this exact loop: tokens, embeddings, attention, neurons, a residual stream, a softmax, a dice roll, repeat. What changes is size, and the amount of text they learned from.

Bigger models have more layers, wider vectors, more heads, bigger vocabularies and far longer memories. Those numbers multiply: every token costs roughly two operations per parameter used.

The largest commercial models do not publish their sizes, so the comparison uses open models whose makers did. Everything they add (chat training, tools, agents) is built on top of this same next-token step. Much of that chat training is human work: people are paid to rate and compare model answers so the model learns which is better, and AITraining.jobs, which we also own, explains it in a plain-language guide to AI evaluation and rating.

Parameters, drawn to scale
This model
Llama 3.1 405B
Areas are proportional. Llama 3.1 405B uses 26,645× more parameters per token than the model on this page, so each of its tokens takes about 810B operations instead of 30.4M.
ModelParamsLayersWidthHeadsVocabContext
This model (stories15M)
2023
15.2M6288632,000256
GPT-2 small
2019
124M127681250,2571K
GPT-2 XL
2019
1.6B481,6002550,2571K
Llama 3.1 8B
2024
8.0B324,09632128,256128K
Llama 3.1 70B
2024
70.6B808,19264128,256128K
Llama 3.1 405B
2024
405B12616,384128128,256128K
DeepSeek-V3
2024 · mixture of experts: each token only runs 37B of the 671B
671B617,168128129,280128K
Click a row to compare it in the drawing. Sources: the GPT-2 paper (Radford et al., 2019), the Llama 3 paper (Meta, 2024), the DeepSeek-V3 technical report (2024).
Forward Pass

A real language model, running in your browser, with nothing hidden.

Weights: stories15M by Andrej Karpathy (llama2.c, MIT license). Training data: TinyStories (Eldan and Li, 2023, CDLA-Sharing-1.0). Tokenizer: the Llama 2 SentencePiece vocabulary. Inference, instrumentation and visualizations written from scratch for this site; everything runs in your browser.

  • About and method
  • Privacy Policy
  • Terms of Service