Cheatsheet 07 — Inference Parameters

The knobs that control generation. Full: Phase 1, Phase 5.

The knobs

ParamRangeEffectDefault to use
temperature0–2Randomness. 0 = deterministic/greedy; ↑ = more diverse/creative0 for extraction/classification/code; 0.7 for creative
top_p (nucleus)0–1Sample from smallest token set summing to p1.0 (or 0.9 with temp)
top_kintSample from k most likely tokensoff / large
max_tokensintCap output lengthSet it! (cost + runaway protection)
stopstringsEnd generation at these stringsTask-specific delimiters
frequency_penalty-2–2Penalize repeated tokens0 (raise to reduce loops)
presence_penalty-2–2Encourage new topics0
seedintReproducible sampling (where supported)Set for evals/tests
nintNumber of completions1 (n>1 multiplies cost)
logprobsbool/intReturn token probabilitiesFor confidence/analysis

Recipes by task

TaskSettings
Extraction / classification / structured outputtemperature=0, set max_tokens, schema/stop
Code generationtemperature=0–0.2
Factual Q&A / RAGtemperature=0, low; rely on grounding
Brainstorming / creative writingtemperature=0.7–1.0, top_p=0.9
Reproducible evalstemperature=0, seed set

Gotchas

  • Set temperature AND top_p carefully — adjusting both compounds; usually tune one.
  • temperature=0 ≠ fully deterministic across runs/providers (hardware/batching nondeterminism); use seed + same provider for tests.
  • Always set max_tokens — uncapped output = runaway cost and latency.
  • Reasoning models ignore some sampling params and bill hidden reasoning tokens.
  • n>1 / logprobs raise cost — use deliberately.

Interview line

"For anything that needs correctness — extraction, classification, code, RAG — I use temperature 0 and cap max_tokens. I only raise temperature for genuinely creative tasks, and I set a seed for reproducible evals."


Next: 08 — Local Inference Commands