Skip to main content

sample_token

Function sample_token 

Source
pub fn sample_token(
    logits: &[f32],
    temperature: f32,
    top_k: usize,
    _repetition_penalty: f32,
) -> u32
Expand description

Sample a token from logits with temperature, top-k, and repetition penalty. Sample a token matching qwen3-tts-rs reference:

  1. temperature scaling
  2. top-k filter (keep top_k, rest = -inf)
  3. top-p filter (keep smallest set with cumprob > top_p, rest = -inf)
  4. softmax over filtered logits
  5. multinomial sample from distribution