Skip to main content

Exercises — GPT numerical operations

Comprehension and code-reading exercises

← Back to the guided tour: Opérations numériques du GPT

Check your understanding

  1. An x of shape (3, 7, 12) passes through linear with weight of shape (8, 12): what is the output shape?

  2. What happens when normalizing a position whose 16 activations are all identical? What role does eps play?

  3. For a tensor x of shape (B, T, d), what does layer_norm(x, axis=-1) normalize? What shape does gelu(x) return? Why would normalizing over axes (0, 1) be different?

    Show answers and reasoning

  4. (3, 7, 8): the last axis (12) is replaced by the output width (8); the batch axes (3, 7) are preserved.

  5. The variance is exactly 0; without eps the division would produce inf or nan. With eps, the denominator is sqrt(eps), so the division is defined. Since the numerator is zero, the normalized output is zero; after the affine transform, the output is exactly beta (not the input mean).

  6. axis=-1 normalizes the d features of each token independently, without mixing batch examples or positions. GELU acts elementwise and preserves shape (B, T, d). Normalizing over (0, 1) would compute shared statistics across examples and positions, mixing elements that should remain independent at this step.

Language: Français · English