Skip to content
nonconvexcard

Why attention divides by the square root of d_k

ProofIntermediate⏱ 30 minDeep Learningattentionscalingvariancesoftmax

Problem

Compute the mean and variance of ⟨q,k⟩\langle q,k\rangle for independent random q,k∈Rdkq,k\in\R^{d_k} with i.i.d. entries of variance σ2\sigma^2. Deduce the scaling, and quantify the effect on the softmax at dk=64d_k = 64 with and without it.

Write a complete argument. Every inequality you use should be one you could state precisely.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Derive the attention crossover lengthLLM OpsProofBeginner15 min
The cross-entropy gradient is the prediction errorLLMsProofBeginner15 min
The Δ²/12 noise varianceQuantizationProofBeginner15 min
When does attention dominate the MLP?Deep LearningNumericalBeginner30 min
Attention is permutation equivariantDeep LearningProofIntermediate30 min