Skip to content
AI.info

Research

Efficient Low Rank Attention for Long-Context Inference in Large Language Models

Overview Research area: Efficient inference for large language models (LLMs), specifically long-context decoding and key-value (KV) cache memory management. Technical level: Advanced. The paper relies

arXiv
2510.23649
Published
2025-10-25
Authors
Tenghui Li, Guoxu Zhou, Xuyang Zhao, Yuning Qiu, Qibin Zhao

AI summary

Overview

Research area: Efficient inference for large language models (LLMs), specifically long-context decoding and key-value (KV) cache memory management.

Technical level: Advanced. The paper relies on matrix factorization, constrained Lagrangian optimization, block coordinate descent, singular value decomposition, and GPU/CPU cache hierarchy management.

Scope: The paper introduces LRQK (Low Rank Query and Key attention), a two-stage prefill-and-decode framework that jointly low-rank-approximates query and key matrices to select the most relevant tokens, then computes attention exactly over only those retrieved full-precision KV pairs using a mixed GPU-CPU cache.

What This Paper Is About

As input text grows longer, the KV cache that decoder-only LLMs keep in GPU memory grows linearly with sequence length and becomes the system bottleneck for long-context inference, especially on resource-constrained hardware. Existing fixes — quantization, pruning/eviction, and CPU offloading — each trade away numerical precision, risk discarding later-critical key-value pairs, or add PCIe transfer latency. LRQK's goal is to select the right KV pairs cheaply using a low-rank proxy score, retrieve only those exact full-precision pairs, and thereby keep attention outputs exact while cutting memory use and CPU-GPU data movement.

Key Contributions

  1. Joint low-rank approximation of Q and K. Instead of running costly SVD on pre-RoPE keys as ShadowKV does, the method jointly optimizes low-rank approximations of both the query and key matrices, reducing computational complexity while maintaining representation accuracy.
  2. Precision-preserving attention computation. The low-rank approximated keys and values serve only as proxies for lightweight attention-score estimation; the subsequent attention operations use the original query, key, and value vectors with no approximation or reconstruction, preserving mathematical fidelity.
  3. Mixed cache management. A hybrid GPU-CPU storage system is implemented with active-token retention, a hit/miss buffer architecture that transfers only missing tokens, and a dedicated recency buffer holding recently accessed keys and values that empirical analysis shows consistently receive high attention scores.
  4. Empirical validation on long-context benchmarks. Experiments on RULER and LongBench with LLaMA-3-8B and Qwen2.5-7B show the method matching or surpassing leading sparse-attention baselines with minimal accuracy loss.

Main Findings

  • Low-rank structure is real and measurable. Figure 3 plots the average singular-value spectrum of per-head query and key matrices for Qwen2.5-7B and LLaMA-3-8B-1M on the Wikitext-2-v1 test set; in both models singular values decay rapidly beyond a small rank, confirming a low-rank approximation loses little. The paper states rank(QKᵀ) ≤ min(rank(Q), rank(Kᵀ)) = min(rank(Q), rank(K)).

  • Attention has a strong recency bias. On the same Wikitext-2-v1 test set with Qwen2.5-7B and LLaMA-3-8B-1M, per-head attention scores (averaged over batches and attention heads, window size 16) are consistently higher for the current token and its near neighbors. This motivates the fixed "lite token" recency buffer.

  • RULER at 128K (LLaMA-3-8B-1M, r=32, top-k=2048, 64 lite tokens). The proposed method scores 81.00 on S1, 100.00 on S2, 97.00 on MK1, 42.00 on MK2, 99.25 on MQ, 98.00 on MV, 75.00 on QA-1 (QA SQuAD), and 53.00 on QA-2 (QA HotpotQA). It matches ShadowKV and Quest on S2 and outperforms all baselines on QA-1 and QA-2. On MQ and MV it exceeds even the original LLaMA-3-8B-1M model (98.96 and 95.57 respectively).

  • LongBench results. The method leads all methods on PRetr (Passage Retrieval) with 89.00 and LCC with 66.13. It is lower than the leading baselines on MK2 (42.00 versus ShadowKV's 98.96) and NQA (16.52 versus Quest's 20.13), and lower than the unmodified LLaMA-3-8B-1M on GRep (20.40 versus 34.18) and SAM (26.35 versus 35.96).

  • Cross-model consistency on a RULER-4K subset (r=16, top-k=256 which is 6.25% of 4K, 16 lite tokens). LLaMA-3-8B-1M goes from 82.00/58.00/99.00 (QA-1/QA-2/VT) to 84.00/57.00/98.80 with LRQK; Qwen2.5-7B goes from 90.00/64.00/99.20 to 91.00/65.00/96.60.

  • Rank matters for some tasks, not uniformly. With top-k fixed at 256 and 16 lite tokens on the RULER-4K subset: r=8 gives 79.00/50.00/56.80; r=16 gives 80.00/60.00/98.80; r=24 gives 83.00/56.00/98.80; r=32 gives 84.00/57.00/99.00. QA-1 and VT generally improve with higher rank (r=32 surpasses the original LLaMA-3-8B-1M on QA-1), while QA-2 is best at the lower rank r=16.

  • Larger top-k improves accuracy. With r=8 and 16 lite tokens: top-256 gives 79.00/50.00/56.80; top-512 gives 78.00/61.00/95.60; top-1024 gives 83.00/63.00/100.00.

  • Cache miss behavior. In a summarization experiment on the wikitext-2-v1 test set, grid-searching r ∈ {8, 16, 32, 64}, active tokens ∈ {128, 256, 512}, and lite tokens ∈ {4, 8}, the miss rate (c_miss / c_total) distribution in Figure 5 is approximately Gaussian-ish in shape with a mean miss rate of around 0.40 and a standard deviation of approximately 0.10.

  • Not reported in the provided content. Concrete memory-saving figures, wall-clock throughput or latency numbers, the Appendix B/C/D results (additional results, time cost analysis, hyperparameter tuning guideline), and the exact experimental hardware count are referenced but not included in the text supplied.

Methodology in Plain English

The method splits inference into two phases.

Prefill. Given the long prompt, the model produces query, key, and value matrices. The authors argue the full query-key interaction matrix (QKᵀ) is well approximated by a product of two much narrower matrices, A_Q and A_K, each with rank r much smaller than the head dimension d. They simultaneously require that Q ≈ A_Q B_Q and K ≈ A_K B_K so that the same factors also compress the query and key themselves. This constrained objective is relaxed into a Lagrangian with two scaling factors and solved by alternately updating A_Q, A_K, B_Q, and B_K (Algorithm 1) — a block coordinate descent scheme. The matrix inverses involved are only r-by-r, so they are cheap (O(r³)); by reordering the multiplications (for example computing Q(KᵀA_K) instead of (QKᵀ)A_K) the cost drops from O(l²d) to O(rld). A_Q and A_K are initialized from a standard normal distribution.

Decode. For each new token, the current query and key are compressed into vectors of dimension r (q̂_t and k̂_t) by solving another Lagrangian that penalizes reconstruction error while constraining the rank-r inner products to match the true ones. Update rules for q̂_t and k̂_t are closed form; B_Q and B_K are updated by a single gradient-descent step with step sizes computed in closed form (Equations 11 and 12). To avoid arbitrary initialization, k̂_t is first guessed by setting λ_d1 = 0. Using the compressed representations, the method computes a proxy attention score over the cached keys in O(lr) time and selects the top-k tokens, plus a small fixed set of recent "lite" tokens.

Cache management. The GPU cache holds these active tokens plus the lite tokens. The full-precision KV cache lives in CPU memory. Each decode step, only the selected tokens missing from the GPU cache are fetched from CPU (a cache miss); already-present tokens need no transfer (a cache hit). The fetched tokens are merged with the GPU cache, and the current token's key and value are written back to CPU asynchronously. Attention is then computed exactly using the original q_t with the retrieved K and V.

Experimental setup. Experiments run on NVIDIA A100 GPUs. The maximum iteration count is 2, the tolerance is 0.01, and all scaling parameters are set to 1. Evaluations use OpenCompass.

Why This Matters

Impact on research. The paper sharpens a distinction that much of the KV-cache literature blurs: using an approximation for selection is different from using an approximation for computation. LRQK uses compressed query/key representations only to decide which tokens to look at, then computes attention over the original full-precision vectors. It also argues against the SVD-on-keys approach of InfiniGen and ShadowKV on both cost and fidelity grounds, and replaces the expensive eviction heuristic with a retrieval-plus-hit/miss scheme. This gives the sparse-attention and efficient-inference communities a concrete alternative design point and a reproducible baseline (code is released at github.com/tenghuilee/LRQK).

Real-world applications.

  • Long-document question answering and summarization on single-GPU or memory-limited servers, where a 128K-token context would otherwise not fit.
  • Retrieval-augmented generation pipelines that stuff large retrieved contexts into the prompt, where reducing CPU-GPU KV transfer directly affects user-perceived latency.
  • On-device or edge assistants that must run long conversational histories within tight memory budgets.
  • Enterprise document-analysis and compliance tools that process book-length or contract-length inputs and cannot tolerate approximation error in the attention output.

Industry relevance. Decoder-only LLMs are increasingly sold on context window length, and serving cost is dominated by KV cache memory and the PCIe traffic of offloading. A method that cuts both memory footprint and CPU-GPU data movement while keeping attention mathematically exact is directly relevant to inference-serving vendors, cloud providers pricing long-context APIs, and hardware teams designing memory hierarchies for accelerators.

Future Directions

  1. Quantify the actual savings. The abstract claims "significant memory savings," but the provided content reports accuracy and miss rates only; explicit memory-footprint and latency/throughput comparisons against each baseline (the Appendix C time-cost analysis) are the natural next thing to establish.
  2. Fix the weak spots. MK2 (42.00 versus ShadowKV's 98.96), GRep (20.40), and SAM (26.35) lag the baselines, so understanding why multi-key retrieval and gathering tasks degrade — and whether rank, top-k, or the recency buffer is responsible — is an open question.
  3. Tune the trade-off automatically. The paper shows rank and top-k interact differently per task (QA-2 prefers r=16 while QA-1 prefers r=32), which suggests adaptive per-task or per-head budgets rather than a single global configuration. The authors flag Appendix D as a hyperparameter-tuning guideline, which points in this direction.
  4. Tighten the miss-rate distribution. With a mean miss rate around 0.40 and standard deviation around 0.10, roughly two-fifths of selected rows still cross the PCIe bus per step. Better recency/active-buffer policies, or prefetching based on the proxy scores, could push this lower.

Target Audience

This paper is written for researchers and engineers working on efficient LLM inference: sparse and dynamic attention, KV cache compression and offloading, and long-context serving systems. It is also relevant to practitioners deploying 7B–8B class models (LLaMA-3-8B, Qwen2.5-7B) under GPU memory constraints who can afford to implement a custom attention kernel and cache manager. Readers without a background in matrix factorization, Lagrangian optimization, or cache architecture will find the mathematical sections demanding; the experimental tables, however, are readable on their own and are the fastest way to judge whether the method suits a given workload.

Authors’ abstract

As the length of input text increases, the key-value (KV) cache in LLMs imposes prohibitive GPU memory costs and limits long-context inference on resource constrained devices. Existing approaches, such as KV quantization and pruning, reduce memory usage but suffer from numerical precision loss or suboptimal retention of key-value pairs. In this work, Low Rank Query and Key attention (LRQK) is introduced, a two-stage framework that jointly decomposes full-precision query and key matrices into compact rank-\(r\) factors during the prefill stage, and then employs these low-dimensional projections to compute proxy attention scores in \(\mathcal{O}(lr)\) time at each decode step. By selecting only the top-\(k\) tokens and a small fixed set of recent tokens, LRQK employs a mixed GPU-CPU cache with a hit-and-miss mechanism where only missing full-precision KV pairs are transferred, thereby preserving exact attention outputs while reducing CPU-GPU data movement. Extensive experiments on the RULER and LongBench benchmarks with LLaMA-3-8B and Qwen2.5-7B demonstrate that LRQK matches or surpasses leading sparse-attention methods in long context settings, while delivering significant memory savings with minimal accuracy loss. Our code is available at https://github.com/tenghuilee/LRQK.

Read the original paper