Should I touch temperature and the other sliders?
Mostly no. Use the settings the model's makers recommend, which good runtimesRuntimeThe software that loads a model file and runs it.Read more and uploads already apply. Change them only to fix a specific problem.
Temperature in one paragraph
After each pass, the model gives a score to every possible next token. Sampling turns those scores into one choice. Temperature controls how adventurous that choice is.
At 0 the model always picks the top-scoring tokenTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more, so the same prompt gives the same answer. Around 0.6 to 1.0, it sometimes picks the second or third choice, which reads as more natural and more varied. Above about 1.2, unlikely tokens start winning and the text drifts into nonsense.
The other settings, one line each
Every other slider limits which tokens are allowed into the draw before temperature picks among them.
| Setting | What it does | Typical value |
|---|---|---|
| Top-k | Keeps only the k highest-scoring tokens | 20 to 40, or off |
| Top-p | Keeps the smallest set of top tokens whose chances add up to p | 0.8 to 0.95 |
| Min-p | Drops any token less likely than this fraction of the top token's chance | 0.05 to 0.1 |
| Repetition penalty | Lowers the score of tokens that already appeared | 1.0 (off) to 1.1 |
Top-k and top-p are the old pair, and most models ship with values for both. Min-p is a newer filter that adapts better when the model is unsure. Repetition penalty is a blunt fix for loops, and it also discourages the model from reusing words it needs, such as variable names in code.
Use the model card's recommended settings. If there are none, leave the runtime's defaults alone.
What to leave alone
The defaults are tuned, often by the lab that trained the model. Changing several sliders at once makes the model worse more often than better, and it makes problems hard to trace. If output is broken, the cause is more likely a wrong chat template or an overflowing How much can the model keep in mind? than a sampling value.
There are two cases where changing them helps.
Case 1: you need the same answer every time
For extraction, classification, tests and anything a program reads, set temperature to 0 or close to it. You get repeatable output and fewer creative detours. How do I test a model for my own use? uses this to compare models fairly.
The catch is that some models get worse at 0. Reasoning models in particular can loop or repeat themselves at zero temperature, and their makers often say so on the model card. For those, use the recommended value and fix the random seed instead.
Case 2: the model loops
If the model repeats the same sentence or paragraph, first check the template and the context. If both are right, raise the repetition penalty slightly, to about 1.05 to 1.1, or add a small min-p. Go up in small steps.
A repetition penalty strong enough to stop a loop can also break code and structured output, where repeating the same names is correct. Turn it back down once the loop is gone, and never use it for tool callsTool callingA model asking the app to run a function, such as a search or a shell command.Read more. Why is the output nonsense? covers other causes of loops.
Setting them
In Ollama, set them inside a session with /set parameter. The names are temperature, top_k, top_p, min_p and repeat_penalty.
/set parameter temperature 0In llama.cpp, the flags are --temp, --top-k, --top-p, --min-p and --repeat-penalty. In LM Studio, the same settings sit in the sidebar of the chat view.
Ask the same question three times at temperature 0, then three times at 1.0. Compare how much the answers change.
Suggest a name for a small bakery that sells only bread. Reply with the name only.Go deeperThat's enough
The order of operations
The runtime runs the filters as a chain. A typical order is repetition penalty first, then top-k, top-p and min-p to cut the list, then temperature to reshape what is left, then a random draw.
Runtimes differ on the exact order, and some let you change it. The order changes results only at the edges, so the defaults are fine.
Why min-p behaves better
Top-p uses a fixed share of probability. When the model is confident, that might keep one token, and when it is unsure, it might keep hundreds, including junk. Min-p ties the cutoff to the top token's chance, so the list shrinks when the model is sure and widens sensibly when it is not.
Seeds
The random draw uses a seed. Fix the seed and use the same settings, model and prompt, and most runtimes give the same output every time. It is a cleaner way to get repeatable runs than temperature 0 for models that dislike greedy decoding.