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
impl DryParams
Sourcepub fn off() -> Self
pub fn off() -> Self
DRY switched off, which is llama.cpp’s default
(dry_multiplier = 0.0f, common/common.h:242).
Sourcepub fn new(
multiplier: f32,
base: f32,
allowed_length: i32,
penalty_last_n: i32,
total_context_size: usize,
breakers: DryBreakers,
) -> Self
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.
Sourcepub fn is_enabled(&self) -> bool
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.
pub fn multiplier(&self) -> f32
pub fn base(&self) -> f32
pub fn allowed_length(&self) -> i32
pub fn penalty_last_n(&self) -> i32
pub fn total_context_size(&self) -> usize
pub fn breakers(&self) -> &DryBreakers
Sourcepub fn penalties(&self, history: PenaltyWindow<'_>) -> HashMap<usize, f32>
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:
- walk backwards for a sequence breaker, and clamp how far a
repetition may reach (
rep_limit); - the reverse Z-algorithm, which fills
repeat_count[i]with the length of the window’s suffix that also occurs ending at positioni; - 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;
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§
Auto Trait Implementations§
impl Freeze for DryParams
impl RefUnwindSafe for DryParams
impl Send for DryParams
impl Sync for DryParams
impl Unpin for DryParams
impl UnsafeUnpin for DryParams
impl UnwindSafe for DryParams
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> 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