TL;DR
SOCKET introduces a data-agnostic "soft" Locality-Sensitive Hashing (LSH) mechanism to enable highly efficient sparse attention during long-context LLM inference. By replacing traditional binary hash collisions with continuous, similarity-aware probabilistic scores, SOCKET drastically reduces memory overhead while maintaining high token-ranking fidelity. Supported by a custom CUDA kernel and Triton backend, it achieves up to a 1.58× throughput speedup over FlashAttention during decoding.
What Problem Does This Paper Address?
As Large Language Models (LLMs) scale to handle contexts spanning tens of thousands or even millions of tokens, they hit a severe memory bottleneck during autoregressive decoding. In this phase, every newly generated token must attend to all previously cached tokens in the Key-Value (KV) cache. This makes dense attention heavily memory-bound, frequently forcing systems to offload the KV cache to slower CPU memory.
Sparse attention reduces this cost by restricting computation to a selected subset of important tokens (top-$k$). However, existing sparse attention methods face a trade-off:
- Data-dependent approaches (like $k$-means clustering or quantization) require expensive online calibration, which severely degrades the Time-to-First-Token (TTFT).
- Traditional Locality-Sensitive Hashing (LSH) is data-agnostic but relies on hard, binary collision signals. This coarse filtering results in noisy rankings unless an impractical number of hash tables—and thus massive amounts of memory—are used.
Methods
The authors introduce SOCKET (SOft Collision Kernel EsTimator), reframing LSH from a crude candidate generator into a principled, similarity-aware scoring kernel.
The method operates in three stages:
- Key Hashing (Prefill Phase): Key vectors are projected using $L$ independent random hyperplanes and assigned to a single discrete bucket per hash table. These compact bucket indices (~600 bits per token) and value vector norms are cached in GPU memory.
- Query Soft Hashing (Decoding Phase): Instead of assigning a new query token to a single hard bucket, the query vector induces a smooth probability distribution over all buckets in each table using a softmax-over-logits approach governed by a temperature parameter $\tau$.
- Value-Aware Top-$k$ Selection: SOCKET computes a continuous similarity score for every key by aggregating the query's probability mass across the key's corresponding buckets, weighted by the value vector's norm. The model then performs exact attention exclusively on the top-$k$ retrieved tokens.
To make this practical, the authors engineered a custom CUDA scoring kernel alongside a Flash Decode Triton backend to handle exact attention over the sparsely selected tokens.
Datasets
SOCKET was evaluated across multiple long-context models (including Llama-3.1-8B-Instruct, Llama-3.2-1B-Instruct, Qwen3-8B, Qwen3-4B, and Qwen3-30B) using two primary benchmarks:
- LongBench: A benchmark covering real-world long-context tasks such as question answering, summarization, reasoning, and code understanding.
- RULER (including RULER-16K and RULER-32K): A synthetic diagnostic benchmark designed to test the retrieval of sparse, position-sensitive information embedded deep within long contexts.
- SAMSUM & QASPER: Utilized for preliminary ranking quality and correlation analyses.
Key Insights and Ideas
- The Power of Soft Collisions: Traditional LSH discards magnitude and directional information by forcing a binary (0 or 1) match. SOCKET's soft assignment allows the query to distribute mass smoothly, preserving the directional structure of high-dimensional random projections. This yields stable, continuous rankings even with a limited number of hash tables.
- Data-Agnostic Efficiency: Because SOCKET relies on random projections rather than data-dependent clustering, it requires no retraining or calibration. This ensures robustness to distribution shifts and keeps TTFT exceptionally low.
- Theoretical Alignment: The authors provide theoretical guarantees proving that the attention distribution derived from SOCKET's soft LSH scores closely approximates a kernel highly similar to standard dense softmax attention.
Key Results
- Superior Ranking Quality: Under an identical memory budget (600 bits/token), SOCKET consistently outperforms traditional LSH across Jaccard index, Precision, and NDCG metrics, demonstrating much higher fidelity to the true top-$k$ keys.
- Downstream Accuracy: On LongBench (Llama-3.1-8B-Instruct), SOCKET at 10× sparsity achieved an average score of 48.8, outperforming competitive baselines like Quest (46.8) and PQCache (45.9). At an aggressive 33× sparsity, SOCKET maintained a high average score of 47.83.
- Throughput Speedups: SOCKET delivers significant decoding speedups that scale with context length. On an NVIDIA H200 GPU at a 140K context length (under 33× sparsity), SOCKET achieved a 1.58× throughput increase over FlashAttention3. On an NVIDIA A100, it consistently outperformed FlashAttention2, reaching up to a 1.53× speedup at 72K tokens.
Limitations and Future Work
- Memory Overhead: Storing the precomputed hash tables introduces a modest additional memory overhead, amounting to approximately 15% beyond the standard KV cache.
- Architectural Generalization: While thoroughly validated on popular transformer model families (Llama and Qwen), evaluating SOCKET's performance on alternative or hybrid architectures (e.g., State Space Models or Linear Attention variants) remains an open question.
- Deterministic vs. Sampling Inference: The theoretical proofs rely on a sampling-based estimator, whereas the practical implementation utilizes deterministic top-$k$ selection. The empirical evaluation of the pure sampling approach is left for future work.
Summary updated