Skip to main content

SamplerConfig

Struct SamplerConfig 

Source
pub struct SamplerConfig {
Show 23 fields pub temperature: f32, pub top_k: usize, pub top_p: f32, pub min_p: f32, pub repetition_penalty: f32, pub repetition_penalty_window: usize, pub seed: Option<u64>, pub mirostat: u8, pub mirostat_tau: f32, pub mirostat_eta: f32, pub grammar: Option<Arc<Grammar>>, pub token_vocab: Option<Arc<Vec<(u32, Vec<u8>)>>>, pub logit_bias: HashMap<u32, f32>, pub banned_tokens: Vec<u32>, pub dry_multiplier: f32, pub dry_base: f32, pub dry_allowed_length: usize, pub xtc_threshold: f32, pub xtc_probability: f32, pub typical_p: f32, pub top_a: f32, pub eta_cutoff: f32, pub epsilon_cutoff: f32,
}
Expand description

Configuration for the sampling strategy.

Fields§

§temperature: f32

Temperature for logit scaling (1.0 = no scaling, 0.0 = greedy).

§top_k: usize

Top-K: only consider the K most likely tokens (0 = disabled).

§top_p: f32

Top-P (nucleus): only consider tokens with cumulative probability <= p.

§min_p: f32

Min-P: minimum probability threshold relative to the top token.

§repetition_penalty: f32

Repetition penalty factor (1.0 = no penalty).

§repetition_penalty_window: usize

Number of recent tokens to consider for repetition penalty.

§seed: Option<u64>

Random seed for reproducible sampling (None = random).

§mirostat: u8

Mirostat mode: 0 = disabled, 2 = Mirostat v2.

§mirostat_tau: f32

Mirostat target surprise (tau). Controls coherence vs diversity. Lower = more coherent, higher = more diverse. Default: 5.0.

§mirostat_eta: f32

Mirostat learning rate (eta). How fast the algorithm adapts. Default: 0.1.

§grammar: Option<Arc<Grammar>>

Optional GBNF grammar for constrained sampling. Logits for tokens that cannot advance the grammar are set to -∞. Skipped during serialization (not representable as JSON directly).

§token_vocab: Option<Arc<Vec<(u32, Vec<u8>)>>>

Pre-computed vocabulary (token_id, byte_repr) table used for grammar masking. Must be set when grammar is Some. Build via TokenizerBridge::vocab_bytes().

§logit_bias: HashMap<u32, f32>

Per-token logit biases applied before top-k/top-p.

Positive values increase a token’s probability; negative values decrease it. For example, logit_bias[token_id] = 5.0 strongly encourages that token, while -100.0 effectively bans it (use banned_tokens for strict banning).

Applied as: logits[token_id] += bias before the greedy / sampling steps.

§banned_tokens: Vec<u32>

Tokens that must never be generated.

Their logits are set to f32::NEG_INFINITY before any other sampling step, including top-k/p filtering. This is a hard constraint — unlike a large negative logit_bias, a banned token will never be selected even if it is the only remaining candidate.

§dry_multiplier: f32

DRY penalty multiplier (0.0 = disabled).

Penalises tokens that would continue an n-gram already present in the recent context. Higher values apply stronger penalties.

§dry_base: f32

DRY exponential base for match-length amplification (default = 1.75).

Longer n-gram matches receive penalty dry_multiplier * dry_base^(match_len - dry_allowed_length).

§dry_allowed_length: usize

Minimum match length (in tokens) before DRY applies any penalty (default = 2).

§xtc_threshold: f32

XTC cumulative-probability threshold (0.0 = disabled; use ≥ 1.0 to disable).

The “top set” is defined as the smallest set of tokens whose cumulative probability exceeds this threshold.

§xtc_probability: f32

XTC exclusion probability — how often the top-set exclusion fires (default = 0.5).

§typical_p: f32

Locally-typical sampling budget (1.0 = disabled / passthrough).

Keeps only tokens whose information content is closest to the distribution entropy until cumulative probability ≥ p.

§top_a: f32

Top-A adaptive threshold multiplier (0.0 = disabled).

Keeps tokens with prob >= top_a * max_prob².

§eta_cutoff: f32

Eta-cutoff entropy-adaptive threshold (0.0 = disabled).

Dynamic floor = max(epsilon_cutoff, eta_cutoff / perplexity).

§epsilon_cutoff: f32

Epsilon hard-floor probability used together with eta_cutoff (0.0 = no floor).

Implementations§

Source§

impl SamplerConfig

Source

pub fn greedy() -> Self

Create a greedy sampling config (always pick the most likely token).

Source

pub fn mirostat_v2(tau: f32, eta: f32) -> Self

Create a Mirostat v2 config with the given target surprise.

Trait Implementations§

Source§

impl Clone for SamplerConfig

Source§

fn clone(&self) -> SamplerConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SamplerConfig

Source§

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

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

impl Default for SamplerConfig

Source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for SamplerConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SamplerConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,