Abstract
Contextual activation sparsity—dynamically activating only a subset of neural network parameters—offers a promising path toward accelerating Large Language Model (LLM) inference. However, traditional sparsity techniques, which focus primarily on Multi-Layer Perceptron (MLP) layers, suffer from a "union problem" in production environments: as batch sizes increase, the union of active neurons across all tokens quickly approaches 100% density, negating computational gains. This paper introduces Polar Sparsity, a framework designed to maintain efficiency at scale by shifting the focus of sparsification from MLP layers to Attention layers. By exploiting the batch-invariant nature of attention head sparsity and utilizing custom GPU kernels, Polar Sparsity achieves up to 2.2x throughput speedups on large-scale models like LLaMA-3 and OPT with negligible impact on accuracy.
Introduction
Large Language Model (LLM) inference is computationally and financially expensive, driven by the massive parameter counts and memory bandwidth requirements of modern architectures. Contextual activation sparsity has emerged as a potential solution, leveraging the observation that only a small fraction of a model's capacity is required to process any given token.
Despite its theoretical promise, a significant gap exists between sparsity research and real-world deployment. Production systems rely on high-throughput batching to maximize GPU utilization. In these scenarios, existing sparsity methods break down. Furthermore, as batch sizes and sequence lengths grow, the primary bottleneck in LLM inference shifts from compute-heavy MLP layers to memory I/O-heavy Attention layers. Polar Sparsity addresses these challenges by re-aligning sparsity strategies with the realities of batched, memory-bound workloads.
The Challenge: The "Union Problem" in Batched Sparsity
In standard batched inference, the GPU processes multiple requests simultaneously. For MLP layers, the hardware must compute the union of all active neurons required by every token in the batch. Empirical evidence shows that even at moderate batch sizes, this union quickly covers nearly all available neurons, forcing the system back into dense computation.
Conversely, Attention layers behave differently. Because each sequence in a batch attends only to its own Key-Value (KV) cache, the computation for attention heads is independent per sequence. This means a system can drop different attention heads for different sequences in the same batch without suffering from the union problem. This batch-invariance makes attention heads the ideal target for scaling sparsity.
The Polar Sparsity Framework
Polar Sparsity introduces a multi-faceted approach to reclaiming efficiency in batched settings:
1. Selective Head Attention (SHA)
Instead of pruning individual neurons, Polar Sparsity prunes entire attention heads. The system employs lightweight, single-layer router networks trained to predict which attention heads will contribute most significantly to a token's output. By activating only the top-$k$ heads, the system reduces both the computation and the memory traffic associated with the attention mechanism.
2. Custom Sparsity-Aware Kernels
Standard dense GPU kernels are inefficient when dealing with irregular sparsity patterns. To solve this, the authors developed:
- Selective FlashAttention: A custom kernel that fuses head activation logic directly into the attention computation. This ensures that only data from active heads is read from or written to High Bandwidth Memory (HBM), providing near-linear speedups relative to sparsity levels.
- Selective GEMM: A dynamic top-$k$ kernel designed to capture residual sparsity in early MLP layers where the union problem is less severe.
3. Architectural Insights: The "Sacred" Layer 0
During development, the authors discovered that the very first attention layer (Layer 0) consistently exhibits the highest importance scores across various models. Forcing Layer 0 to remain dense while applying uniform head sparsity to all subsequent layers proved crucial for maintaining model accuracy across benchmarks.
Experimental Evaluation
Methodology
Routers were trained using 400,000 token samples from the WikiText-2 dataset. Evaluation was conducted using the lm-eval-harness across a suite of zero-shot benchmarks, including COPA, OpenBookQA, PIQA, RTE, Winogrande, HellaSwag, MMLU, and ARC. Generative capabilities were further verified on MMLU-PRO and LongBench.
Key Results
- Throughput Gains: Polar Sparsity delivered up to 2.2x end-to-end throughput improvements during batched decoding for large models (e.g., OPT-66B at batch size 64) compared to dense baselines.
- Accuracy Preservation: Average accuracy remained within 1% of dense baselines at critical sparsity thresholds. For instance, OPT-66B maintained performance at 30% attention density, while LLaMA-3.1 70B operated effectively at 62.5% density.
- Model Scaling: Larger models demonstrated a higher tolerance for sparsification. OPT-66B saw only a 5% perplexity increase at 70% head pruning, whereas the smaller OPT-6.7B suffered a 37% penalty at the same level.
- Kernel Efficiency: The Selective FlashAttention kernel achieved a 2.8x faster forward pass at 30% density compared to standard FlashAttention.
Limitations and Future Directions
While Polar Sparsity excels at scale, it is less efficient for very small batch sizes (e.g., batch size 1) due to the overhead of router computation and GPU underutilization. Additionally, models using Grouped Query Attention (GQA), such as LLaMA-3, show higher sensitivity to head sparsity because dropping a query head group removes a larger portion of the context.
Future work will explore dynamic, task-aware routing, where the system allocates more attention heads to complex queries and fewer to simpler ones within the same batch. Extending these techniques to ultra-long context windows (exceeding 1 million tokens) remains a priority for further research.
Summary updated