LoopGuard: Breaking Self-Reinforcing Attention Loops via Dynamic KV Cache Intervention
Organizations: Soochow University · Tongji University · The Hong Kong University of Science and Technology · Alibaba Group ·
Abstract
Through systematic experiments on long-context generation, we observe a damaging failure mode in which decoding can collapse into persistent repetition loops. We find that this degeneration is driven by collapsed attention patterns, where a subset of heads locks onto a narrow suffix of the history, and is further stabilized by inference-time KV cache reuse. Crucially, since many existing KV cache policies rely on attention-based importance, this collapse can produce spuriously high scores for repetitive tokens, causing cache management to inadvertently amplify repetition. To study this phenomenon in a controlled and reproducible manner, we introduce LoopBench, a benchmark with explicit loop-inducing conditions and loop-oriented metrics that quantify repetition severity and generation instability beyond downstream task scores. Building on these insights, we propose LoopGuard, a lightweight, plug-in KV cache guard that detects loop onset online and disrupts the feedback cycle by pruning repetitive tail spans under a fixed cache budget. Experiments on LoopBench show that LoopGuard reduces loop incidence by over 90 percentage points, while restoring output diversity and reducing token waste.
Figures & tables
| Dataset | Model | Method | CR | TTR | Avg Len | Loop Rate |
|---|---|---|---|---|---|---|
| LoopBench-DC | Qwen3-1.7B | Full Cache | 0.064 | 0.086 | 2495 | 100% |
| StreamingLLM | 0.085 | 0.118 | 2496 | 100% | ||
| H 2 O | 0.052 | 0.079 | 2495 | 100% | ||
| LoopGuard (Ours) | 0.219 | 0.528 | 1326 | 1.3% | ||
| Llama3.2-1B | Full Cache | 0.044 | 0.065 | 2498 | 100% | |
| StreamingLLM | 0.058 | 0.087 | 2498 | 100% |
| Method | F1 |
|---|---|
| Full Cache | 50.49 |
| StreamingLLM | 21.05 |
| H 2 O | 33.73 |
| LoopGuard (Ours) | 53.61 |
| Variant | Loop Rate (%) | Avg. #Int. | Early (%) |
|---|---|---|---|
| No Guard | 100.0 | 0.00 | – |
| Always-on Pruning | 79.8 | 12.5 | 57.6 |
| Single-signal ( ) | 35.4 | 7.6 | 21.2 |
| Full LoopGuard | 1.3 | 4.8 | 1.7 |
Appendix figures & tables1 asset
Supplementary material from the paper’s appendix.