10/30
Part 2 of 6 · Loss checksLearn and do

Overfit one batch, to prove the model can learn

A model that can't learn at all is the opposite failure, and it has its own check.

# the only batch it will see
x, y = get_batch(data, model.block_size, 2)
opt = torch.optim.AdamW(model.parameters(), lr=3e-3)
for step in range(301):
    _, loss = model(x, y)
    opt.zero_grad(); loss.backward(); opt.step()
    if step % 50 == 0:
        print(step, round(loss.item(), 4))

This asks the opposite question. The floor test asks whether the model can cheat. This one asks whether it can learn at all:

CheckIt asksThe answer must be
random tokenscan the model cheat?no
one batchcan the model learn?yes

Take one tiny batch and train on nothing else. Karpathy's recipe suggests as few as two examples, trained until the loss reaches the lowest value it can, here 0. Any working GPT can memorize two sequences.

Predict

The blocks sit in a plain Python list, so the optimizer can't see them. Can the model still memorize two sequences?

Pick an answer above to see the rest