LoopCache: Accelerating Long-Context Self-Speculative Decoding for Looped Transformers
Zizhuo Fu, Haochen Huang, Shengxuan Qiu, Linye Wei, Ziyu Tang, Runsheng Wang, Meng Li
cs.CL, cs.LG
2026-11-18
LoopCache refines drafts by a logit gap and reads one loop KV per step. On six looped Transformers, 4K to 128K, it averages 5.12× AR, 10.25× WFD, and 14.56× LoopSpec.
A looped Transformer buys depth by running one shared block for R steps. Ouro loops the whole stack 4 times. Huginn and Raven loop an inner block 32 times, between a prelude and a coda that do not recur. Weights are shared. The KV cache is not: each loop stores its own keys and values, because the hidden state changes on every pass.
Autoregressive decoding waits until the current token finishes all R loops. Early loops already predict the next token, so they can draft for the full-depth model. Draft-then-Verify (DtV) writes the draft with shallow loops, then checks the batch with the remaining loops. The two phases never overlap. WaveFront Decoding (WFD) and LoopSpec put tokens that sit at different loops into one forward, a wavefront pipeline. On short contexts that means fewer steps, and a bad draft can be stopped earlier.
Long context spends that saving. Tokens in one step occupy different loops, so the step may read up to R full KV caches. Figure 4 is the result: WFD and LoopSpec use fewer global steps than autoregressive decoding and still move much more KV data. Stretch the context and the speedup falls. They often end up slower than plain autoregressive decoding. They also draft only at fixed loops. Intermediate loops change the prediction often enough that every later speculative token on the old path is computed and then thrown away at the last loop.
LoopCache, from Peking University, is self-speculative decoding for this setup. Drafts come from the model's own intermediate loops. There is no extra draft model to train.
Only one trajectory stays alive. Every loop can name a next token, but keeping every branch reaches 2^(R-1) states in the worst case. At 32 loops that does not fit. A replacement is harmful when the token just removed becomes the top prediction again on a later loop. Confidence is the logit gap Δz, how much this loop prefers the new candidate over the current draft in log probability. The draft changes only when Δz is at least τ, and speculative tokens hanging off the old draft are pruned. Figure 7 shows larger gaps reverse less often. The ablation sets τ to 0.125. With no threshold the draft flips back and forth, and chains that were already written get discarded.
KV reads rotate. Global step g opens only loop c = 1 + ((g-1) mod R), walking R1 through RR and wrapping. Every token in the step shares that one long prefix, so a full-prefix read drops from as many as R copies to one.
The spec branch keeps guessing and uses the scheduled KV even when its loop id does not match. Cross-loop KV states are similar enough for the approximation to still draft. The KV branch is what commits. It starts at the next complete cycle and recomputes the prefix in order, each loop on its own cache, producing the logits for greedy decoding and rejection sampling. Rejection sampling is what makes the accepted distribution match a full-depth run. A correct token id is not enough: hidden states written under the wrong KV cannot be reused. The lossless part is this recompute.
Shallow layers are the exception. Figure 5 shows large KV movement between neighboring loops in shallow layers, and much less deeper down. On the spec branch, the first two physical layers read the draft's own loop KV when the loop ids differ by at least 1. Other layers keep the shared cyclic cache. The extra traffic is two shallow reads. Verification always uses the real cache.
Six looped models are measured. Ouro-1.4B and Ouro-2.6B use 4 loops, with 6 GiB and 12 GiB of KV per loop at 32K. Huginn-3.5B uses 32 loops and 2.58 GiB per loop. Three Raven variants, built on Llama-3.2, OLMo-2, and TinyLlama, also use 32 loops, at 0.375, 1.50, and 0.25 GiB per loop. The hardware is eight A100s, with context parallelism on long sequences. Benchmarks are LongBench v1/v2, RULER, and LongReason, from 4K to 128K. Past the native window, YaRN extends the context.
Baselines are autoregressive decoding (AR), DtV, DFlash, WFD, and LoopSpec. DFlash is a separately trained block-diffusion drafter with block size 16, trained out to 128K.
| Baseline | Mean speedup | What it does |
| AR | 5.12× | Each token runs all R loops |
| DtV | 2.52× | Draft, then verify, in series |
| WFD | 10.25× | Wavefront at one fixed loop |
| LoopSpec | 14.56× | A proposal at each of two depths |
The 10.25× and 14.56× numbers are averages against WFD and LoopSpec. Both are often slower than AR once the context is long, so the ratio is inflated by a weak denominator. For a deployment, 5.12× against AR and 2.52× against DtV are the comparisons that count. LoopSpec also slows itself down: its second proposal grows fallback branches, and the paper cites peak effective batch sizes of 176 and 191 on LoopSpec's two Raven models.
Acceptance stays above the other methods at every length. The text never prints the percentages; they are only in Figure 9. Tokens per forward (TPF), committed tokens per global step, is high for the wavefront methods, but those steps read several loop caches. LoopCache reads one long prefix per step plus a few shallow-layer reads, and TPF stays high. Figure 10 does not label the AR-normalized multiples.
At 4K, with batch size from 1 to 32, wavefront speedups fall as the batch grows. LoopCache holds up better. The ablation starts from WFD and adds confidence updates, cyclic KV, and shallow decoupling one at a time. Each piece helps. All three together are best. Decoupling the first two layers costs little TPF and little extra time per step.
Looped models trade repeated passes for depth. A long KV cache then makes decoding bandwidth-bound. Wavefront decoding saves steps and gives the saving back as up to R times the cache traffic. LoopCache moves one full prefix per step, and still rewrites the draft when an intermediate loop is confident enough.
Older ways of sharing KV across loops also read less, and they change the model. Overwriting old slots, reusing the last loop or an average, or reusing the first loop as Mixture-of-Recursions does, all lose quality. Last-loop KV does not exist yet at prefill, so it cannot match training. LoopCache does not take that path. The verify path uses the real cache at every loop.
The practical fit is long-context decoding on Ouro, Huginn, or Raven. Bandwidth and discarded drafts go down. Capacity does not: all R caches stay resident. At 32K the per-loop footprint runs from 0.25 GiB to 12 GiB. The reported 5.12× is the paper's overall average across these models, benchmarks, and lengths. On short contexts and small batches the wavefront baselines are less disadvantaged, and the gap shrinks.
There is no limitations section. Losslessness is an argument from the KV-branch recompute plus rejection sampling. No table checks task scores or tokens against AR. A bug on that path would not show up in the numbers.
The 10.25× and 14.56× averages use denominators that are often slower than AR at long context, and the paper never breaks them out by model or length. Figure 8 is curves. There is also no average against DFlash. DFlash pays for a trained drafter, so without that number the cheaper system is not identified.
One τ and one shallow-layer choice are shared by every model. Figure 12 does not say which context lengths those ablations used. The batch sweep is explicitly at 4K. Four loops and 32 loops are far apart, and nothing shows that 0.125 is the best point for both.
At 32 loops, exact verification waits for the next matching cycle and then recomputes loops 1 through R. The paper reports throughput, not time to first token or per-token latency. Interactive decoding that cares about tail latency is not measured.
Traffic fell. Peak memory did not. Reaching 128K took eight GPUs and context parallelism. Whether the speedups survive on one GPU, or when the R KV caches are what runs out of memory first, is open.