Skip to main content

Exercises — Complete GPT model

Comprehension and code-reading exercises

← Back to the guided tour: Modèle GPT complet

Check your understanding

  1. Why position_embedding[:seq_len] and not the whole position_embedding?

  2. With V=50, T=16, d=16, H=2, L=2, hidden=32, compute the total parameter count without running the code.

  3. 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

  4. The table always has context_length rows; a shorter sequence uses only the first seq_len. Without the slice, adding (B, T, d) + (T_max, d) would fail as soon as T < T_max.

  5. 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); positions 16×16 = 256; final norm 32; head bias 50. Total: 4448 + 1600 + 256 + 32 + 50 = 6386.

  6. 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.

Language: Français · English