AI SYSTEMS6 MIN READ3 INTERACTIVE LABS

From Probabilities to Words: Temperature, Top-p, and Speculative Decoding

How raw logits become a chosen token, why decoding hits a memory-bandwidth wall, and how Speculative Decoding runs 3× faster with identical output quality.

01

A language model never picks a word directly

After tokenization and self-attention , the final layer emits raw logits ziz_i across the entire vocabulary, converted into probabilities via temperature-scaled softmax:

P(ti)=ezi/T∑jezj/TP(t_i) = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}}
02

Temperature, Top-k, and Top-p: shaping the tail

Raising temperature TT flattens the curve for variety, but exposes a noisy long tail of improbable tokens. Top-k keeps a fixed count kk, while Top-p keeps the smallest prefix summing to pp.

Temperature, Top-k & Top-p Shaper
Paris
99.9%
Lyon
0.0%
located
0.0%
Marseille
0.0%
known
0.0%
banana
0.0%
Faded bars are pruned before sampling. Notice how Top-p shrinks to 1 token on confident prompts while widening on open-ended ones.
03

Why decoding leaves a $30,000 GPU mostly idle

Even with the KV cache , emitting 1 token from a 70B FP16 model streams ~140 GB of weights across HBM memory. Verifying 5 tokens in parallel transfers the exact same 140 GB.

HBM Memory Bus vs Compute Cores (70B FP16)
1 token / 140 GB read
HBM Bus Read
140 GB
Tensor Cores
2% busy
Verifying 5 tokens in parallel transfers the exact same 140 GB of weights while doing 5× the useful work per pass.
04

Speculative decoding: draft fast, verify in parallel

A tiny draft model guesses K=5K = 5 tokens in milliseconds, and the target model verifies all 5 in one parallel pass. Rejection sampling accepts matching tokens into the KV cache or corrects the first mismatch, guaranteeing the exact same output distribution 2× to 3× faster.

Speculative Verification Passes
5 tokens emitted in 1 target passes (5.0× tokens/pass)
Pass 1def calculate_total(items
Pass 1: Boilerplate Python signature — all 5 drafted tokens accepted in a single 70B forward pass.