atlas

Research map / Architectures and efficiency / Attention and transformers

Loki: Low-rank Keys for Efficient Sparse Attention

NeurIPS 2024 · Architectures and efficiency › Attention and transformers · approach: Sparse attention for long-context LLMs · 2 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Loki approximates attention by computing top-k key selection scores in a low-dimensional PCA-projected key space (calibrated offline), then computing exact attention over the selected keys, with Triton kernels giving up to 45% attention speedup on Llama2-13B.

Problem

Self-attention in LLM inference is costly in memory bandwidth and compute for long sequences because the KV-cache must be read every decoding step; existing sparse methods either permanently evict tokens or use fixed sparsity patterns and degrade quality.

Approach

Keys lie in a low-dimensional subspace consistently across models and datasets; PCA-project queries and keys, rank tokens using only the top-d principal dimensions, then compute exact attention on the top-k tokens without deleting any cache entries.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use Loki sparse attention (k_f=0.25, d_f=0.25) instead of full attentionLlama2-7B · WikiText-2 testperplexity: 5.1101 -> 5.2017Hurt
Use Loki sparse attention (k_f=0.25, d_f=0.25) instead of full attentionLlama2-13B · WikiText-2 testperplexity: 4.5680 -> 4.6102Hurt
Use Loki sparse attention (k_f=0.25, d_f=0.25) instead of full attentionLlama3-8B · WikiText-2 testperplexity: 5.5696 -> 5.6648Hurt
Use Loki sparse attention (k_f=0.25, d_f=0.25) instead of full attentionMistral-7B · WikiText-2 testperplexity: 4.9140 -> 4.9233Hurt
Use pre-rotary rather than post-rotary PCA transformation (ablation)Loki · Llama3-8B and Mistral-7Bperplexity: about 5 for the full attention to over 10Helped
Use k_f=0.25, d_f=0.25 rather than k_f=0.125, d_f=0.5 (ablation)Loki · Short-context and LongBench tasksaccuracyHelped
Increase key budget and reduced dimension from k_f=0.25, d_f=0.25 to k_f=0.5, d_f=0.5 (ablation)Loki on Llama2-7B · Short-context tasksaverage score: 43.50 -> 47.45Helped
Use k_f=0.125, d_f=0.5 rather than k_f=0.25, d_f=0.25 (ablation)Loki on Llama2-7B · Short-context tasksaverage score: 43.50 -> 39.76Hurt
Use PCA transforms calibrated on different datasets (ablation)Loki · Short-context tasksaccuracyNo clear effect
Use optimized Triton kernels rather than the compared SparQ kernelsLoki attention implementation · Certain kernel scenariosspeedup: 2-3×Helped
Use Loki rather than vanilla attentionLlama2-13B-like setup · Prompt length 3072, generation length 512attention compute speedup: nearly a 45% speedupHelped
Vary the per-layer reduced-dimension policy (ablation)Loki · Appendix experimentmodel qualityNo clear effect

Surprising findings

Limitations

Experimental setup

Datasets: WikiText-2 WikiText-103 C4 BookCorpus LongBench GSM8K MMLU

Benchmarks: WikiText-2 perplexity HellaSwag TruthfulQA Winogrande ARC GSM8K MMLU LongBench

Metrics: perplexity accuracy Jaccard similarity of top-k attention time speedup

Baselines: Full Attention Exact-TopK H2O SparQ Attention InfiniGen

Builds on: SparQ Attention H2O RoPE Triton

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy