Skip to main content

DryParams

Struct DryParams 

Source
pub struct DryParams { /* private fields */ }
Expand description

One request’s DRY configuration.

Fields are private and there is no Default that can be enabled: DryParams::off is the only way to get a disabled one and DryParams::new the only way to get an enabled one, and it takes the breakers. See the module docs for why that is a type invariant rather than a convention.

Implementations§

Source§

impl DryParams

Source

pub fn off() -> Self

DRY switched off, which is llama.cpp’s default (dry_multiplier = 0.0f, common/common.h:242).

Source

pub fn new( multiplier: f32, base: f32, allowed_length: i32, penalty_last_n: i32, total_context_size: usize, breakers: DryBreakers, ) -> Self

DRY with the given configuration and breakers.

total_context_size is llama.cpp’s n_ctx_train: the ceiling a penalty_last_n of -1 resolves to, and the clamp every window is passed through.

Source

pub fn is_enabled(&self) -> bool

The single predicate for “DRY does nothing”, transcribed from the guard both llama_sampler_dry_accept (:3143) and llama_sampler_dry_apply (:3154) open with, and the same three conditions llama_sampler_init_dry reads to return an empty sampler (:3387).

One function rather than the three copies upstream has, because this is read by the chain, by the CLI banner and by the server’s refusal, and a disagreement between them is a sampler that is reported on but not run.

Source

pub fn multiplier(&self) -> f32

Source

pub fn base(&self) -> f32

Source

pub fn allowed_length(&self) -> i32

Source

pub fn penalty_last_n(&self) -> i32

Source

pub fn total_context_size(&self) -> usize

Source

pub fn breakers(&self) -> &DryBreakers

Source

pub fn penalties(&self, history: PenaltyWindow<'_>) -> HashMap<usize, f32>

The penalty to SUBTRACT from each token’s logit, keyed by token id. Empty when DRY is off or has nothing to say.

llama_sampler_dry_apply (src/llama-sampler.cpp:3151-3345), in its four documented steps:

  1. walk backwards for a sequence breaker, and clamp how far a repetition may reach (rep_limit);
  2. the reverse Z-algorithm, which fills repeat_count[i] with the length of the window’s suffix that also occurs ending at position i;
  3. for each non-zero count, the token that WOULD extend that repetition is the one to penalise, and the longest repetition ending in it wins;
  4. multiplier * base ^ (length - allowed_length), skipped for a token that is a whole sequence breaker by itself.

history is the same PenaltyWindow the repetition penalties use, for the same reason: llama.cpp’s DRY sampler is fed by common_sampler_accept, which both front ends call for prompt tokens as well as generated ones (see crate::penalty_window).

Trait Implementations§

Source§

impl Clone for DryParams

Source§

fn clone(&self) -> DryParams

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 DryParams

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.

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> Same for T

Source§

type Output = T

Should always be Self
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.