Skip to main content

Sampler

Trait Sampler 

Source
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§

Source

fn sample(&self, logits: &[f32], rng: &mut dyn RngCore) -> Result<TokenId>

Sample next token from logits

Source

fn name(&self) -> &str

Get sampler name

Source

fn is_deterministic(&self) -> bool

Whether this sampler is deterministic

Provided Methods§

Source

fn sample_with_context( &self, ctx: &SamplingContext<'_>, rng: &mut dyn RngCore, ) -> Result<TokenId>

Sample with additional context (default implementation ignores context)

Implementors§