pub struct Sampler { /* private fields */ }Expand description
Stateful sampler that maintains PRNG state across calls.
Implementations§
Source§impl Sampler
impl Sampler
Sourcepub fn new(config: SamplerConfig) -> Self
pub fn new(config: SamplerConfig) -> Self
Create a new sampler with the given config.
Sourcepub fn sample(&mut self, logits: &[f32], recent_tokens: &[u32]) -> u32
pub fn sample(&mut self, logits: &[f32], recent_tokens: &[u32]) -> u32
Sample a token ID from logits.
Sourcepub fn reset_grammar(&mut self)
pub fn reset_grammar(&mut self)
Reset the grammar state to the beginning (use for a new generation).
Sourcepub fn grammar_complete(&self) -> bool
pub fn grammar_complete(&self) -> bool
Returns true when the grammar (if any) is in a valid accepting state.
Sourcepub fn config(&self) -> &SamplerConfig
pub fn config(&self) -> &SamplerConfig
Get a reference to the config.
Sourcepub fn mirostat_mu_value(&self) -> f32
pub fn mirostat_mu_value(&self) -> f32
Return the current mirostat mu value for snapshot/resume.
Sourcepub fn restore_rng_state(&mut self, state: u64, mu: f32)
pub fn restore_rng_state(&mut self, state: u64, mu: f32)
Restore the RNG state and mirostat mu (for resume).
Auto Trait Implementations§
impl Freeze for Sampler
impl RefUnwindSafe for Sampler
impl Send for Sampler
impl Sync for Sampler
impl Unpin for Sampler
impl UnsafeUnpin for Sampler
impl UnwindSafe for Sampler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more