Skip to main content

Module sampler

Module sampler 

Source
Expand description

Token sampling — temperature, top-p, top-k, min-p, repetition penalty.

Randomness comes from an explicit SplitMix64 PRNG carried by the caller: reproducible with a seed, unbiased across the whole CDF (the v1 subsec_nanos source could never pick past ~23% of it).

Structs§

SamplerConfig
Sampling configuration.
SamplerScratch
Reusable per-pipeline sampling workspace. The epoch table lets the repetition penalty visit each token id once without allocating a HashSet or clearing a vocab-sized boolean vector on every decode step.
SplitMix64
SplitMix64 — tiny, fast, statistically solid for sampling.

Functions§

argmax
Greedy: index of the maximum value.
sample
Sample next token from logits. Chain order is fixed: rep-penalty → temperature → softmax → min-p → top-k → top-p → sample.
sample_with_scratch
Sampling entry point for hot decode loops with reusable scratch storage.