Expand description
Sampling controls for decode loops (ROADMAP row 133, slice 1: the pure host sampler).
sample_with_params picks the next token from one logits row under a SamplingParams and
the tokens seen so far. It is host-side and deterministic: the same logits, params, history and
RNG state give the same token. With only a positive temperature set it reduces exactly to
crate::lazy::sample_logits (same RNG stream, same probabilities), which a test pins.
Order of operations, so a caller can predict the result:
- penalties on the raw logits, from
history: repetition (HF form: a seen token’s positive logit is divided by the penalty, a negative one multiplied), thenlogit -= frequency * count + presence * (count > 0); temperature <= 0or NaN: the argmax of the penalised logits (greedy), lowest index on a tie;- otherwise scale by
1 / temperature, softmax, thentop_k, thentop_p(nucleus: the smallest prefix of descending probabilities reachingtop_p, at least one token), thenmin_p(drop tokens belowmin_ptimes the largest remaining probability), renormalise, and draw withcrate::lazy::sample_multinomial.
Logprobs are of the model’s own distribution: log_softmax of the INPUT logits, before
penalties, temperature and filters (vLLM’s “raw logprobs”). They describe what the model said,
not what was sampled from, and they do not depend on the sampling controls.
history is whatever the caller wants penalised. OpenAI penalises generated tokens only;
HF’s repetition penalty covers the prompt too. The scheduler slice decides which it passes.
Structs§
- Sampled
- One sampled step.
- Sampling
Params - Every control for one sampling step.
Defaultis greedy with no penalties and no logprobs.
Functions§
- sample_
with_ params - Pick the next token. Errors on empty or non-finite logits, a history token outside the vocabulary, or invalid params; never panics.