Temperature, top-p, top-k and min-p calculator
This page computes what temperature, top-p, top-k and min-p do to a real sampling distribution. Enter any logits, and it applies the Hugging Face transformers filter rules in the order that the library appends its logits processors, temperature first, then top-k, then top-p, then min-p. It also runs the llama.cpp CLI order on the same logits, where temperature is applied last. For every token you see its probability at temperature 1, after temperature and after the filters, which filter removed it, and how the surviving mass renormalizes. On the worked example below, temperature 0.7 with top-p 0.9 keeps 3 of the 5 tokens at 73.69%, 17.66% and 8.65%. All arithmetic runs in your browser.
Updated 17 November 2026
By Michael Lip, zovo.one. Temperature divides the logits by a value before the softmax. The Hugging Face TemperatureLogitsWarper computes scores_processed = scores / self.temperature. Top-p keeps the smallest set of tokens whose cumulative probability reaches top_p when sorted in descending order, exactly as TopPLogitsWarper sorts the scores in ascending order and removes tokens whose cumulative probability is at or below 1 - top_p. Hugging Face top-k keeps each token whose score is greater than or equal to the k-th score, so ties can keep more than k tokens, while llama.cpp keeps exactly k. Min-p keeps every token whose probability is not below min_p times the probability of the leading token. The page does not send your inputs to a server.
Compute the filtered distribution
Result, Hugging Face order (temperature, top-k, top-p, min-p)
| Token | Raw logit | p at T=1 | p after temperature | Final p (renormalized) | Kept or removed by |
|---|
Result, llama.cpp CLI order (top-k, top-p, min-p, temperature last)
| Token | Raw logit | p at T=1 | Final p (renormalized) | Kept or removed by |
|---|
The worked example, step by step
The default inputs give these exact numbers. The five logits 2.0, 1.0, 0.5, 0.0, -1.0 have a plain softmax of 56.30%, 20.71%, 12.56%, 7.62%, 2.80%. At temperature 0.7 the softmax becomes 70.02%, 16.78%, 8.21%, 4.02%, 0.96%. Top-p 0.90 keeps the smallest prefix whose cumulative mass reaches 0.90: after token 2 the mass is 86.80%, after token 3 it is 95.01%, so 3 tokens survive and renormalize to 73.69%, 17.66% and 8.65%. With top-p 0.9, top-k 0 and min-p 0 the calculator keeps those 3 tokens in the Hugging Face order and 4 in the llama.cpp order, where the cutoffs run on the temperature-1 probabilities first and only then rescale. Set temperature to 1, top-p to 1.0 and min-p to 0.1, and 4 of the 5 tokens survive, at 57.93%, 21.31%, 12.93% and 7.84%, because the leading probability 56.30% sets the cutoff at 5.63% and the weakest token at 2.80% falls below it. In the llama.cpp order the same settings give the same split, because at temperature 1 the position of the temperature step does not change the result.
What each filter does, in the exact words of the implementations
Temperature rescales all logits before the softmax. Hugging Face's TemperatureLogitsWarper computes scores_processed = scores / self.temperature, and the generation default is 1.0. Values below 1 sharpen the distribution toward the leading token, values above 1 flatten it. Top-p keeps the nucleus. TopPLogitsWarper sorts the scores in ascending order, computes the cumulative sum of their softmax and removes every token whose cumulative probability at its sorted position is at or below 1 - top_p, which keeps the smallest prefix whose mass reaches top_p and always keeps at least one token. In Hugging Face, top-k keeps each score that is greater than or equal to the k-th highest score, so a tie at the cutoff keeps more than k tokens, and the warper always keeps at least min_tokens_to_keep = 1. Min-p removes each token whose probability is less than min_p times the top probability, and Hugging Face computes scaled_min_p = self.min_p * top_probs against the leading probability. The llama.cpp CLI table documents top-k 40, top-p 0.95 and min-p 0.05, and runs its samplers in the default chain order penalties;dry;top_n_sigma;top_k;typ_p;top_p;min_p;xtc;temperature, with temperature last. The prose of the same README gives top-p 0.9 and min-p 0.1, which differs from its own table. Hugging Face raises an error for temperature 0 and tells you to set do_sample=False for greedy decoding. This page treats temperature 0 as greedy, one token at probability 1, and never divides by zero.
Ties and exact boundaries
Hugging Face sorts with torch.sort(scores, descending=False) and does not pass stable=True, the option that the PyTorch torch.sort documentation says "guarantees that the order of equivalent elements is preserved". llama.cpp ranks candidates in llama-sampler.cpp at c7518db with std::partial_sort and the comparator return a.logit > b.logit;, which sets no order for equal logits. So when tied tokens sit on a cut, the libraries do not promise which one stays, and this page fixes the order. In the Hugging Face table, tied tokens keep their input order in the ascending sort, so at a top-p cut the higher-numbered token stays. In the llama.cpp table, tied tokens rank by input order, so at a top-k or top-p cut the lower-numbered token stays. Hugging Face top-k and both min-p rules keep every tied token, so no tie rule is needed there. A cumulative sum that comes within 0.000000000001 of the top-p value counts as reaching it, so 10 equal logits with top-p 0.9 keep 9 tokens, as in exact arithmetic.
What this tool does not do
This page is a computation aid, not advice. It does not decide what sampling values you should use for your model or your workload. Always verify the cutoffs against your own runtime before you rely on them in production.
Formula notes
The softmax at temperature T is p_i = exp(z_i / T) / sum_j exp(z_j / T). This page computes every softmax with the maximum logit subtracted first, so logits of 1000 and -1000 cannot overflow, and temperature 0 gives the greedy limit instead of a division by zero. For top-p, sort p in descending order, keep the smallest prefix with cumulative sum at or above top_p, remove the rest and renormalize. A top-p of 1.0 disables the filter, per the llama.cpp help text. For top-k, in the Hugging Face order, keep the scores at or above the k-th score, and in the llama.cpp order, keep exactly k tokens. A top-k of 0 disables it. Min-p keeps tokens with p_i at or above min_p times the maximum p, and a min-p of 0 disables it. The filters compose in the order that the library appends them, and the surviving probabilities renormalize over the kept set. The nucleus idea and its truncation of the "less reliable tail" come from Holtzman et al., arXiv 1904.09751. Min-p as a dynamic truncation that scales the threshold with the top token's probability comes from Nguyen et al., arXiv 2407.01082. The softmax that maps logits to probabilities in [0,1] summing to 1 is the standard PyTorch definition.
Where these numbers come from
All sources were fetched on 2026-11-17. The processor rules come from the Hugging Face transformers logits_process.py at the pinned commit fc75327 (TemperatureLogitsWarper, TopKLogitsWarper, TopPLogitsWarper, MinPLogitsWarper), and the append order from generation/utils.py at the same commit, lines 1616 to 1630. The generation defaults temperature 1.0, top_k 50 and top_p 1.0 come from configuration_utils.py at the same commit. The llama.cpp sampler chain order, its CLI table defaults and its prose disagreement come from the llama.cpp completion README at the pinned commit c7518db. The nucleus-sampling definition comes from Holtzman et al., arXiv 1904.09751, and min-p from Nguyen et al., arXiv 2407.01082. The results are calculations from your inputs. The arithmetic runs in this browser tab.
Estimates use standard published formulas. Real results vary with your data, your settings, and your runtime.
This tool is for planning and teaching. Check a result against your own measurement before you rely on it.
All computation runs client side. No data leaves your browser.
ml0x publishes free machine learning calculators and explainers. Every calculator result on this page is computed in your browser from the inputs you enter. Nothing is sent to a server. Written by Michael Lip, part of the Zovo Tools network.
By Michael Lip, zovo.one.