Skip to main content

SampleOpts

Struct SampleOpts 

Source
pub struct SampleOpts {
Show 23 fields pub temperature: f32, pub top_p: f32, pub top_k: Option<u32>, pub repetition_penalty: f32, pub dynamic_temp: Option<(f32, f32)>, pub dynamic_temp_exponent: f32, pub typical_p: f32, pub top_n_sigma: f32, pub xtc_threshold: f32, pub xtc_prob: f32, pub dry_multiplier: f32, pub dry_base: f32, pub dry_allowed_length: usize, pub dry_max_ngram: usize, pub dry_sequence_breakers: Vec<u32>, pub mirostat: MirostatMode, pub mirostat_tau: f32, pub mirostat_eta: f32, pub mirostat_m: usize, pub frequency_penalty: f32, pub presence_penalty: f32, pub repetition_window: usize, pub min_keep: usize,
}
Expand description

Sampling parameters. Greedy when temperature == 0 and no advanced sampler is enabled. All “advanced” knobs default to off / no-op so legacy callers see classic top-k/top-p/temperature behaviour.

into_chain() turns these flat fields into a SamplerChain that downstream backends can execute. Ordering follows llama.cpp’s canonical chain (penalties → temperature → top-k → typical → top-p → top-n-σ → xtc → mirostat).

Fields§

§temperature: f32§top_p: f32§top_k: Option<u32>§repetition_penalty: f32§dynamic_temp: Option<(f32, f32)>

Dynamic temperature [min, max] gated by softmax entropy. None ⇒ flat temperature only.

§dynamic_temp_exponent: f32§typical_p: f32

Locally-typical sampling (Meister et al. 2022). 1.0 ⇒ off.

§top_n_sigma: f32

Top-n-σ cutoff (Hewitt et al. 2024). 0 ⇒ off.

§xtc_threshold: f32

XTC: probability of dropping high-confidence top tokens.

§xtc_prob: f32§dry_multiplier: f32

DRY repetition penalty knobs.

§dry_base: f32§dry_allowed_length: usize§dry_max_ngram: usize§dry_sequence_breakers: Vec<u32>§mirostat: MirostatMode

Mirostat mode + parameters.

§mirostat_tau: f32§mirostat_eta: f32§mirostat_m: usize§frequency_penalty: f32

Frequency / presence penalties (OpenAI-style).

§presence_penalty: f32§repetition_window: usize§min_keep: usize

Minimum tokens kept by top-p / typical (avoid one-token nucleus).

Implementations§

Source§

impl SampleOpts

Source

pub fn greedy() -> Self

Source

pub fn nucleus(temperature: f32, top_p: f32) -> Self

Source

pub fn is_greedy(&self) -> bool

Source

pub fn is_classic(&self) -> bool

True when only classic top-k/top-p/temperature are configured; backends can take a cheap fast path in this case (e.g. the existing sample_row CPU kernel) instead of building a chain.

Source

pub fn into_chain(&self) -> SamplerChain

Build the SamplerChain corresponding to these options. The returned chain is ready to drive SamplerChain::sample against a logits row + history. Greedy decoding produces a chain with one Temperature{t:1e-6} step (which collapses to argmax after softmax) — callers that want true greedy can short-circuit via is_greedy() before building the chain.

Trait Implementations§

Source§

impl Clone for SampleOpts

Source§

fn clone(&self) -> SampleOpts

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 SampleOpts

Source§

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

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

impl Default for SampleOpts

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> 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<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,