Skip to main content

SamplingConfig

Struct SamplingConfig 

Source
pub struct SamplingConfig {
    pub temperature: f32,
    pub top_k: Option<usize>,
    pub top_p: Option<f32>,
    pub min_p: Option<f32>,
    pub repeat_penalty: f32,
    pub repeat_last_n: usize,
    pub seed: u64,
}
Expand description

Configuration for StochasticSampler’s logit-transform pipeline.

Every threshold is Option-or-plain depending on whether “disabled” is a meaningful state: top_k/top_p/min_p default to None (that stage of the pipeline is skipped entirely), while temperature and repeat_penalty always run (a temperature of 1.0 and a repeat penalty of 1.0 are each that stage’s identity value, so leaving them at their defaults is equivalent to skipping them, without needing a second Option layer).

Fields§

§temperature: f32

Divides every logit before the final softmax. 1.0 (the default) leaves the distribution’s shape unchanged; values below 1.0 sharpen it toward the top-scoring tokens, values above 1.0 flatten it toward uniform. <= 0.0 is treated as “skip stochastic sampling entirely and fall back to greedy_argmax” — see StochasticSampler::sample’s docs for why that is an exact equivalence, not an approximation.

§top_k: Option<usize>

Keep only the k highest-scoring tokens before sampling. None (the default) skips this stage.

§top_p: Option<f32>

Nucleus sampling: keep the smallest prefix of tokens (sorted by probability, descending) whose cumulative probability is the first to exceed p. None (the default) skips this stage.

§min_p: Option<f32>

Keep only tokens whose probability is at least min_p times the single most likely token’s probability. None (the default) skips this stage.

§repeat_penalty: f32

Divides a previously-generated token’s logit by this value if it was positive, or multiplies it if negative — the standard (Keskar et al., 2019, CTRL) repetition penalty. 1.0 (the default) is the identity: no penalty.

§repeat_last_n: usize

How many of the most recently generated tokens StochasticSampler remembers for Self::repeat_penalty’s history window.

§seed: u64

Seeds StochasticSampler’s internal PRNG — see this module’s docs for why this is mandatory rather than defaulting to system entropy.

Trait Implementations§

Source§

impl Clone for SamplingConfig

Source§

fn clone(&self) -> SamplingConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SamplingConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SamplingConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.