Exercises — GPT numerical operations
Comprehension and code-reading exercises
← Back to the guided tour: Opérations numériques du GPT
Check your understanding
An
xof shape(3, 7, 12)passes throughlinearwithweightof shape(8, 12): what is the output shape?What happens when normalizing a position whose 16 activations are all identical? What role does
epsplay?For a tensor
xof shape(B, T, d), what doeslayer_norm(x, axis=-1)normalize? What shape doesgelu(x)return? Why would normalizing over axes(0, 1)be different?Show answers and reasoning
(3, 7, 8): the last axis (12) is replaced by the output width (8); the batch axes (3, 7) are preserved.The variance is exactly 0; without
epsthe division would produceinfornan. Witheps, the denominator issqrt(eps), so the division is defined. Since the numerator is zero, the normalized output is zero; after the affine transform, the output is exactlybeta(not the input mean).axis=-1normalizes thedfeatures 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.