Skip to main content

Sampler

Struct Sampler 

Source
pub struct Sampler { /* private fields */ }
Expand description

Stateful sampler: owns the RNG + the recent-token history (for penalties).

Implementations§

Source§

impl Sampler

Source

pub fn new(cfg: SamplerConfig) -> Self

Source

pub fn is_greedy(&self) -> bool

Source

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.

Source

pub fn top_k(&self) -> usize

Source

pub fn penalty_last_n(&self) -> usize

Source

pub fn penalty_repeat(&self) -> f32

Source

pub fn penalty_freq(&self) -> f32

Source

pub fn penalty_present(&self) -> f32

Source

pub fn top_p(&self) -> f32

Source

pub fn min_p(&self) -> f32

Source

pub fn temperature(&self) -> f32

Source

pub fn seed(&self) -> u64

Source

pub fn accept(&mut self, token: u32)

Record an emitted token so subsequent penalties see it.

Source

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.)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.