Exercises — Complete GPT model
Comprehension and code-reading exercises
← Back to the guided tour: Modèle GPT complet
Check your understanding
Why
position_embedding[:seq_len]and not the wholeposition_embedding?With
V=50, T=16, d=16, H=2, L=2, hidden=32, compute the total parameter count without running the code.A prefix-invariance test compares the logits for a prefix alone with the logits at those same positions after future tokens are appended. What result is expected, and what can this test not establish on its own?
Show answers and reasoning
The table always has
context_lengthrows; a shorter sequence uses only the firstseq_len. Without the slice, adding(B, T, d) + (T_max, d)would fail as soon asT < T_max.Per block:
4×16×16 + 4×16 + 2×32×16 + 32 + 16 + 4×16 = 1024+64+1024+48+64 = 2224. Two blocks:4448. Embeddings:2×50×16 = 1600(table + untied head); positions16×16 = 256; final norm32; head bias50. Total:4448 + 1600 + 256 + 32 + 50 = 6386.The prefix-position logits should remain identical up to numerical tolerance: future tokens must not influence earlier predictions. This is targeted evidence for the tested inputs and configurations; by itself it does not prove causality for every possible input.