Under the hood · 4 of 8 Local models

What do top-k, top-p and min-p do?

Before a model picks its next word, the program running it can drop the unlikely ones from the list, and lower the odds of words it has already written. These are the settings a local runner shows you. Move them and watch which words stay in the draw.

Two places in a sentence, and a reply that goes round in circles:

The odds for the next word, after your settings

On Saturdays the market in Millbrook sells …

How many words each filter keeps, on its own

Solid: the Open spot. Dashed: the Sure spot. Rings: your settings. top-k keeps the same number at both spots; min-p follows how sure the model is.

What came up in 0 replies

Solid: how often each word came up. Outline: its odds with no filter.

A longer reply, repeat_penalty 1.10

Underlined: a run of three words the reply already wrote.

After your settings, or what came up The odds with no filter word = cut from the draw ✗ = makes no sense here
top-k: 5keep this many words
top-p: offkeep this share of the odds
min-p: offshare of the top word's odds
temperature: 0.80how bold the pick is
repeat_penalty: 1.10lower words already used

Loading the engine…

Words kept

–

Left in the draw at this spot.

A word that makes no sense

–

The chance of one of the ✗ words.

Good words cut

–

Of the 13 words that fit here.

Cut, then share out

Each filter drops words from the list before the draw. The odds of the dropped words are shared out among the words that are left, so those come up more often.

Three ways to cut

top-k keeps a fixed number of words. top-p keeps the top words until their odds add up to a share. min-p keeps every word with at least a share of the top word's odds.

Lower what was said

repeat_penalty lowers the score of every word already in the recent reply. It is applied first, before the filters and the temperature.

The trap

A filter can only remove words. If the right word is not near the top, no setting brings it back, and a strong repeat penalty can push the right word down when the reply needs it again, like a name or a full stop.

Open Under the hood for each word's numbers at every step, with your settings.

Why knowing this helps you

Ollama, llama.cpp and LM Studio let you set these yourself. A few things to know when you do.

Start from the defaults

Ollama starts at temperature 0.8, top_k 40, top_p 0.9 and min_p 0, with repeat_penalty off (1.0) since version 0.32.10. Many models in its library ship their own: qwen3 uses temperature 0.6, top_k 20 and top_p 0.95. Change one setting at a time, and compare a few replies each time.

Try min-p

min-p around 0.05 to 0.1 follows how sure the model is. Many local setups use it with top-k and top-p switched off (top_k 0, top_p 1).

Keep the penalty mild

If replies loop, a small repeat_penalty such as 1.05 to 1.1 is a common first try. Code, lists and names repeat on purpose, so a strong penalty hurts them first.

Settings do not add knowledge

Sampling settings choose among the words the model already rates well. If the answers are wrong, look at the prompt, the context or the model.

Checked on 2026-10-07 against the Ollama docs and its v0.32.10 release, the llama.cpp server docs and the min-p paper (Nguyen et al., 2025). Defaults differ by runner and change between versions. The repeat penalty comes from the CTRL paper (Keskar et al., 2019), which used 1.2. Ollama used 1.1 until v0.32.10, and llama.cpp documents 1.1 for its API while its command line leaves the penalty off. Lazaridis et al. (2026) found that a penalty of 1.30 broke a model's code, while 1.15 left it working.

Where this goes next

Next: LoRA

Settings change how the model picks. To change what it knows, you change the model itself, without retraining all of it.

Then: learning rate

How big a step each round of training takes, and why too big a step ruins a model.

Every number on this page comes from a C engine compiled to WebAssembly. The scores of the two spots are made up, and the reply comes from a model counted from twenty sentences about a made-up town.