Decoding Policy Acts on Fixed Logits

Hold one logits row fixed while comparing greedy decoding, temperature, top-k restriction, and seeded sampling. Learn which changes affect the probability distribution and which affect only selection.

The model returns logits. A decoding policy transforms or filters that row and then selects a token. Keep the original logits fixed when comparing policies.

Greedy Choice

Greedy decoding uses

y^=argmaxizi.\hat y=\arg\max_i z_i.

It is deterministic for fixed logits and a fixed tie rule. It does not return the most probable complete sequence in general; it makes one locally largest choice at each step.

Temperature

For temperature τ>0\tau>0:

pi=exp(zi/τ)jexp(zj/τ).p_i=\frac{\exp(z_i/\tau)}{\sum_j\exp(z_j/\tau)}.
  • τ<1\tau<1 sharpens differences;
  • τ>1\tau>1 flattens them;
  • τ=1\tau=1 leaves the original softmax distribution;
  • this chapter handles τ=0\tau=0 as an explicit greedy request;
  • negative temperature is rejected.

For logits [2,1,0][2,1,0], temperature 0.5 gives scaled logits [4,2,0][4,2,0] and probabilities approximately [0.8668,0.1173,0.0159][0.8668,0.1173,0.0159].

Top-kk Filtering

Top-kk keeps the kk largest logits, sets the rest to -\infty, and renormalizes.

  • k=1k=1 becomes greedy after tie handling;
  • k=Vk=V removes no token;
  • k<1k<1 or k>Vk>V is invalid.

Filtering changes the sampling distribution. It does not change model parameters or the unfiltered logits.

Sampling Needs Its Own Random State

The verified sampled run uses seed 41, temperature 1, and top-k=3k=3:

<bos> Y X Y <eos>

A different seed can produce another valid draw from the same probabilities. One attractive sample is not evidence of lower loss or better model quality.

Q1. Scale logits by temperature

What logits result from dividing [3,1,-1] by temperature 2?

Compute it first, then check your number.

Hint
Calculate each coordinate independently.
Solution
The scaled logits are [1.5,0.5,-0.5].
Not attempted
Review

Not marked done.

Policy Is Not a Cache Setting

Cached and uncached execution should produce the same logits. Apply the same policy and random-generator state only after that equality is established.

Pause and reflect

In your own words, note what you understood, what remains unclear, or what you want to revisit. The note stays with this lesson.

0 of 1 exercises marked done

Review

Not marked done.

LLM PrimerDecoding Policy Acts on Fixed Logitshttps://llmprimer.com/transformers/autoregressive-generation-and-efficient-inference/decoding-policy-acts-on-fixed-logits© 2026 LLM Primer