Don't Repeat Yourself: Stopping Verbatim Loops at Sampling Time
Organizations: Thoughtworks · New York University
Abstract
Large Language Models generate text autoregressively, but open-ended generation is prone to verbatim looping, in which models repeat spans already present in context. Standard defenses such as repetition, presence, and frequency penalties and n-gram blocking act on token recurrence rather than the sequential structure of a loop, and often suppress looping only at strengths that also degrade formatting or fluency. We propose Don't Repeat Yourself (DRY), a sampling-time logit adjustment that penalizes a candidate token only when generating it would extend the current suffix into an exact continuation of a span seen earlier in the context. Sequence breakers protect chat templates and formatting tokens. Across models from 1.5B to 120B parameters, nine prompt families, and a 600-pair human study, DRY reduces suffix-extension rate by 47% while improving lexical diversity. An intervention-matched placebo produces no comparable reduction, identifying suffix matching as the operative mechanism. On AWQ-quantized 70B and 120B models, DRY reduces loop rate by roughly half while preserving MT-Bench, MMLU, and GSM8K performance, whereas standard alternatives lose measurable ground. DRY has been adopted by popular open-source LLM inference frameworks including llama.cpp, ExLlamaV2, and text-generation-webui, highlighting its practical impact on text generation.
Figures & tables
| Method | SER@4 (95% CI) | SER@8 | D-4 | LFL |
|---|---|---|---|---|
| No intervention | 0.124 [.087, .160] | 0.069 | 0.958 | 100.1 |
| Repetition penalty | 0.083 [.061, .106] | 0.047 | 0.969 | 137.1 |
| Presence penalty | 0.112 [.077, .144] | 0.064 | 0.959 | 98.8 |
| Frequency penalty | 0.097 [.063, .126] | 0.056 | 0.967 | 134.5 |
| No-repeat n-gram ∗ | 0.043 [.029, .056] | 0.000 | 0.986 | 101.6 |
| Contrastive decoding | 0.145 [.137, .153] | 0.079 | 0.957 | 58.7 |
Appendix figures & tables19 assets
Supplementary material from the paper’s appendix.
Appendix
| Qwen 2.5-1.5B | Llama 3.2-3B | Qwen 2.5-7B | ||||
|---|---|---|---|---|---|---|
| Method | SER@4 | D-4 | SER@4 | D-4 | SER@4 | D-4 |
| No intervention | 0.057 | 0.974 | 0.167 | 0.947 | 0.147 | 0.953 |
| Repetition pen. | 0.045 | 0.977 | 0.093 | 0.970 | 0.112 | 0.961 |
| Presence pen. | 0.053 | 0.976 | 0.147 | 0.947 | 0.136 | 0.956 |
| Frequency pen. | 0.039 | 0.984 | 0.127 | 0.960 | 0.124 | 0.956 |
| No-repeat n-gram | 0.018 | 0.995 | 0.058 | 0.984 | 0.052 | 0.979 |
| Regime A | Regime B | |||
|---|---|---|---|---|
| Method | SER@4 | D-4 | SER@4 | D-4 |
| No intervention | 0.124 | 0.958 | 0.121 | 0.970 |
| DRY | 0.065 | 0.975 | 0.067 | 0.980 |
| Relative reduction | 47.4% | 44.6% | ||
| Seed 7 | Seed 42 | Seed 123 | Mean SD | |
|---|---|---|---|---|
| DRY SER@4 | 0.067 | 0.065 | 0.065 | 0.066 0.001 |
| Baseline SER@4 | 0.121 | 0.126 | 0.121 | 0.123 0.003 |
| Method | Hard/soft | Structure-aware | Typical failure mode |
|---|---|---|---|
| Repetition pen. | Soft | No | Suppresses common or structural tokens |
| Presence pen. | Soft | No | Discourages any reuse, even expected |
| Frequency pen. | Soft | No | Flattens high-frequency structural tokens |
| No-repeat n-gram | Hard | No | Blocks legitimate fixed phrases and templates |
| DRY | Soft | Yes (breakers) | Depends on breaker choice, exact loops only |
| Method | Target | Type | Key parameter(s) |
|---|---|---|---|
| No intervention | – | Reference | – |
| Repetition penalty | Token recurrence | Soft, multiplicative | penalty |
| Presence penalty | Token occurrence | Soft, additive | penalty |
| Frequency penalty | Token count | Soft, additive | penalty |
| No-repeat n-gram | N-gram recurrence | Hard blocking | |
| Contrastive decoding | Amateur–expert gap | Soft, model-based | , amateur model |
| Family | Count | Primary test |
|---|---|---|
| Stress dialogue | 40 | Multi-turn loop suppression |
| Long-context chat | 40 | Late-turn looping in long histories |
| Creative continuation | 40 | Loop suppression vs. style preservation |
| Structured formatting | 20 | Format token preservation |
| Necessary repetition | 20 | False-positive control (labels, refrains) |
| Exact copy / quotation | 20 | Copy fidelity under repetition control |
| Method | Settings |
|---|---|
| DRY | , , , default breakers, range = 1024 |
| Contrastive decoding | , , amateur = same family 1B |
| Repetition penalty | penalty (mean reported), range = 1024 |
| Presence penalty | penalty = 0.50, range = 1024 |
| Frequency penalty | penalty = 0.50, range = 1024 |
| No-repeat n-gram |
| Configuration | SER@4 | False Positive Penalty Rate | Structural MAUVE |
|---|---|---|---|
| No intervention | 0.120 | – | 1.00 ∗ |
| DRY (no breakers) | 0.041 | 28.4% | 0.61 |
| DRY (standard breakers) | 0.053 | 1.2% | 0.94 |
| Method | SER@4 (95% CI) | SER@8 | D-4 | LFL |
|---|---|---|---|---|
| No intervention | 0.130 [.123, .143] | 0.075 | 0.948 | 82.7 |
| Repetition penalty ‡ | 0.123 [.122, .124] | 0.064 | 0.963 | 109.6 |
| Presence penalty † | 0.125 [.106, .144] | 0.079 | 0.974 | 95.0 |
| Frequency penalty † | 0.106 [.098, .113] | 0.064 | 0.974 | 106.1 |
| No-repeat n-gram ∗ | 0.042 [.040, .043] | 0.000 | 0.981 | 83.0 |
| DRY (ours) | 0.079 [.069, .093] | 0.027 | 0.962 | 84.2 |
| Method | Context = 4K | Context = 32K | Context = 64K | Context = 128K |
|---|---|---|---|---|
| Forward pass (no intervention) | 10.45 ms/tok | 11.12 ms/tok | 11.95 ms/tok | 12.30 ms/tok |
| Repetition penalty ( logit pass) | +0.15 ms/tok | +0.22 ms/tok | +0.28 ms/tok | +0.41 ms/tok |
| DRY (reverse suffix match) | +0.04 ms/tok | +0.09 ms/tok | +0.18 ms/tok | +0.32 ms/tok |
| DRY relative overhead | 0.4% | 0.8% | 1.5% | 2.6% |
| Llama-3-70B-Instruct | GPT-OSS-120B | |||||
|---|---|---|---|---|---|---|
| Method | SER@4 | D-4 | MAUVE | SER@4 | D-4 | MAUVE |
| No intervention | 0.088 [.082, .095] | 0.942 | 1.00 ∗ | 0.076 [.071, .082] | 0.951 | 1.00 ∗ |
| Repetition penalty | 0.065 [.059, .070] | 0.948 | 0.79 | 0.058 [.051, .064] | 0.954 | 0.81 |
| Presence penalty | 0.079 [.071, .085] | 0.944 | 0.52 | 0.069 [.065, .073] | 0.952 | 0.58 |
| No-repeat n-gram | 0.035 [.033, .038] | 0.971 | 0.93 | 0.031 [.029, .033] | 0.975 | 0.94 |
| DRY (ours) | 0.042 [.038, .046] | 0.959 | 0.96 | 0.039 [.035, .042] | 0.966 | 0.97 |
| Method | MT-Bench | MMLU (gen, 5-shot) | GSM8k (0-shot CoT) |
|---|---|---|---|
| No intervention | 8.95 0.04 | 79.2% | 92.1% |
| Repetition penalty | 8.61 0.12 | 76.8% | 88.4% |
| No-repeat n-gram | 8.12 0.15 | 71.4% | 81.2% |
| DRY (ours) | 8.97 0.05 | 79.1% | 92.0% |
| Method | Qwen 2.5-1.5B | Llama 3.2-3B | Qwen 2.5-7B | Macro-avg |
|---|---|---|---|---|
| No intervention | 0.074 | 0.092 | 0.063 | 0.077 |
| Repetition penalty | 0.049 | 0.071 | 0.147 | 0.089 |
| Presence penalty | 0.052 | 0.107 | 0.098 | 0.086 |
| Frequency penalty | 0.020 | 0.113 | 0.053 | 0.062 |
| No-repeat n-gram | 0.053 | 0.094 | 0.057 | 0.068 |
| Placebo control | 0.086 | 0.070 | 0.099 | 0.085 |
| Configuration | SER@4 | D-4 | LFL |
|---|---|---|---|
| No intervention (regime A) | 0.106 | 0.959 | 100.2 |
| No interv. + temp 0.7 + top- 0.9 | 0.136 | 0.949 | 67.5 |
| DRY alone | 0.059 | 0.975 | 97.1 |
| DRY + temp 0.7 | 0.074 | 0.969 | 78.3 |
| DRY + top- 0.9 | 0.073 | 0.969 | 85.1 |
| DRY + temp 0.7 + top- 0.9 | 0.079 | 0.964 | 73.5 |