Along which axis of the QK^T score matrix is softmax applied inside attention?
Along the key axis (the last dimension). Each query gets a probability distribution over keys; each row sums to 1.
Imagine planning a meal where each chef has to decide how much of each ingredient to use. The chef does not normalize 'how much each ingredient gets used across all chefs'. The chef normalizes 'how much of my own meal each ingredient takes up', so for each chef's own dish, the ingredient percentages add up to 100%. Each query token in attention is like one chef: it decides for itself how attention mass is split across all available keys, and those splits add up to 100% for that query.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Identify the key axis as the normalization axis, derive the choice from the downstream V matmul shape, contrast with wrong-axis options, and walk how masking, FlashAttention tiling, and cross-attention all align with the key-axis convention.
Real products, models, and research that use this idea.
- PyTorch's torch.nn.functional.scaled_dot_product_attention computes softmax(scores, dim=-1) internally before multiplying by V.
- All modern LLMs (GPT-5.5, Llama 4 Maverick, Claude Opus 4.7, Gemini 3.1 Pro, DeepSeek V4) apply softmax along the key axis in every attention layer.
- Causal masking in autoregressive transformers sets the upper triangular of the score matrix to -inf along the key axis before softmax.
- FlashAttention's online-softmax tiling iterates over key-axis blocks precisely because softmax normalization happens along the key axis.
- Attention visualization tools (BertViz, exBERT) plot the weight matrix with rows summing to 1, confirming the key-axis normalization.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat would change if softmax were applied along the query axis instead of the key axis?
QHow does FlashAttention's online-softmax algorithm exploit the key-axis normalization?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Applying softmax along the query axis. That would give each key a distribution over queries, not each query a distribution over keys, and the downstream V matmul would be malformed.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.