Expand description
2026-09-25: Host-side token sampling: SamplingParams, the Sampler that
copies device logits to the host, the penalty stage, and the argmax helpers.
Owner: metrale-sampling. Invariants:
- In this crate, only the non-greedy path of
sample_with_params_seededwrites the entropy gauges (throughrecord_entropy).
Modules§
- feed_
argmax - 2026-09-25: Host reference for one row of
argmax_bf16_batch_feed(kernels/gb10/common/argmax_feed.cu), computed from the same BF16 bytes.
Structs§
- Sampler
- 2026-09-25: Copies device logits to the host and picks tokens there.
- Sampling
Params - 2026-09-25: Sampling parameters for a request.
Functions§
- apply_
dry_ penalty - 2026-09-25: DRY (“don’t repeat yourself”) penalty. No-op for an empty
history or
multiplier == 0.0. - apply_
lz_ penalty - 2026-09-25: LZ penalty over the last
LZ_WINDOW(256) tokens ofhistory. - apply_
penalties_ and_ bias - 2026-09-25: Apply the repetition, presence, frequency, LZ and DRY penalties,
then the per-token logit bias, to
logitsin place, usingtoken_history. - argmax_
bf16 - 2026-09-25: Argmax over little-endian BF16 bytes; the first maximum wins, and
empty input returns 0. Used by
Sampler. - argmax_
f32 - 2026-09-25: Argmax over little-endian FP32 bytes, with the same two passes
and first-index tie-break as
argmax_first_wins_f32, reading the byte chunks directly instead of building aVec<f32>. - argmax_
first_ wins_ f32 - 2026-09-25: Index of the first maximum of
vunder strict>. - last_
entropy - 2026-09-25: Entropy (nats) of the last non-greedy sample in this run.
- low_
entropy_ token_ count - 2026-09-25: Non-greedy samples in this run whose entropy was below 0.3 nats.
- sample_
with_ params - 2026-09-25:
sample_with_params_historywith an empty history, so of the penalty stage only the logit bias applies. - sample_
with_ params_ history - sample_
with_ params_ seeded - 2026-09-25: Samples one token id from the little-endian f32 logits in
data.temperature <= 0.0returns the greedy argmax. OtherwiseSome(seed)draws fromStdRng::seed_from_u64(seed)andNonefromrand::random. - total_
sampled_ token_ count - 2026-09-25: Non-greedy samples in this run that recorded an entropy.