pub trait Sampler: Send + Sync {
// Required methods
fn sample(&self, logits: &[f32], rng: &mut dyn RngCore) -> Result<TokenId>;
fn name(&self) -> &str;
fn is_deterministic(&self) -> bool;
// Provided method
fn sample_with_context(
&self,
ctx: &SamplingContext<'_>,
rng: &mut dyn RngCore,
) -> Result<TokenId> { ... }
}Expand description
Token sampler trait for selecting next token from processed logits
Required Methods§
Sourcefn sample(&self, logits: &[f32], rng: &mut dyn RngCore) -> Result<TokenId>
fn sample(&self, logits: &[f32], rng: &mut dyn RngCore) -> Result<TokenId>
Sample next token from logits
Sourcefn is_deterministic(&self) -> bool
fn is_deterministic(&self) -> bool
Whether this sampler is deterministic
Provided Methods§
Sourcefn sample_with_context(
&self,
ctx: &SamplingContext<'_>,
rng: &mut dyn RngCore,
) -> Result<TokenId>
fn sample_with_context( &self, ctx: &SamplingContext<'_>, rng: &mut dyn RngCore, ) -> Result<TokenId>
Sample with additional context (default implementation ignores context)