pub struct Sampler<'a, C> {
pub steps: Vec<&'a SampleStep<C>>,
pub finalizer: &'a SampleFinalizer<C>,
}Expand description
A series of sampling steps that will produce a vector of token data.
C is dynamic context that will be passed to the sampling functions. Some sampling steps may
require state to be maintained across multiple samples, and this context can be used to store
that state. For example, LlamaTokenDataArray::sample_token_mirostat_v2 requires a mu to be
shared across multiple samples.
Fields§
§steps: Vec<&'a SampleStep<C>>The steps to take when sampling.
finalizer: &'a SampleFinalizer<C>The final step to select one or more tokens from the remaining candidates.
Implementations§
source§impl<'a, T> Sampler<'a, T>
impl<'a, T> Sampler<'a, T>
sourcepub fn new(finalizer: &'a SampleFinalizer<T>) -> Self
pub fn new(finalizer: &'a SampleFinalizer<T>) -> Self
Create a new sampler with a given finalizer.
sourcepub fn push_step(&mut self, step: &'a SampleStep<T>)
pub fn push_step(&mut self, step: &'a SampleStep<T>)
Adds a step to the sampler.
sourcepub fn sample(
&mut self,
context: &mut T,
candidates: LlamaTokenDataArray
) -> Vec<LlamaTokenData>
pub fn sample( &mut self, context: &mut T, candidates: LlamaTokenDataArray ) -> Vec<LlamaTokenData>
Sample a token from the given candidates.
Trait Implementations§
Auto Trait Implementations§
impl<'a, C> Freeze for Sampler<'a, C>
impl<'a, C> !RefUnwindSafe for Sampler<'a, C>
impl<'a, C> !Send for Sampler<'a, C>
impl<'a, C> !Sync for Sampler<'a, C>
impl<'a, C> Unpin for Sampler<'a, C>
impl<'a, C> !UnwindSafe for Sampler<'a, C>
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