All courses

Chain of thought as extra computation

Explain that each generated token gets a fixed budget of about 2N FLOPs and L sequential layers. Explain why writing intermediate steps buys more serial computation and working memory for hard problems.

Builds on: FLOPs per token: 2N forward, 6N training, Autoregressive generation loop

▶ Watch this lesson Start the whole course

What the animation says

One token, one climb

Ask a model for a hard answer straight away, and it often gets it wrong. Let it write steps first, and it often gets it right. Same weights. Same prompt. Producing one token is one forward pass: about two times N operations, climbing through the layers in order. A result made in one layer can only be used by the layers above it. Our toy model has four layers, and each layer follows one hop of a chain. This question needs six hops. Can one pass get there?

Depth, not operations

Watch. Hop one, hop two, hop three, hop four, and the layers run out. Billions of operations don't help. The limit is depth: how many steps can happen one after another. Add more positions, like a longer prompt, and the picture gets wider, not taller. Each position reads earlier ones only from the layer below. So every chain of dependencies still climbs at most L layers.

Writing as scratch paper

So write it down. The pass samples its result as a token. On the next pass, that token enters at the bottom, and a fresh four-layer climb starts from it. Here is the toy in code. This forward function does four hops from the last token. This loop appends each result and runs again. Twenty hops take five tokens, with the same weights every time. Tap what carries the result into the next pass.

The real budget

Now a real size: seven billion parameters, thirty-two layers. Answer directly: about fourteen billion operations, and thirty-two layers deep. Write three hundred tokens of steps first: three hundred and one passes, about four trillion operations, and up to nine thousand six hundred thirty-two layers of depth. Every token gets the same budget. Writing steps chains those budgets together, and leaves a scratchpad every later token can read.

Why does writing steps out help?

You have seen this: ask an LLM for a hard answer immediately and it often gets it wrong. Let it write out intermediate steps first and it often gets it right. The weights and the prompt are the same. So what changed? Is the step-by-step text just style, or does writing tokens give the model something it lacks when it has to answer in a single token?

A fixed budget per token

Producing one token is one forward pass: about $2N$ FLOPs, flowing through $L$ layers in order. Within that pass, a result computed at layer $\ell$ can only be used by layers above $\ell$. If each dependent step needs about one layer, a chain of more than about $L$ dependent steps cannot finish inside one token. A written token re-enters at the bottom on the next pass, so the next pass starts from that result. Writing works like scratch paper.

Budget with k intermediate tokens

If the model writes $k$ intermediate tokens and then the answer: $$\text{FLOPs} \approx 2N(k+1), \quad \text{serial depth} \le L(k+1)$$ Here $N$ is the non-embedding parameter count and $L$ the number of layers. The attention term is ignored. Why must results be written? In one pass, position $t$ at layer $\ell$ reads earlier positions only through their layer $\ell-1$ states. So dependency chains never exceed $L$, however many positions there are. The only thing that travels from the top of one pass to the bottom of the next is the sampled token id. An intermediate result can start a fresh $L$-layer chain only if it is written as a token. The written text is working memory that every later position can read at every layer.

7B model: answer now vs think first

Take $N = 7\times10^9$ and $L = 32$. **Direct answer:** $2N = 1.4\times10^{10}$ FLOPs, 32 layers deep. **300 tokens of steps, then the answer:** $301 \times 1.4\times10^{10} \approx 4.2\times10^{12}$ FLOPs. Depth is up to $32\times301 = 9{,}632$ layers. Now follow a 100-hop chain (a→b, b→c, …), assuming one hop per layer. Answering directly fails, since 100 > 32. Writing each node means each pass needs only 1 hop.

Toy: fixed-depth passes plus scratch tokens

This is a toy model in which one pass can do at most `L` dependent hops. A 20-hop chain is out of reach in one pass. Appending each pass's result as a token and running again completes the chain in 5 tokens. The prompt and the per-pass ability stay the same throughout; only the written intermediate results grow.
import numpy as np
nxt = np.random.default_rng(0).permutation(1000)
L, start, hops = 4, 7, 20
def forward(tokens):
    x = tokens[-1]
    for _ in range(L): x = nxt[x]
    return x
truth = start
for _ in range(hops): truth = nxt[truth]
toks = [start]
for _ in range(hops // L): toks.append(forward(toks))
print(toks[-1] == truth, len(toks) - 1)

Remember this

Every generated token gets the same budget: about $2N$ FLOPs and $L$ sequential layers. Writing intermediate steps feeds computed results back in as input. That adds up to $L$ more serial depth per token, plus a readable scratchpad, which hard multi-step problems need.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.