Zenaique

Attention temperature divides QK^T; sampling temperature divides output logits, distinguishwhere each lives.

MCQ·Medium·4.0 · 0·~1 min·Asked atBcgElevenlabsLakera·Relevant atAi4bharatAnthropicCerebrasDeepseek
Attempt it
TL;DR

Attention temperature shapes mid-layer routing over keys; sampling temperature shapes final next-token selection over vocabulary. Different softmaxes, fully independent.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine writing a story. First, you keep notes on every paragraph you have already written so you can refer back. The way you decide which old paragraph to look at when writing a new sentence is one knob, that is attention temperature. Set it low and you laser-focus on one prior paragraph; set it high and you blend many. Second, when you actually pick the next word to write, you have a long list of possible words and you sample one. That sampling knob is sampling temperature. Set it low and you pick the most likely word; set it high and you pick something unusual. Two completely separate decisions, two completely separate knobs.

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.

Two temperatures show up in transformer language: attention temperature and sampling temperature. Both reshape softmax distributions, but they act on different softmaxes at different stages of the pipeline and have completely different effects on model behavior.

This deep dive walks through where each one lives, what each one shapes, why the canonical 1 / sqrt(d_k) factor is sometimes confused with attention temperature, and how the two knobs interact with production serving practice.

Mental model: T_attn shapes how heads route over keys at every layer. T_sample shapes the discrete choice of the next token. Different softmaxes, different effects, fully independent.

Counting the softmaxes in a generation step

How many softmaxes per token

A decoder-only LLM with L layers and H heads runs L * H + 1 softmaxes per generated token:

  • L * H attention softmaxes, one per head per layer. Each one operates on a (seq_len,) vector of scores for a single query position.
  • 1 vocabulary softmax at the end, operating on a (d_vocab,) logit vector.

For Llama-3-70B with 80 layers and 64 heads, that is 80 * 64 + 1 = 5121 softmaxes per generated token.

Why this matters

The two temperatures act on different members of this set. T_attn divides the input of the L * H attention softmaxes. T_sample divides the input of the single vocabulary softmax. They are touching disjoint operations.

Independence

This is why the two knobs can coexist freely. Setting T_attn = 1.0 (the default, which means no extra multiplier beyond sqrt(d_k)) and T_sample = 0.7 changes only the final sampling distribution. Setting T_attn = 2.0 and T_sample = 0.0 (greedy) changes only the internal routing.

There is no shared parameter, no shared softmax, no interaction at the math level.

Attention temperature: shaping mid-layer routing
Sampling temperature: shaping the final token choice
Failure mode comparison and production wisdom
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
PropertyAttention temperatureSampling temperature
Where it actsPre-softmax scores in every attention layerFinal vocabulary logits before sampling
What it shapesKey routing per headNext-token discrete choice
Failure mode (high)Uniform attention, routing collapseRandom vocabulary, nonsense output
Failure mode (low)Single-key lock, hallucinationGreedy repetition
API exposureRarely exposedAlways exposed

Real products, models, and research that use this idea.

  • OpenAI, Anthropic, and Google LLM APIs (GPT-5.5, Claude Opus 4.7, Gemini 3.1 Pro) all expose sampling temperature as a user-facing knob; attention temperature is never exposed.
  • Research stacks like nanoGPT and academic transformer implementations sometimes expose attention temperature for ablation studies.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QWhat is the relationship between attention temperature and the sqrt(d_k) factor?
A

sqrt(d_k) is a fixed normalizer that keeps dot product variance independent of head dimension. T_attn would be an additional multiplier on top. Most implementations bake sqrt(d_k) in and treat T_attn as 1 (effectively absent).

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Treating the two temperatures as the same knob with different names. They act on different softmaxes at different stages of the pipeline and have completely different effects.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Count how many softmaxes run per generated token

  • Where attention temperature acts in the pipeline

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium