The quest for extended context windows in large language models has historically demanded significant computational resources or architectural modifications. A recent arXiv preprint introduces KV-Fold, a novel, training-free approach to long-context inference that ingeniously repurposes the key-value (KV) cache.
Stable Recurrence via Functional Folding
KV-Fold treats the KV cache as an accumulator in a left fold operation across sequence chunks. At each step, the model processes a new chunk, conditioned on the accumulated cache from previous chunks. This cache is then appended with the newly generated keys and values, and the enlarged cache is passed forward. This simple, one-step update mirrors the behavior of `foldl` in functional programming, establishing a stable, chunk-to-chunk recurrence. The researchers observed that per-step drift quickly saturates and remains stable, demonstrating robustness across numerical precision, chunk sizes, and model families.