Expand description
Token sampling strategies.
Phase 1: Greedy argmax (CPU-side D2H + argmax). Future: temperature, top-k, top-p, min-p, repetition penalty.
Structs§
- Sampler
- Sampler that picks tokens from logits.
- Sampling
Params - Sampling parameters for a request.
Functions§
- apply_
dry_ penalty - DRY (Don’t Repeat Yourself) penalty. Ported from llama.cpp PR #9702.
- apply_
lz_ penalty - Sampling pipeline: repetition_penalty → top-n-sigma → temperature → top-k → softmax → min-p → top-p → sample.
- apply_
penalties_ and_ bias - Apply repetition / presence / frequency / LZ / DRY penalties and
per-token logit bias to
logitsIN PLACE, usingtoken_history. - argmax_
bf16 - Legacy: argmax over BF16 values (still used by argmax_on_device fallback).
- argmax_
f32 - Argmax over FP32 values stored as raw bytes (4 bytes per element, little-endian).
First-index-wins, identical to
argmax_first_wins_f32— same two-pass shape, iterating the byte chunks directly so noVec<f32>is materialised. - argmax_
first_ wins_ f32 - Argmax over an f32 slice with the strict-
>FIRST-index-wins tie-break. - last_
entropy - Read the most recent per-token entropy (nats).
- low_
entropy_ token_ count - Total tokens with entropy < 0.3 (potential degeneration).
- sample_
with_ params - Convenience wrapper: sample without token history (no repetition penalty).
- sample_
with_ params_ history - sample_
with_ params_ seeded - Core sampling pipeline with explicit seed control.
seedoverrides the RNG for deterministic sampling. None = thread_rng. - total_
sampled_ token_ count - Total tokens sampled (for computing low-entropy ratio).