QK norm
Query-key normalization that rescales attention queries and keys before their dot products, changing the attention score path rather than the whole residual stream.
QK norm stabilizes attention by normalizing the query and key vectors right before their dot products, which narrows the change to the score path instead of renormalizing the entire hidden stream around every transformer sublayer.
At a glance
Released
October 2020
Authors
Alex Henry, Prudhvi Raj Dachapally, Shubham Pawar, et al.
Optimizes
- Attention Logit Stability
What It Is
QK norm applies normalization directly to the query and key vectors used in attention scoring. Instead of normalizing the whole residual stream, it targets the part of the block that decides how sharply one token attends to another.Why It Exists
QK norm mainly targets attention-logit stability. It reduces the chance that raw query or key magnitude will make the softmax too sharp, especially in deeper models or longer-context settings.How It Works
The block projects hidden states into queries and keys, normalizes those vectors, then forms attention scores from the normalized versions before the usual softmax and value mixing. The attention pattern depends more on direction and less on raw vector length.Hidden statesProject queries and keysNormalize Q and KAttention scoresWeighted valuesAttention outputHidden states to Project queries and keysProject queries and keys to Normalize Q and KNormalize Q and K to Attention scoresAttention scores to Weighted valuesWeighted values to Attention output
Math Or Compute Schema
The formula below shows the attention score path after normalized queries and keys are substituted into the standard dot product. The hats mark the normalized forms.Compared To Nearby Modules
Layer norm and RMSNorm usually normalize the hidden state that flows through a whole transformer block. QK norm is narrower: it only changes the query-key score path inside attention. That makes it more of a targeted attention tweak than a general residual-stream norm.| Comparison dimension | QK Norm | Layer Norm | RMSNorm |
|---|---|---|---|
| Normalization target | Query and key vectors only | Full token or hidden vector | Full token or hidden vector |
| Placement | Inside attention before the dot product | Around transformer sublayers | Around transformer sublayers |
| Main benefit | Keeps attention logits from becoming too sharp | Stabilizes the broader residual stream | Stabilizes scale with less work than layer norm |