pub struct Sampler { /* private fields */ }Expand description
Stateful sampler: owns the RNG + the recent-token history (for penalties).
Implementations§
Source§impl Sampler
impl Sampler
pub fn new(cfg: SamplerConfig) -> Self
pub fn is_greedy(&self) -> bool
Sourcepub fn is_spec_sampling(&self) -> bool
pub fn is_spec_sampling(&self) -> bool
Sampled spec in its FASTEST regime: pure temperature, no truncation filters, no
penalties. Filters and penalties are also distribution-exact under the rejection
verify (spec.rs applies both symmetrically to draft q and target p), so they remain
spec-ELIGIBLE — see spec_eligible in memra-server’s worker, the authoritative
predicate. What they cost is the in-graph draft chain: the captured sampled draft
samples from the RAW softmax and can hold neither per-row filter stats nor a varying
penalty history, so spec.rs engages graph_s only in this pure-temp regime
(pure_temp) and otherwise falls back to the eager draft chain. This predicate names
that regime; it is NOT an eligibility test.
pub fn top_k(&self) -> usize
pub fn penalty_last_n(&self) -> usize
pub fn penalty_repeat(&self) -> f32
pub fn penalty_freq(&self) -> f32
pub fn penalty_present(&self) -> f32
pub fn top_p(&self) -> f32
pub fn min_p(&self) -> f32
pub fn temperature(&self) -> f32
pub fn seed(&self) -> u64
Sourcepub fn identity(&self) -> SamplerIdentity
pub fn identity(&self) -> SamplerIdentity
This sampler’s canonical SamplerIdentity — the whole-session resume predicate’s input.
Sourcepub fn penalty_counts(&self) -> Vec<(u32, u32)>
pub fn penalty_counts(&self) -> Vec<(u32, u32)>
Sparse (token_id, count) rows for the current penalty window. The order cannot affect
the arithmetic because every entry mutates one distinct logit; avoiding a per-token sort
is material on long agent histories.
Sourcepub fn sample(&mut self, logits: &[f32]) -> u32
pub fn sample(&mut self, logits: &[f32]) -> u32
Sample the next token id from raw logits [n_vocab]. Does NOT mutate logits in place beyond
a local copy. Returns the chosen token id. (Caller should accept() it afterwards.)
Sourcepub fn penalized_logits(&self, logits: &[f32]) -> Vec<f32>
pub fn penalized_logits(&self, logits: &[f32]) -> Vec<f32>
The penalized logits row this sampler would score the next token from, as bytes: a
copy of logits with the active penalty window applied through the ONE serving
penalty pass (apply_penalties_dense). Identity when penalties are off (window
empty or every coefficient neutral), exactly as sample sees it.
EXISTS AS THE ORACLE SEAM for the device penalty kernels (lane/spec-exclusions-
20260902): a spec route that penalizes verify rows on device claims “the same bits
the plain sampler produces”, and that claim needs the plain sampler’s bits to compare
against, not a re-derivation in a test. sample only ever returns the chosen id.