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

Measure it through the code you were given

Now run that check on the model you were handed. Here data, get_batch and model are the ones in the practice file.

x, y = get_batch(data, model.block_size, 16)
with torch.no_grad():
    logits, loss = model(x, y)
V, s = logits.size(-1), logits.std().item()
print(f"measured {loss.item():.3f}   ln V {math.log(V):.3f}   s {s:.3f}")
print(f"predicted ln V + s^2/2 = {math.log(V) + s * s / 2:.3f}")

On a fresh, healthy GPT with 65 tokens in its vocabulary, and 100,000 random tokens as data, one batch printed this:

measured 4.203   ln V 4.174   s 0.175
predicted ln V + s^2/2 = 4.190

One batch is a little noisy, so the measured loss sits a hundredth above the prediction. Use their get_batch and their model, not a batch you build yourself: a bug anywhere on that path, from their data to their loss, moves this one number.

Three inits give three first losses

Here are three fresh copies of one GPT: 2 layers, 64 wide, 65 tokens in the vocabulary, so ln⁡65=4.17\ln 65 = 4.17. They differ only in their init.

Predict

Tie the head to the token table, and keep PyTorch's default init for the table, spread 1. What's the first loss, against ln 65 = 4.17?

Pick an answer above to see the rest