apply_dry_penalty

Function apply_dry_penalty 

Source
pub fn apply_dry_penalty(
    logits: &mut [f32],
    history: &[u32],
    multiplier: f32,
    base: f32,
    allowed_length: u32,
    breakers: &[u32],
)
Expand description

DRY (Don’t Repeat Yourself) penalty. Ported from llama.cpp PR #9702.

Uses suffix matching to find the longest repeated sequence ending at the current position in the token history. For each candidate token, checks if appending it would extend a previously-seen sequence. Applies exponential penalty: penalty = multiplier * base^(match_length - allowed_length)

Sequence breakers (e.g., newlines, quotes, braces) reset tracking, preventing false positives in structured output like JSON tool calls.