Skip to main content

LlamaSampler

Struct LlamaSampler 

Source
pub struct LlamaSampler {
    pub sampler: *mut llama_sampler,
}

Fields§

§sampler: *mut llama_sampler

Implementations§

Source§

impl LlamaSampler

Source

pub fn sample( &mut self, ctx: &LlamaContext<'_>, idx: i32, ) -> Result<LlamaToken, SampleError>

§Errors

Returns SampleError if the C++ sampler throws an exception or if the index is invalid.

Source

pub fn apply(&self, data_array: &mut LlamaTokenDataArray)

Source

pub fn accept(&mut self, token: LlamaToken) -> Result<(), SamplerAcceptError>

§Errors

Returns SamplerAcceptError if the underlying sampler rejects the token.

Source

pub fn accept_many( &mut self, tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>, ) -> Result<(), SamplerAcceptError>

§Errors

Returns SamplerAcceptError if the underlying sampler rejects any token.

Source

pub fn with_tokens( self, tokens: impl IntoIterator<Item = impl Borrow<LlamaToken>>, ) -> Result<Self, SamplerAcceptError>

§Errors

Returns SamplerAcceptError if the underlying sampler rejects any token.

Source

pub fn try_accept( &mut self, token: LlamaToken, ) -> Result<(), SamplerAcceptError>

§Errors

Returns an error if the underlying sampler rejects the token.

Source

pub fn reset(&mut self)

Source

pub fn get_seed(&self) -> u32

Source

pub fn chain(samplers: impl IntoIterator<Item = Self>, no_perf: bool) -> Self

Source

pub fn chain_simple(samplers: impl IntoIterator<Item = Self>) -> Self

Source

pub fn temp(t: f32) -> Self

Source

pub fn temp_ext(t: f32, delta: f32, exponent: f32) -> Self

Source

pub fn top_k(k: i32) -> Self

Source

pub fn top_n_sigma(n: f32) -> Self

Source

pub fn typical(p: f32, min_keep: usize) -> Self

Source

pub fn top_p(p: f32, min_keep: usize) -> Self

Source

pub fn min_p(p: f32, min_keep: usize) -> Self

Source

pub fn xtc(p: f32, t: f32, min_keep: usize, seed: u32) -> Self

Source

pub fn grammar( model: &LlamaModel, grammar_str: &str, grammar_root: &str, ) -> Result<Self, GrammarError>

§Errors

Returns an error if the grammar is invalid or the sampler cannot be initialized.

Source

pub fn grammar_lazy( model: &LlamaModel, grammar_str: &str, grammar_root: &str, trigger_words: impl IntoIterator<Item = impl AsRef<[u8]>>, trigger_tokens: &[LlamaToken], ) -> Result<Self, GrammarError>

§Errors

Returns an error if the grammar or trigger words are invalid.

Source

pub fn grammar_lazy_patterns( model: &LlamaModel, grammar_str: &str, grammar_root: &str, trigger_patterns: &[String], trigger_tokens: &[LlamaToken], ) -> Result<Self, GrammarError>

§Errors

Returns an error if the grammar or trigger patterns are invalid.

Source

pub fn llguidance( model: &LlamaModel, grammar_kind: &str, grammar_data: &str, ) -> Result<Self, GrammarError>

§Errors

Returns GrammarError if the grammar is invalid or the sampler cannot be initialized.

Source

pub fn dry( model: &LlamaModel, multiplier: f32, base: f32, allowed_length: i32, penalty_last_n: i32, seq_breakers: impl IntoIterator<Item = impl AsRef<[u8]>>, ) -> Result<Self, GrammarError>

§Errors

Returns an error if any string in seq_breakers contains null bytes.

Source

pub fn penalties( penalty_last_n: i32, penalty_repeat: f32, penalty_freq: f32, penalty_present: f32, ) -> Self

Source

pub fn mirostat(n_vocab: i32, seed: u32, tau: f32, eta: f32, m: i32) -> Self

Source

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

Source

pub fn dist(seed: u32) -> Self

Source

pub fn greedy() -> Self

Source

pub fn logit_bias( n_vocab: i32, biases: &[LlamaLogitBias], ) -> Result<Self, SamplingError>

§Errors

Returns SamplingError::IntegerOverflow if biases.len() exceeds i32::MAX.

Trait Implementations§

Source§

impl Debug for LlamaSampler

Source§

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

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

impl Drop for LlamaSampler

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> 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, 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.