TL;DR
LastKV pushes cross-layer Key-Value (KV) cache sharing to its logical limit by storing only the final layer's KV cache for older history. By organizing sequences into chunks, it slashes older-history KV memory requirements by up to $L$-fold while preserving standard parallel training and maintaining or improving performance across text, video, and 3D modalities.
What Problem Does This Paper Address?
As Large Language Models (LLMs) and diffusion models handle increasingly long contexts, they hit a massive "memory wall." The Transformer's Key-Value (KV) cache grows along two axes simultaneously: sequence length and network depth. Every single layer must store its own keys and values for every token processed.
While many existing solutions compress the token axis (via eviction or pooling), compressing the layer axis (cross-layer sharing) remains challenging. Prior attempts at cross-layer sharing either only work with modest sharing factors among adjacent layers, or they break exact parallel training—requiring complex iterative approximations or entirely new model architectures to handle the causal dependencies.
Methods
The authors introduce LastKV, a chunk-based design that separates local computation from long-range memory without altering the core Transformer block architecture.
- Chunked Processing: The input sequence is partitioned into chunks of size $C$ (e.g., 4096 tokens). Inside the current chunk, the model operates exactly like a standard Transformer with full intra-chunk parallelism and per-layer KV caches.
- Last-Layer Writing: Only when a chunk completely finishes processing does it commit its last layer's KV cache to persistent long-range memory. The KV caches for the other $L-1$ layers of that chunk are discarded.
- Cross-Chunk Sharing: For all future chunks, every single layer reads from this single, shared last-layer cache using ordinary attention.
- Nearest-Chunk KV Refinement: To smooth out discontinuities at chunk boundaries, LastKV optionally retains the full per-layer caches for just the immediately preceding chunk, $\alpha$-blending them with the last-layer cache.
Datasets
The approach was validated across three distinct modalities:
- Language Modeling: Pretrained from scratch (141M to 3.26B parameters) and continued pretraining of an 8B model (Marin 8B) on Long-Data-Collections. Evaluated using Books3 for validation loss and RULER for long-context retrieval.
- Autoregressive Video Generation: Fine-tuned Wan 2.1 (1.3B and 14B) text-to-video models on VidProM captions, evaluated using the official VBench protocol.
- Novel View Synthesis (3D): Trained on Objaverse and filtered DL3DV-10K, and evaluated on the Google Scanned Objects (GSO) split.
Key Insights and Ideas
- Chunk Boundaries Enable Parallelism: Deferring the cache-sharing mechanism to chunk boundaries completely bypasses the causal dependency trap. Because no layer waits on the last-layer output of its own chunk, training requires no iterative approximations and uses standard backpropagation.
- Upward Sharing is Superior: Prior cross-layer sharing methods typically share "downward" (lower layers dictating what upper layers see). LastKV demonstrates that sharing "upward"—where all layers look back at the deepest, most highly processed summary (the last layer)—yields significantly better context retrieval.
- An Effective Inductive Bias: Surprisingly, in Novel View Synthesis, forcing every layer to read from a single deep summary of past views actually outperformed the full-cache baseline. The compact memory acts as a beneficial inductive bias for cross-view correspondence.
Key Results
- 8B Scale Parity: Through continued pretraining over 120B tokens, the authors successfully converted a standard 8B Transformer into a LastKV model. Retaining just 1 out of 32 KV layers for older history, it performed within 0.6 points of the full-cache baseline across 12 standard benchmarks (including MMLU, GSM8K, and BBH).
- Maintained Training Efficiency: When using an optimized chunk-loop implementation with a chunk size of 1024, LastKV recovers 95.6% of the full-cache baseline's training throughput, proving that memory savings do not have to come at the cost of training speed.
- Modality Performance: LastKV consistently achieved lower per-token validation loss on Books3, stayed highly competitive on RULER retrieval tasks, and improved mean evaluation PSNR from 25.38 to 25.95 dB on object-level 3D reconstruction.
Limitations and Future Work
While LastKV demonstrates impressive memory reductions, the authors acknowledge several limitations:
- No End-to-End Serving Benchmarks: The paper lacks hardware-level inference benchmarks (e.g., decode latency, tokens/sec) on optimized serving stacks like vLLM or TensorRT-LLM.
- Lack of Direct Cross-Method Comparisons: LastKV was compared strictly against full-cache baselines rather than head-to-head against other layer-sharing methods like YOCO or CLA due to differences in chunking and positional embedding setups.
- Unexplored Curricula: Future work remains to explore training curricula, such as pretraining with large chunk sizes and fine-tuning on smaller ones, or combining LastKV with token-axis eviction policies.
Summary updated