pub struct StochasticSampler { /* private fields */ }Expand description
Temperature / top-k / top-p / min-p / repetition-penalty sampling,
composed as a pipeline of logit transforms (see this module’s docs) and
driven by a seeded [Rng].
§Pipeline order
StochasticSampler::sample applies, in this order: repetition
penalty (needs the raw logit scale — see
[apply_repetition_penalty]’s docs) -> top-k -> top-p -> min-p ->
temperature -> softmax -> weighted-random draw. Top-k/top-p/min-p run
before temperature deliberately: top-p and min-p compute a softmax
internally to rank tokens by probability, and temperature changes how
flat or peaked that probability distribution is — running them after
temperature would make the nucleus/threshold decision depend on a
rescaling that has not been “committed to” yet. This is the same
ordering llama.cpp’s sampler chain uses.