Repository navigation
phase 1.56: DRY (Don't Repeat Yourself) LogitProcessor (#1082) - #1160
Merged
Merged
Conversation
Repetition penalty that scales **exponentially** with matched
n-gram length, per the oobabooga/Aphrodite/koboldcpp formulation.
## API
```rust
let p = DryProcessor::new(
/*multiplier=*/ 0.8,
/*base=*/ 1.75,
/*allowed_length=*/ 2,
/*history=*/ vec![row_history],
)
.with_sequence_breakers(newline_set);
let penalized = p.apply(&logits)?;
```
## Algorithm
For each batch row, walk history once and for each position `i`:
1. Count how many tokens *before* `i` match the tail of history
(with sequence-breaker resets). Call this `k`.
2. Match length for `history[i]` is `k + 1`.
3. Take the max across all positions for each token id.
For each token whose best match `m` exceeds `allowed_length`,
subtract `multiplier * base^(m - allowed_length)` from its logit.
`base ≤ 1` rejected (penalty must grow). `multiplier < 0` rejected
(would be a reward, not a penalty).
## Reference
oobabooga/textgen#5677 — the
canonical DRY implementation everyone has converged on.
## Tests
9 unit tests, CPU-only:
- No repetition → no penalty (sanity)
- Extended match: `[1,2,3,1,2]` + allowed=1 penalizes tok 3 by
`1.0 * 2^2 = 4.0`
- multiplier=0 is no-op
- Sequence breakers reset the match (insert a breaker between
two would-be repeats → no penalty)
- Longer match grows exponentially: `[1,2,3,1,2]` + allowed=0
→ tok 3 penalty `1.0 * 2^3 = 8.0`
- Negative multiplier errors
- base ≤ 1 errors
- History/batch mismatch errors
- name() == "dry"
## Chain status
11 of 12 menu items shipped. Remaining: grammar-mask (separate
schema-compiler effort).
Refs #1082
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repetition penalty that scales exponentially with matched n-gram length, per the oobabooga/Aphrodite/koboldcpp formulation.
API
Algorithm
For each batch row, walk history once and for each position
i:imatch the tail of history (with sequence-breaker resets). Call thisk.history[i]isk + 1.For each token whose best match
mexceedsallowed_length, subtractmultiplier * base^(m - allowed_length)from its logit.Reference
oobabooga/textgen#5677
Tests
9 unit tests, CPU-only.
Chain status
11 of 12 menu items shipped. Remaining: XTC + grammar-mask.
Refs #1082