Expand description
Token sampling from a decoder’s output logits: temperature, top-k, top-p (nucleus), and repetition penalty, on top of the greedy argmax ferrox previously always used unconditionally.
crate::speculative verifies draft tokens against
sampling_distribution – the exact distribution Sampler
draws from for a given SamplingParams – so speculation is
lossless with respect to whatever sampling configuration the caller
asked for, rather than only at temperature 0.
No external rand dependency: a small xorshift64* generator (the
same algorithm Decoder::new_random_small’s test-only Lcg already
uses in decoder.rs) is enough for sampling and keeps the
dependency tree the same minimal, pure-Rust shape as the rest of
this crate.
Structs§
- Recommended
Sampling - The sampling a checkpoint recommends for itself, one
Optionper field so that “this model says nothing about top_p” stays distinguishable from “this model recommends top_p = 1.0”. This is sglang’ssampling_defaults='model', ported from FreeTokenpython/freetoken/utils/hf.py:92 load_generation_sampling. - Requested
Sampling - The sampling fields one request actually specified.
Nonemeans the request said nothing about that field, so the checkpoint’s recommendation (and then the framework default) may speak for it. - Sampler
- A small, seedable xorshift64* generator. Not cryptographically secure – sampling doesn’t need that – but reproducible given a seed, which greedy argmax already was for free.
- Sampling
Params - Sampling parameters for one generation request.
temperature <= 0.0means “sample nothing, take the greedy argmax” – the same deterministic behavior ferrox always had before this module existed.
Functions§
- sampling_
distribution - The exact distribution
Sampler::sampledraws from for these logits, params and history: penalties applied, temperature divided in, top-k and top-p filtered, renormalised to sum to 1.
Type Aliases§
- Logit
Mask - Zeroes out logits a caller wants to forbid, in place, before the sampler looks at them. Used by JSON-object mode to keep generation inside the grammar.