Transformers, ELI5 · Part 9 / 10

Making it big, affordably

Bigger models are predictably better — and a few tricks (the KV cache, LoRA) keep the cost in check.

Bigger models are better. The catch is cost — so there are clever tricks.

Predictably better

Add , data, or compute and the loss falls along a straight line on log-log axes — a . These predictable curves are called — you can predict the payoff before you spend a cent.

Slide the model size. Loss slides down a predictable line.
Go deeper: it's a budget you split (Chinchilla)

Params aren’t the only dial. For a fixed compute budget you split it between model size and training data — and there’s a sweet spot. That’s .

Trade model size against data — watch the loss find its valley.

Don’t redo the past: the KV cache

For each new word, the model would re-attend over the whole history every time. The stores the past instead, so it only computes the new row.

Toggle the cache. Work-per-token drops from a triangle to a line.
see this in PyTorch

To generate text, the model keeps reading everything written so far, guesses the next token, sticks it on the end, and runs again.

import torch

# `model` maps a sequence of token ids -> logits for every position.
# logits[..., t, :] = scores over the whole vocab for "what comes after position t".

tokens = torch.tensor([[1, 14, 27]])   # our prompt so far: (batch=1, seq=3)

for _ in range(5):                      # generate 5 new tokens, one at a time
    logits = model(tokens)              # run model on ALL tokens so far: (1, seq, vocab)
    last_logits = logits[:, -1, :]      # we only care about the LAST position: (1, vocab)
    probs = torch.softmax(last_logits, dim=-1)   # turn scores into probabilities
    next_token = torch.multinomial(probs, num_samples=1)  # sample one token: (1, 1)
    tokens = torch.cat([tokens, next_token], dim=1)       # append it -> seq grows by 1

# after the loop, `tokens` holds prompt + 5 freshly generated tokens
print(tokens)

Because attention compares every token with every other (~n² work), a model can only hold so many at once — its (commonly ~128k, up to ~1M+ tokens). Run past it and the start of the chat falls off.

Fine-tune cheaply: LoRA

Re-training a giant matrix means changing millions of numbers. freezes it and learns a tiny shortcut beside it — a handful of numbers instead of millions.

Toggle Full vs LoRA. Compare how many numbers actually change.
Go deeper: two more 'big but cheap' tricks

stores each weight in fewer bits (tiny model, barely-worse answers). keeps many specialist sub-networks but wakes only a couple per word.

Drop the bit-width — size plunges, accuracy barely dips.
Each word wakes only 2 of 8 experts — huge total, cheap to run.

Last stop: can we see what the model learned?

Sources · 9