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: f32Temperature for logit scaling (1.0 = no scaling, 0.0 = greedy).
top_k: usizeTop-K: only consider the K most likely tokens (0 = disabled).
top_p: f32Top-P (nucleus): only consider tokens with cumulative probability <= p.
min_p: f32Min-P: minimum probability threshold relative to the top token.
repetition_penalty: f32Repetition penalty factor (1.0 = no penalty).
repetition_penalty_window: usizeNumber of recent tokens to consider for repetition penalty.
seed: Option<u64>Random seed for reproducible sampling (None = random).
mirostat: u8Mirostat mode: 0 = disabled, 2 = Mirostat v2.
mirostat_tau: f32Mirostat target surprise (tau). Controls coherence vs diversity. Lower = more coherent, higher = more diverse. Default: 5.0.
mirostat_eta: f32Mirostat 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: f32DRY 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: f32DRY 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: usizeMinimum match length (in tokens) before DRY applies any penalty (default = 2).
xtc_threshold: f32XTC 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: f32XTC exclusion probability — how often the top-set exclusion fires (default = 0.5).
typical_p: f32Locally-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: f32Top-A adaptive threshold multiplier (0.0 = disabled).
Keeps tokens with prob >= top_a * max_prob².
eta_cutoff: f32Eta-cutoff entropy-adaptive threshold (0.0 = disabled).
Dynamic floor = max(epsilon_cutoff, eta_cutoff / perplexity).
epsilon_cutoff: f32Epsilon hard-floor probability used together with eta_cutoff (0.0 = no floor).
Implementations§
Source§impl SamplerConfig
impl SamplerConfig
Trait Implementations§
Source§impl Clone for SamplerConfig
impl Clone for SamplerConfig
Source§fn clone(&self) -> SamplerConfig
fn clone(&self) -> SamplerConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SamplerConfig
impl Debug for SamplerConfig
Source§impl Default for SamplerConfig
impl Default for SamplerConfig
Source§impl<'de> Deserialize<'de> for SamplerConfig
impl<'de> Deserialize<'de> for SamplerConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for SamplerConfig
impl RefUnwindSafe for SamplerConfig
impl Send for SamplerConfig
impl Sync for SamplerConfig
impl Unpin for SamplerConfig
impl UnsafeUnpin for SamplerConfig
impl UnwindSafe for SamplerConfig
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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>
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