FOLD: Position-Free Far Memory with Local Order for Long-Context Speculative Decoding
Organizations: Sun Yat-sen University · Canva Research · Peking University
Abstract
Speculative decoding accelerates LLM generation through lightweight drafting and parallel verification. It is particularly promising for long inputs, where KV-cache access costs can be amortized over multiple accepted tokens. Yet most drafters are trained on short sequences and degrade on long inputs, while long-context training is costly. Existing training-free approaches restrict the context window, rescale positions, or augment recent context with retrieved distant entries. Drafters, however, read target hidden states that already encode contextual and positional information, and their lightweight architecture makes full-history attention affordable. We propose FOLD, a training-free method that preserves exact local positions and treats all distant entries as far memory at a shared position. To counter attention dilution as the memory grows, we sharpen attention within it to emphasize relevant entries while separately controlling its total weight relative to the local window. Across six target-drafter pairs and diverse benchmarks of up to 256K tokens, FOLD predominantly delivers the highest speedup, with the best case more than doubling the speedup over autoregressive decoding, from 2.08 to 4.22.
Figures & tables
| Target | Drafter | Attention layers | Train | ||
|---|---|---|---|---|---|
| Llama-3.1-8B | DFlash | 10 | 5 full | 3K | 2,048 |
| Qwen3.5-9B | DFlash | 16 | 5 SW (4K) + 1 full | 40K | 4,096 |
| Gemma-4-12B | DFlash, DSpark | 7 | 5 full, partial RoPE | 4K | 4,096 |
| Qwen3-8B | DFlash, DSpark | 7 | 5 full | 4K | 2,048 |
| Method | Gov | LBv2 | Retr.KV | En. | LCA | RepoBench | SWE-bench | Avg. | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Spd. | Spd. | Spd. | Spd. | Spd. | Spd. | Spd. | Spd. | |||||||||
| Llama-3.1-8B | ||||||||||||||||
| DFlash | 2.49 | 2.35 | 2.88 | 2.62 | 1.35 | 1.24 | 1.77 | 1.64 | 2.75 | 2.53 | 2.87 | 2.68 | 1.86 | 1.74 | 2.28 | 2.11 |
| StreamingLLM | 2.88 | 2.71 | 3.88 | 3.57 | 1.79 | 1.69 | 2.70 | 2.57 | 4.06 | 3.79 | 4.07 | 3.79 | 2.36 | 2.22 | 3.11 | 2.91 |
| YaRN | 3.49 | 3.18 | 3.87 | 2.91 | 1.66 | 1.12 | 2.65 | 1.87 | 4.01 | 3.03 | 3.94 | 3.22 | 3.02 | 2.42 | 3.23 | 2.54 |
| CMR | 3.39 | 2.58 | 4.05 | 2.98 | 1.76 | 1.44 | 2.87 | 2.36 | 4.34 | 3.41 | 4.19 | 3.22 | 2.82 | 2.21 | 3.35 | 2.60 |
| Method | Qwen3-8B | Gemma-4-12B | ||||
|---|---|---|---|---|---|---|
| General | General | Code | ||||
| Spd. | Spd. | Spd. | ||||
| DSpark | 4.02 | 3.41 | 3.03 | 2.62 | 3.68 | 3.22 |
| StreamingLLM | 4.19 | 3.54 | 2.68 | 2.33 | 3.54 | 3.13 |
| YaRN | 4.27 | 3.32 | 3.21 | 2.45 | 3.72 | 3.03 |
| CMR | 4.25 | 2.91 | 2.94 | 2.25 | 3.79 | 3.00 |
| DFlash Window | Window FOLD | |||||
|---|---|---|---|---|---|---|
| 32K | 64K | 122K | 32K | 64K | 122K | |
| Llama | ||||||
| Qwen3.5 | ||||||
| Gemma | ||||||
| Model | Tasks | vs. 1 | vs. 2 | |
|---|---|---|---|---|
| Llama | General | 3.17 | 1.150 [1.137, 1.162] | 1.018 † [1.014, 1.022] |
| Code | 4.52 | 1.067 [1.064, 1.072] | 0.992 [0.991, 0.994] | |
| Qwen3 | General | 3.26 | 1.160 [1.138, 1.183] | 1.012 † [1.006, 1.019] |
| Qwen3.5 | General | 3.59 | 2.793 [2.743, 2.845] | 1.146 [1.133, 1.159] |
| Code | 6.86 | 4.173 [4.068, 4.285] | 1.001 [1.000, 1.003] | |
| Gemma | General | 2.88 | 1.071 [1.066, 1.077] | 1.001 † [0.998, 1.004] |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Target | Drafter checkpoint |
|---|---|
| NousResearch/Meta-Llama-3.1-8B-Instruct | z-lab/LLaMA3.1-8B-Instruct-DFlash-UltraChat |
| Qwen/Qwen3.5-9B | z-lab/Qwen3.5-9B-DFlash |
| google/gemma-4-12B-it | deepseek-ai/dflash_gemma4_12b_block7 |
| google/gemma-4-12B-it | deepseek-ai/dspark_gemma4_12b_block7 |
| Qwen/Qwen3-8B | deepseek-ai/dflash_qwen3_8b_block7 |
| Qwen/Qwen3-8B | deepseek-ai/dspark_qwen3_8b_block7 |
| Llama-3.1-8B | Qwen3.5-9B | Gemma-4-12B | |||||
| Task | Gen. limit | Input length | Input length | Input length | |||
| Gov | 512 | 284 | 1.8K–27K | 275 | 1.1K–28K | 275 | 1.1K–28K |
| LBv2 | 128 | 320 | 9.8K–128K | 379 | 10K–253K | 378 | 10K–250K |
| Retr.KV | 128 | 488 | 121K–122K | 478 | 165K–166K | 478 | 170K–170K |
| En.Sum | 1200 | 48 | 65K–125K | 72 | 66K–235K | 72 | 66K–240K |
| En.QA | 512 | 112 | 64K–128K † | 281 | 64K–256K † | 281 | 64K–256K † |
| Method | 8K | 16K | 32K | |||
|---|---|---|---|---|---|---|
| Spd. | Spd. | Spd. | ||||
| Llama-3.1-8B | ||||||
| DFlash | 3.02 | 2.84 | 2.69 | 2.52 | 2.21 | 2.07 |
| StreamingLLM | 3.50 | 3.27 | 3.18 | 2.99 | 2.89 | 2.72 |
| YaRN | 4.07 | 3.70 | 3.62 | 3.17 | 3.34 | 2.74 |
| CMR | 3.87 | 2.92 | 3.70 | 2.82 | 3.33 | 2.57 |
| Method | Gov | LBv2 | ||
|---|---|---|---|---|
| Spd. | Spd. | |||
| DFlash | 2.68 | 2.52 | 4.08 | 3.58 |
| StreamingLLM | 2.55 | 2.38 | 5.28 | 4.59 |
| YaRN | 2.84 | 2.58 | 5.36 | 4.26 |
| CMR | 2.77 | 2.12 | 5.33 | 3.71 |
| ReRoPE | 2.80 | 2.60 | 4.32 | 3.72 |
| All 1,531 requests | Common set (1,437) | ||||
|---|---|---|---|---|---|
| Method | Speedup | Diff. (AR) | Speedup | ||
| DFlash | 1.96 | 1.54 | 83 | 1.97 | 1.55 |
| SGLang window | 2.70 | 2.18 | 82 | 2.70 | 2.18 |
| StreamingLLM | 2.74 | 2.11 | 84 | 2.75 | 2.11 |
| CMR | 2.93 | 2.16 | 82 | 2.93 | 2.16 |
| ReRoPE | 3.21 | 2.46 | 79 | 3.22 | 2.47 |
| Bucket | DFlash Window | Window FOLD | |||
|---|---|---|---|---|---|
| Llama-3.1-8B | |||||
| 8–16K | 28 | 2.63 | 4.07 | +0.57 [+0.36, +0.79] | +0.87 [+0.52, +1.25] |
| 16–32K | 90 | 2.85 | 3.99 | +0.66 [+0.54, +0.78] | +0.48 [+0.32, +0.64] |
| 32–64K | 72 | 3.12 | 4.44 | +1.09 [+0.91, +1.28] | +0.23 [+0.06, +0.43] |
| 64–128K | 130 | 2.83 | 4.18 | +1.34 [+1.16, +1.52] | +0.01 [-0.08, +0.09] |
| Qwen3-8B | |||||
| Model | Tasks | vs. 1 | vs. 2 | ||
|---|---|---|---|---|---|
| Llama | Natural | 1137 | 3.15 | 1.174 [1.158, 1.191] | 1.027 † [1.022, 1.032] |
| SPEED | 1816 | 4.24 | 1.039 [1.036, 1.043] | 0.991 [0.989, 0.992] | |
| QA/MC/Dia | 391 | 3.22 | 1.078 [1.070, 1.086] | 0.993 [0.991, 0.996] | |
| Qwen3 | Natural | 359 | 3.26 | 1.160 [1.138, 1.183] | 1.012 † [1.006, 1.019] |
| SPEED | 1150 | 3.51 | 1.194 [1.185, 1.203] | 1.012 [1.010, 1.014] | |
| Qwen3.5 | Natural | 1138 | 3.75 | 2.709 [2.632, 2.787] | 1.217 [1.198, 1.236] |
Speculative Decoding
Speculative decoding accelerates generation by drafting multiple tokens and verifying them in parallel with a larger target model.
See all 291 papers