OjaKV: Context-Aware Online Low-Rank KV Cache Compression

Fuente: arXiv
Guardado en:
Detalles Bibliográficos
Autores principales: Zhu, Yuxuan, Yang, David H., Amiri, Mohammad Mohammadi, Murugesan, Keerthiram, Pedapati, Tejaswini, Chen, Pin-Yu
Formato: Preprint
Publicado: 2025
Materias:
Acceso en línea:
Etiquetas: Agregar Etiqueta
Sin Etiquetas, Sea el primero en etiquetar este registro!
_version_ 1866911599651979264
author Zhu, Yuxuan
Yang, David H.
Amiri, Mohammad Mohammadi
Murugesan, Keerthiram
Pedapati, Tejaswini
Chen, Pin-Yu
author_facet Zhu, Yuxuan
Yang, David H.
Amiri, Mohammad Mohammadi
Murugesan, Keerthiram
Pedapati, Tejaswini
Chen, Pin-Yu
contents The expanding long-context capabilities of large language models are constrained by a significant memory bottleneck: the key-value (KV) cache required for autoregressive generation. This bottleneck is substantial; for instance, a Llama-3.1-8B model processing a 32K-token prompt at a batch size of 4 requires approximately 16GB for its KV cache, a size exceeding the model's weights. While KV-cache compression via low-rank projection is a promising direction, existing methods rely on a static, offline-learned subspace that performs poorly under data distribution shifts. To overcome these limitations, we introduce OjaKV, a novel framework that integrates a strategic hybrid storage policy with online subspace adaptation. First, OjaKV recognizes that not all tokens are equally important for compression; it preserves the crucial first and most recent tokens in full-rank, maintaining high-fidelity anchors for attention. Second, for the vast majority of intermediate tokens, it applies low-rank compression by incrementally adapting the projection basis using Oja's algorithm for online principal component analysis. This adaptation involves a comprehensive update during prompt prefilling and lightweight periodic updates during decoding, ensuring the subspace remains aligned with the evolving context. Crucially, our framework is fully compatible with modern attention modules like FlashAttention. Experiments demonstrate that OjaKV maintains or even improves zero-shot accuracy at high compression ratios. In particular, OjaKV achieves its strongest gains on very long-context benchmarks that require complex reasoning, highlighting the importance of online subspace adaptation in dynamically tracking context shifts. These results establish our hybrid framework as a practical, plug-and-play solution for memory-efficient long-context inference without requiring model fine-tuning.
format Preprint
id arxiv_https___arxiv_org_abs_2509_21623
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle OjaKV: Context-Aware Online Low-Rank KV Cache Compression
Zhu, Yuxuan
Yang, David H.
Amiri, Mohammad Mohammadi
Murugesan, Keerthiram
Pedapati, Tejaswini
Chen, Pin-Yu
Computation and Language
Artificial Intelligence
Machine Learning
The expanding long-context capabilities of large language models are constrained by a significant memory bottleneck: the key-value (KV) cache required for autoregressive generation. This bottleneck is substantial; for instance, a Llama-3.1-8B model processing a 32K-token prompt at a batch size of 4 requires approximately 16GB for its KV cache, a size exceeding the model's weights. While KV-cache compression via low-rank projection is a promising direction, existing methods rely on a static, offline-learned subspace that performs poorly under data distribution shifts. To overcome these limitations, we introduce OjaKV, a novel framework that integrates a strategic hybrid storage policy with online subspace adaptation. First, OjaKV recognizes that not all tokens are equally important for compression; it preserves the crucial first and most recent tokens in full-rank, maintaining high-fidelity anchors for attention. Second, for the vast majority of intermediate tokens, it applies low-rank compression by incrementally adapting the projection basis using Oja's algorithm for online principal component analysis. This adaptation involves a comprehensive update during prompt prefilling and lightweight periodic updates during decoding, ensuring the subspace remains aligned with the evolving context. Crucially, our framework is fully compatible with modern attention modules like FlashAttention. Experiments demonstrate that OjaKV maintains or even improves zero-shot accuracy at high compression ratios. In particular, OjaKV achieves its strongest gains on very long-context benchmarks that require complex reasoning, highlighting the importance of online subspace adaptation in dynamically tracking context shifts. These results establish our hybrid framework as a practical, plug-and-play solution for memory-efficient long-context inference without requiring model fine-tuning.
title OjaKV: Context-Aware Online Low-Rank KV Cache Compression
topic Computation and Language
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2509.21623