SamplingParams

Struct SamplingParams 

Source
pub struct SamplingParams {
Show 18 fields pub temperature: f32, pub top_k: u32, pub top_p: f32, pub top_n_sigma: f32, pub min_p: f32, pub logit_bias: Vec<(u32, f32)>, pub repetition_penalty: f32, pub repetition_penalty_window: u32, pub presence_penalty: f32, pub frequency_penalty: f32, pub lz_penalty: f32, pub dry_multiplier: f32, pub dry_base: f32, pub dry_allowed_length: u32, pub dry_sequence_breakers: Vec<u32>, pub max_tokens: usize, pub stop_token_ids: Vec<u32>, pub seed: Option<u64>,
}
Expand description

Sampling parameters for a request.

Fields§

§temperature: f32

Temperature (0.0 = greedy).

§top_k: u32

Top-k: keep only the k highest-probability tokens before sampling. 0 = disabled (use all tokens).

§top_p: f32

Top-p (nucleus): keep smallest set of tokens whose cumulative probability >= p. 1.0 = disabled.

§top_n_sigma: f32

Top-n-sigma: filter tokens in logit space before temperature scaling. Keep only tokens with logit >= mean - n*sigma. Temperature-invariant. 0.0 = disabled. Recommended: 1.0 for NVFP4 models.

§min_p: f32

Min-p: keep tokens with prob >= min_p * max_prob (post-softmax). 0.0 = disabled. Recommended: 0.05-0.1.

§logit_bias: Vec<(u32, f32)>

Per-token logit bias: (token_id, bias_value) pairs. Applied additively to raw logits before any filtering.

§repetition_penalty: f32

Repetition penalty: multiply logits of previously-seen tokens. 1.0 = disabled. Recommended: 1.05-1.1.

§repetition_penalty_window: u32

Repetition penalty window: only consider the last N tokens. 0 = full history (default). Recommended: 64 for long-form generation.

§presence_penalty: f32

Presence penalty (OpenAI-style): flat additive penalty for each token that appeared at least once. Range [-2.0, 2.0], 0.0 = disabled.

§frequency_penalty: f32

Frequency penalty (OpenAI-style): additive penalty proportional to occurrence count. Range [-2.0, 2.0], 0.0 = disabled.

§lz_penalty: f32

LZ penalty: penalize tokens that extend repeated n-gram patterns. 0.0 = disabled. 1.0 = moderate (default). Based on arXiv:2504.20131.

§dry_multiplier: f32

DRY (Don’t Repeat Yourself) penalty multiplier. From llama.cpp. Uses Z-algorithm O(n) sequence matching with exponential penalty. 0.0 = disabled. Recommended: 0.8.

§dry_base: f32

DRY penalty base for exponential scaling. penalty = multiplier * base^(match_len - allowed_len). Recommended: 1.75.

§dry_allowed_length: u32

DRY minimum match length before penalty applies. Sequences shorter than this are ignored. Recommended: 2.

§dry_sequence_breakers: Vec<u32>

DRY sequence breaker token IDs. Delimiters (newlines, colons, quotes, braces) that reset sequence tracking. Critical for JSON/tool call output where structural tokens repeat.

§max_tokens: usize

Maximum tokens to generate.

§stop_token_ids: Vec<u32>

Stop token IDs.

§seed: Option<u64>

Seed for deterministic sampling. When Some, the RNG is seeded with this value for reproducible output. None = non-deterministic (thread_rng).

Implementations§

Source§

impl SamplingParams

Source

pub fn greedy(max_tokens: usize) -> Self

Greedy sampling with a max token limit.

Source

pub fn is_greedy(&self) -> bool

Trait Implementations§

Source§

impl Clone for SamplingParams

Source§

fn clone(&self) -> SamplingParams

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 SamplingParams

Source§

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

Formats the value using the given formatter. 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.

§

impl<T> Instrument for T

§

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

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

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

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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