Dividing pre-softmax attention scores by an extra factor > 1 at inference does what?
Dividing pre-softmax logits by a factor greater than 1 flattens the attention distribution, useful for redistributing weight away from over-peaked recent tokens at long context.
Picture a roomful of people voting on what to do next. If everyone's votes are very lopsided, the loudest few decide everything. Dividing every vote count by a number bigger than 1 before tallying brings everyone's totals closer together, so quieter voters get more say. The model works the same way when it picks which earlier words to focus on. Shrinking all the raw scores closer together before the final tally spreads its focus across distant words instead of pinning everything to the few loudest recent ones. That is exactly what you want when a long-prompt model has started ignoring useful information far back in the conversation.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Attention temperature scaling is a small but consequential knob in modern long-context inference. The setup is mundane: divide the pre-softmax attention scores by a factor greater than 1 to soften the resulting distribution. The motivation is less obvious: as you stretch a transformer to context lengths far beyond what it was trained on, attention often collapses onto the most recent tokens, ignoring distant content that the model should be using. Temperature scaling at inference time can rebalance the distribution back.
The technique is part of the YaRN length-extension recipe and shows up in production Llama 3 long-context variants, Mistral extensions, and other community-tuned long-context models. It works because softmax is fundamentally sensitive to the magnitude of its inputs, and the relationship between attention magnitude and sequence length is not constant.
This deep dive walks through the softmax math, the empirical observation that motivates the technique, the YaRN-style formula in detail, and the trade-offs that determine when it helps versus hurts.
Softmax's sensitivity to logit magnitude
Softmax is shift-invariant: adding a constant to every input leaves the output unchanged. But it is not scale-invariant: multiplying every input by c > 1 makes the output more peaked, and dividing by c > 1 makes it flatter.
The math
For inputs (s_1, s_2, ..., s_n), softmax produces:
Dividing each s_i by t > 1 before softmax gives:
As t increases, the differences between scores shrink toward zero, and the distribution approaches uniform (1/n for every i). As t decreases below 1, the differences grow, and the distribution approaches a one-hot at the argmax.
Intuition
Think of softmax as 'soft argmax'. The temperature controls how soft. At t = 1 you get standard attention; at t > 1 it spreads weight more evenly; at t = inf it becomes uniform; at t -> 0 it collapses to one-hot.
This is the same temperature parameter used in language model sampling, just applied in a different part of the model. Sampling temperature scales the next-token logits; attention temperature scales the attention scores.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- YaRN (Yet Another RoPE extensioN) by Peng et al. 2023 uses a temperature term in its length-extension recipe and is integrated into Mistral and Llama variants.
- Together AI's long-context Llama 3 70B variants apply YaRN-style temperature scaling when extending to 128k inference.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does attention temperature interact with RoPE position interpolation (PI) and YaRN?
PI rescales RoPE angles to map a longer inference context onto the trained position range; YaRN extends PI with per-dimension scaling and a magnitude correction. Attention temperature is a separate knob that corrects softmax magnitude. The full YaRN recipe applies both: PI-like position scaling plus a sqrt(t)-scaled attention factor. Using one without the other typically underperforms either alone.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Inverting the direction. Dividing by greater than 1 softens; multiplying by greater than 1 sharpens. Getting this backward will make over-peaked attention worse, not better.
60 second bullets to scan on the way to the call.
Direction of effect: dividing scores by greater than 1 softens, multiplying sharpens
Why softmax becomes more peaked when logit magnitudes grow
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.