Crate metrale_sampling

Crate metrale_sampling 

Source
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_seeded writes the entropy gauges (through record_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.
SamplingParams
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 of history.
apply_penalties_and_bias
2026-09-25: Apply the repetition, presence, frequency, LZ and DRY penalties, then the per-token logit bias, to logits in place, using token_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 a Vec<f32>.
argmax_first_wins_f32
2026-09-25: Index of the first maximum of v under 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_history with 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.0 returns the greedy argmax. Otherwise Some(seed) draws from StdRng::seed_from_u64(seed) and None from rand::random.
total_sampled_token_count
2026-09-25: Non-greedy samples in this run that recorded an entropy.