Sampling Techniques — Interview Grill

40 questions on sampling and decoding. Drill until you can answer 30+ cold.


A. Foundations

1. What's the basic decoding loop? At each position, the model produces logits . We optionally rescale (temperature), truncate (top-k/top-p), apply penalties, softmax to get probabilities, sample a token, append, repeat.

2. What does temperature do? . Lower = sharper distribution (closer to argmax). Higher = flatter distribution (closer to uniform). : model's natural distribution. : greedy. : uniform.

3. Why is the formula ? Dividing logits by uniformly amplifies () or attenuates () all of them. After softmax, emphasizes (or de-emphasizes) the highest-scoring tokens. produces a sharper distribution; produces a smoother one.

4. means what? Greedy decoding. The argmax token gets probability 1; everything else 0. Deterministic.

5. What's typical for chat? . Specific tasks: factual (), creative (), code ( for correctness, higher for diversity).


6. What's greedy decoding? Pick at every step. Equivalent to . Deterministic, often repetitive.

7. When is greedy appropriate? Tasks with one correct answer (math, code, structured output). When you need determinism. When the highest-probability token is overwhelmingly correct.

8. Why is greedy bad for open-ended generation? Repetition (highest probability is to continue a loop). Boring outputs. No diversity (same prompt → same response).

9. What is beam search? Maintain running candidates. At each step, expand each with all next tokens, score, keep top . Output the highest-scoring complete sequence.

10. Why does beam search work for translation? Translation has approximately one correct answer; beam search finds the highest-probability sequence, which approximates that answer. Constrained tasks where global probability tracks correctness.

11. Why does beam search fail for LLMs? For open-ended generation: produces low-entropy consensus text that's plausibly average and boring. Length bias toward shorter sequences (cumulative log-prob decreases with length). Strong repetition.

12. What's length normalization in beam search? Divide score by () to reduce length bias. Without it, beam search prefers shorter sequences because each additional log-prob is negative.

13. What does Holtzman et al. ("Curious Case of Neural Text Degeneration") show? Beam search produces text that looks plausibly average but has unnaturally low entropy. Real human text has higher entropy and surprise than beam-search output. Argument for sampling-based methods over beam search for open-ended generation.


C. Top-k

14. What's top-k sampling? Sample only from the highest-probability tokens; zero out the rest; renormalize. Then sample.

15. What's a typical ? 40 or 50. Usually combined with temperature.

16. Pros of top-k? Eliminates the long tail of low-probability garbage tokens. Cheap to implement. Stable across many tasks.

17. Top-k's main weakness? Fixed is too rigid. Confident model: includes tokens that should be excluded. Uncertain model: may not capture all reasonable continuations. Top-p adapts to confidence dynamically.


D. Top-p (nucleus)

18. What's top-p (nucleus) sampling? Sample from the smallest set of tokens whose cumulative probability . The "nucleus" is this set. Truncates the tail dynamically based on the actual distribution.

19. Why is top-p better than top-k? Adapts to the model's confidence. Confident model: nucleus is tiny. Uncertain model: nucleus is larger. Always grabs "the most probable mass" rather than fixed count.

20. Typical ? or . , is a common chat default.

21. Walk me through top-p with a concrete example. Suppose probs after softmax = . With : cumulative = . Smallest set = (first three). Renormalize: . Sample.

22. Top-p's failure modes? Very low (0.5): nucleus shrinks to greedy-ish behavior. Very high (0.99): includes the long tail again. Near-uniform distributions: nucleus is huge.

23. Where does the name "nucleus" come from? Holtzman et al. 2020. The "nucleus" of the distribution is the smallest set capturing most of the probability mass. Like a nucleus is the dense core of a cell.


E. Min-p

24. What's min-p sampling? Sample from tokens with . The threshold scales with the top-1 probability, so every sampled token has probability comparable to the top.

25. Why is min-p better than top-p sometimes? Top-p with can include tokens whose probability is much smaller than the top — the smallest member of the nucleus might be while top-1 is . Min-p ensures every sampled token has probability , eliminating the worst tail.

26. Typical ? .


F. Other sampling methods

27. What's typical sampling? Sample tokens whose conditional information content is close to the expected information content (entropy). The intuition: human language tends to have token-level information content close to the average. Niche.

28. What's Mirostat? Adaptive sampling that targets a specific output perplexity. Adjusts truncation dynamically based on local entropy. Used in some local-LLM servers; not common in production.

29. What's contrastive search? Maintains diversity by penalizing tokens that are too similar to recent outputs (using cosine similarity in embedding space). Used in some open-ended generation research.


G. Penalties

30. What's repetition penalty? For tokens already in the context, divide logit by (e.g., ) before softmax (multiplying if logit is negative). Discourages repeating tokens.

31. Frequency penalty vs presence penalty? Frequency: subtract from each logit — penalty grows with frequency. Presence: subtract if token appeared at least once — binary penalty. Frequency is usually softer.

32. Failure mode of penalties? Too high → unnatural text (model avoids common words like "the"). Treats symptoms, not the underlying repetition cause. Some workflows: light penalty () for chat; none for code.


H. Speculative decoding & best-of-N

33. Walk me through speculative decoding. Draft model proposes tokens autoregressively (cheap); target model verifies in one forward pass; accept via rejection sampling rule . Output distribution is exactly target's. 2–3x speedup typical.

34. Why is speculative decoding exact? The rejection-sampling rule is constructed to make the distribution of accepted tokens equal the target model's distribution. Output samples are statistically indistinguishable from regular target decoding.

35. What's best-of-N? Generate independent samples; pick the best by a scorer (perplexity, reward model, judge). Trade compute for quality.

36. Why does best-of-N work? You're sampling from a distribution and selecting the highest-quality output. Equivalent to test-time scaling: more compute () → better quality (max over ). Used in modern reasoning models (o1, R1) at large .

37. What's the relationship between best-of-N and RLHF data? RLHF preference data is often generated by sampling completions and having humans rank them. The model learns the same "pick the best" function that best-of-N approximates at inference.


I. Common gotchas

38. Why might lowering temperature not reduce hallucinations? Lower temperature reduces sampling randomness but doesn't make the model's beliefs more accurate. If the highest-probability continuation is wrong (bad calibration), temperature won't help. Hallucinations need fixes at the model level (better training, RAG, post-hoc checks), not just sampling.

39. Why does the same prompt with the same parameters sometimes give different outputs? Sampling is stochastic by default (any ). Even at (greedy), floating-point precision can break ties unpredictably. For reproducibility: set seeds; for production: store seeds.

40. How do you choose between sampling parameters? Validation against the target task. For chat: , top-p is a strong baseline. Adjust per task: lower for factual; higher for creative. Don't tune in production based on cherry-picked outputs.


J. Quick fire

41. Default chat ? . 42. Default chat top-p? or . 43. Top-p paper? Holtzman et al. 2020. 44. Greedy vs ? Identical. 45. Beam search good for? Translation, summarization with constraints.


Self-grading

If you can't answer 1-15, you don't know decoding. If you can't answer 16-30, you'll fall short on inference interviews. If you can't answer 31-45, frontier-lab interviews will go past you.

Aim for 30+/45 cold.