pub struct ConfigurableSampler {
pub config: SamplingConfig,
/* private fields */
}Expand description
A sampler that combines temperature scaling, top-k filtering, top-p (nucleus) filtering, and repetition penalty into a single configurable pipeline.
Pipeline order: repetition_penalty → temperature → top-k → top-p → sample.
Fields§
§config: SamplingConfigThe complete sampling configuration.
Implementations§
Source§impl ConfigurableSampler
impl ConfigurableSampler
Sourcepub fn new(config: SamplingConfig) -> Result<Self, SamplingError>
pub fn new(config: SamplingConfig) -> Result<Self, SamplingError>
Construct a ConfigurableSampler from a SamplingConfig.
Validates temperature, top_k, and top_p at construction time.
Sourcepub fn with_default() -> Self
pub fn with_default() -> Self
Construct a ConfigurableSampler with the default configuration.
This is equivalent to ConfigurableSampler::new(SamplingConfig::default()) but
is infallible because the defaults are always valid.
Sourcepub fn apply_repetition_penalty(
logits: &mut [f64],
context: &[usize],
penalty: f64,
)
pub fn apply_repetition_penalty( logits: &mut [f64], context: &[usize], penalty: f64, )
Apply repetition penalty in-place.
For each token that appears in context:
- If the logit is positive → divide by
penalty(move toward 0). - If the logit is negative → multiply by
penalty(move away from 0).
A penalty of 1.0 is a no-op.
Sourcepub fn sample(
&mut self,
logits: &[f64],
context: &[usize],
) -> Result<SampledToken, SamplingError>
pub fn sample( &mut self, logits: &[f64], context: &[usize], ) -> Result<SampledToken, SamplingError>
Run the full sampling pipeline:
- Apply repetition penalty to
logitsfor tokens incontext. - Scale by temperature.
- Apply top-k filter (if configured).
- Apply top-p (nucleus) filter (if configured).
- Sample from the resulting distribution.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConfigurableSampler
impl RefUnwindSafe for ConfigurableSampler
impl Send for ConfigurableSampler
impl Sync for ConfigurableSampler
impl Unpin for ConfigurableSampler
impl UnsafeUnpin for ConfigurableSampler
impl UnwindSafe for ConfigurableSampler
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> 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