Loki: Low-rank Keys for Efficient Sparse Attention

Inference on large language models (LLMs) can be expensive in terms of the compute and memory costs involved, especially when long sequence lengths are used. In particular, the self-attention mechanism used in LLM inference contributes significantly to these costs, which has sparked an interest in approximating the self-attention computation to reduce such costs. In this work, we propose to approximate self-attention by focusing on the dimensionality of key vectors computed in the attention block. Our analysis reveals that key vectors lie in a significantly lower-dimensional space, consistently across several datasets and models. Exploiting this observation, we propose Loki, a novel sparse attention method that ranks and selects tokens in the KV-cache based on attention scores computed in low-dimensional space. Our evaluations show that Loki is able to speed up the attention computation due to reduced data movement (load/store) and compute costs while maintaining the efficacy of the models better than other popular approximation methods.

Paper

Similar papers

Peer review

Reviewer dYWK8/10 · confidence 5/52024-07-03

Summary

This method propose the PCA based attention score approximation for top-k attention. Perform PCA on offline dataset, and store the PCA vectors for inference.

Strengths

This work easily makes a QK approximator without gradient-based training but with only simple PCA for top-k attention selection.

Weaknesses

You have to store the PCA vectors and perform the projection of KV during attention. This projection matrix should be holded on threadblock in GPU, to minimize the GPU memory access. But this matrix might be huge if the hidden size of QKV is large. But untill now, most of LLM using less than $256$, therefore, should be fine. (NOTE: I need to checkout the implementation whether this is correct or not)

Questions

1. The .gz file seems broken. Can you upload the file in other format again? I want to look into source codes, for details. 2. Fig. 1. might leads mis understand that this attention mechnism using low rank PCA attention only. Can you add that this method perform top-k operation on top of approximated scores in the figure using diagram? (I think text only is not sufficient) 3. Top-k operation is usually very slow in GPU, due to synchronization and information exchange of top-k values via global-memory. I think per-kernel latency breakdown should be presented on this paper. (Fig. 6 only shows the single sequnce length in left.) 4. Some figures are not sized properly. (e.g. Fig. 6.) Can you adjust the size of figures to avoid stretching the texts? 5. I think there should be some plot that show latency-performance trade-off (ms - accuracy) Can you add this plot using some downstream tasks? 6. Fig.4, they evaluate downstream tasks, but every task is quite short sequence length. Can you try LongBench (https://github.com/THUDM/LongBench)? Question 5 should be solved using LongBench rather than short sequence tasks. I have concern about performance evalution. The only metic used is Perplexity, HellaSwag, TQA, Winogrande, ARC, MMLU, which is relatively short sequence compared to long context LLM such as Qwen2 and Phi3. I suggest to add evaluation on long context.

Rating

8

Confidence

5

Soundness

4

Presentation

4

Contribution

4

Limitations

PCA should be performed during train stage, and PCA projection required for top-k attention selection. This may leads additional effort to optimize the GPU kernels in many scale, and sometimes impossible if the device cannot hold PCA projection matrix in shared memory.

Reviewer dYWK2024-08-06

I fixed the .gz

I found out that the `tar.gz` file seems forced to be renamed `.gz` in OpenReview. Don't worry about my question 1, it is resolved by myself right now... If possible, I will look into it during the discussion period. Thank you for your great work, and sorry for my mistake.

Reviewer dYWK2024-08-11

Thank you for the detailed and kindly described rebuttal. Sorry for my late reply. I am happy that most of my concerns are resolved, and I want to increase the rating. I am pretty confident that this paper is an acceptable grade. I hope other reviewers will respond soon. - I briefly looked into triton codes, and they are simple and worth understanding for further researchers. I hope the readability (adding a comment, changing the variable names from A and B.. to something semantically meaningful) will be improved in the public release. I think the modularity of this code is generally good. - However, the hooker function is implemented with a forward overriding style, and I do not like this style... I hope we have a better way than this because this kind of approach will be broken if the `transformers` framework changes its internal API. - Since the PCA projection is in a separate kernel, this should be improved also. - I am very grateful for the latency breakdown plot in the PDF. In every other paper that I reviewed in this NIPS, no other author actually made this chart. I truly think this analysis is critical to find further bottleneck of method for future research. - I acknowledge the practical impact of this work is understandable by showing reducing the memory footprint of K tokens read by low-rank projection. - I hope the researchers will find a way to do PCA-took in a fused way (like flash attention. e.g., Flash-PCA-Topk). I think we have two approaches: **(1)** ML perspective: changing algorithms. e.g., change top-k into thresholding function. I think these papers will be helpful for the thresholding approach [1]. Or perform Top-k in hierarchically [2] **(2)** System perspective: preserve algorithm as much as possible, but change the implementation. e.g., implement top-k operation using a bucket (partitioning may also be possible). - **I think memory reduction is not very critical for this kind of work**. So, I respectfully disagree with aGJV's weakness. I understand why the reviewer points to memory reduction because, often, memory consumption limits the research scales. However, I think the memory access footprint is quite underestimated here. The important point of the whole reduction is reducing K memory **read** footprint. This means we can effectively reduce the latency and total throughput of K reads, which is the most significant part of attention. This means we do not need high bandwidth memory such as HBM3e, and we can just use GDDR6, which is much more cost-effective. Moreover, in much sparse attention works [2], they are struggling to reduce the memory throughput of K tokens because single K tokens are already quite huge (128 * 2 bytes for each token and there are 32 heads. usually 8KB, which is 2 pages of VM). So I really love the reduction of memory footprint, and this make possible to KV cache offloading effectively as shown in [2, 3] I hope other reviewers can acknowledge this practical benefits. Maybe it is good to show, how much memory reads actually happened during PCA-topk vs. FlashAttention using `nsight-compute` [4] in future research. I expect to minimize actual memory reads, we should be careful with memory addressing and formating of KV cache tensor. Again, thank you for your wonderful work, and I hope this kind of work (improving attention mechanism) continues. [1] https://arxiv.org/pdf/2107.00910 [2] https://arxiv.org/abs/2406.09827 [3] https://arxiv.org/html/2406.19707v1 [4] https://developer.nvidia.com/nsight-compute

Authorsrebuttal2024-08-12

We thank the reviewer for their extremely positive comments and the corresponding score increase. We greatly appreciate the insightful suggestions and hope to incorporate them in future work to further improve our method.

Reviewer KXhq6/10 · confidence 3/52024-07-12

Summary

This paper reveals that key vectors lie in a significantly lower-dimensional space. Inspired by this finding, the author approximates the computation of the original attention score using PCA, then selects the top-k keys based on the approximate attention scores. Experiments across different models and datasets show that PCA-TopK can achieve speedups of up to 40% with minor reductions in generation quality.

Strengths

1. The author discovers that the key vectors in multi-head attention lie in a lower-dimensional space, which may inspire future work on Sparse Attention. 2. TThe experiments across various models and datasets indicate that PCA-TopK can achieve speed improvements with only minor reductions in generation quality.

Weaknesses

1. There are some typos (lines 44, 150) in this article, and some figures are unclear with text overlaps (Figures 2, 6). 2. There are few baselines about Sparse Attention in the experiments. How does the PCA-TopK method compare to SPAR-Q Attention? What is the trade-off curve between their acceleration ratio and effect?

Questions

1. The analysis that key vectors lie in a lower-dimensional space is interesting. Do value vectors and query vectors share similar characteristics? What about the vector after merging multi-head attention? 2. Given the differences in Rankl@90 across layers, what is the impact of varying the policy depending on the layer? 3. If post-training with PCA-TopK, will it yield better performance?

Rating

6

Confidence

3

Soundness

3

Presentation

2

Contribution

3

Limitations

N/A

Reviewer aGJV6/10 · confidence 3/52024-07-12

Summary

The paper introduces a method for approximating attention in LLMs, with the benefit of improved inference efficiency. The insight is to focus on the dimensionality of the key vectors computed in the attention block. Principal component analysis reveals that the keys lie in a low dimensional space. This gives rise to the proposed method PCA-TopK, which uses PCA to compute approximate attention scores in a reduced dimension, and then selects the top-k tokens based on these scores, and compute the equivalent of full attention only for the selected tokens. The method is evaluated on multiple LLMs from the Llama family, Pythia, Mistral, Mixtral, Phi, and various datasets. The results show comparable performance to full attention while having significant speedups.

Strengths

The study of low intrinsic dimensionality of attention keys across multiple models and datasets is insightful. Theoretical support is provided through lemmas and proofs. The evaluation includes several models, tasks and datasets, showing it could be generalized. The authors developed optimized Triton kernels for practical implementation.

Weaknesses

The method does not seem to reduce the memory usage.

Questions

For some models the pre-rotary PCA transforms outperform the post-rotary ones, which is intriguing. The authors acknowledge that they do not have a clear explanation, however if more understanding was developed it would be great to include it in the paper.

Rating

6

Confidence

3

Soundness

3

Presentation

3

Contribution

2

Limitations

yes

Reviewer vRA76/10 · confidence 4/52024-07-13

Summary

This paper proposes a sparse attention mechanism for large language models by leveraging the low-dimensionality of key vectors in the attention block. The approach ranks and selects tokens in the KV-cache based on attention scores computed in the reduced dimensional space, leading to significant speedups in attention computation without major sacrifices in model quality.

Strengths

Empirical Validation: Extensive evaluations demonstrate significant speedups with minimal accuracy degradation. Theoretical Soundness: The use of low-rank keys is backed by robust theoretical analysis, enhancing the credibility of the approach.

Weaknesses

Implementation Complexity: The method's complexity might pose challenges for achieving the theoretical speedups without specialized knowledge. Memory Footprint Consideration: While the approach excels in computation, it does not address memory footprint reduction, a limitation when compared to other sparse attention techniques.

Questions

1. Model Class and Size Performance Variance: How does Loki's performance vary with different model classes and sizes not included in the paper? 2. Integration with High-Efficiency Attention Mechanisms: How does the PCA-TopK method align with or complement high-efficiency attention mechanisms such as Flash Attention or Ring Attention? Can it be orthogonally integrated with these techniques, or are there specific challenges that need to be addressed? 3. Comparison with Other Sparsity Strategies: The paper does not compare with attention sparse strategies beyond H2O, such as SnapKV[1]. Could the authors discuss the positioning of PCA-TopK relative to these methods and possibly include comparative analysis in future work? 4. Figure Clarity: Regarding Figure 6 (left), it appears there might be a compression issue. Could the authors verify the image quality and ensure that it is legible in subsequent versions of the paper? 5. Information Loss Management: How does PCA-TopK handle the potential loss of information when reducing the dimensionality of key vectors, especially in the context of Rotary Positional Embeddings (RoPE) which increase dimensionality? 6. Combination with Compression Techniques: How does PCA-TopK interact with other model compression techniques, and is there a combined approach that could yield better results? 7. Handling of Longer Sequences: How does Loki handle sequence lengths longer than those in the evaluation datasets? 8. Quantization Integration: Can the PCA-TopK mechanism be integrated with other optimization techniques like quantization?

Rating

6

Confidence

4

Soundness

2

Presentation

2

Contribution

2

Limitations

N/A

Reviewer vRA72024-08-13

Thanks for the author's response, and I will increase my rating to 6.

Authorsrebuttal2024-08-14

We thank the reviewer for their response and the score increase.

Reviewer KXhq2024-08-13

Thanks for the responses! I will keep my rating.

Authorsrebuttal2024-08-14

We thank the reviewer for their response.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC