Post-Training Sparse Attention with Double Sparsity

## Abstract

Abstract The inference process for large language models is slow and memory-intensive, with one of the most critical bottlenecks being excessive Key-Value (KV) cache accesses. This paper introduces ”Double Sparsity,” a novel post-training sparse attention technique designed to alleviate this bottleneck by reducing the number of accesses to the KV cache. Double Sparsity combines token sparsity, which focuses on utilizing only the important tokens for computing self-attention, with channel sparsity, an approach that uses important feature channels for identifying important tokens. Our key insight is that the pattern of channel sparsity is relatively static, allowing us to use offline calibration to make it very efficient at runtime, thereby enabling accurate and efficient identification of important tokens. Experimental results demonstrate that Double Sparsity can achieve 1 16 1 16 \frac{1}{16} divide start_ARG 1 end_ARG start_ARG 16 end_ARG token and channel sparsity with minimal impact on accuracy across various benchmarks.
It achieves up to a 16x acceleration in attention operations and up to a 1.9x improvement in end-to-end inference speed on GPUs.

## 1 Introduction

Large Language Models (LLMs) have significantly advanced machine learning capabilities, enabling a wide range of applications from natural language processing to complex problem-solving tasks (achiam2023gpt; touvron2023llama; team2023gemini). However, their inference remains costly and slow due to token-by-token decoding. This decoding process exhibits low arithmetic intensity, making it largely memory-bound. During decoding, access to two types of memory is required: model weights and the Key-Value (KV) cache in the self-attention layers (vaswani2017attention). Both can be very large and thus become bottlenecks. When the batch size is large or the sequence length is long, the size of the KV cache can easily surpass that of the model weights (pope2023efficiently). While extensive research has focused on reducing access to model weights through quantization and sparsification, the reduction of access to the KV cache has received less attention.

In this paper, we explore methods to reduce access to the KV cache during inference, thereby making attention computation more bandwidth-efficient and accelerating its execution. Our focus is on post-training methods that can be directly applied to a pre-trained model to provide wall-clock acceleration without requiring excessive additional training or fine-tuning overhead. Prior work has attempted to leverage quantization (hooper2024kvquant; liu2024kivi), compression (nawrot2024dynamic), and sparsity (zhang2024h2o; anagnostidis2024dynamic; ge2024model; ribar2023sparq) to achieve these goals.
Among them, sparsity holds significant potential if a high sparsity ratio can be achieved. The intuition of sparsification is that not every token is equally important for decoding the next token. Therefore, during the decoding process, we can rely on a small subset of important tokens to compute the self-attention, achieving nearly the same results.
While the approach of sparse attention seems intuitive, previous research has struggled to find a post-training sparse attention method that maintains high accuracy while being runtime-efficient.

The primary challenge in post-training sparse attention lies in accurately and efficiently identifying important tokens. A naive approach entails calculating the entire attention weight matrices and then sorting the tokens based on the accumulated attention weights. Although this method can precisely identify important tokens, it fails to offer a runtime speedup, as it requires computing the full attention weight matrices, which is precisely the step we aim to avoid.
Previous studies have proposed various methods for selecting important tokens; however, these methods either lead to significant accuracy losses or fail to achieve practical wall-clock acceleration. Notably, H2O (zhang2024h2o) employs a dynamic strategy that maintains a small fixed-size cache of important tokens. Due to its limited size, it must evict many tokens. Since it cannot predict future important tokens, it often inadvertently evicts them, leading to accuracy degradation.
SparQ (ribar2023sparq), in contrast, retains all tokens and dynamically selects important ones at each step. Yet, its design falls short of achieving the desired speedup and incurs considerable additional memory overhead. In summary, designing an efficient method capable of accurately identifying important tokens remains a significant challenge.

We propose “Double Sparsity,” a method that leverages both token sparsity and channel sparsity to achieve accurate and efficient post-training sparse attention. Token sparsity refers to the sparse attention method mentioned above (zhang2024h2o), which uses only important tokens to compute self-attention. Channel sparsity, a new method we introduced, selects important tokens at runtime using significant feature channels. Our key insight is that while token sparsity is highly dynamic, channel sparsity exhibits relatively static behavior, enabling us to identify and select important channels through offline calibration. This static channel sparsity thus provides an efficient means to achieve dynamic token sparsity at runtime. Building on this concept, we carefully explored how to select important channels based on statistics from offline calibrations.
Furthermore, once we can quickly identify important tokens for the current layer, we extend this process by predicting the important tokens of the next layer. We achieve this by utilizing the embedding similarity between adjacent layers. This approach enables us to offload the entire KV cache to host memory and prefetch only the important tokens to GPU memory, significantly reducing GPU memory footprint.

Shown in Figure 2, we demonstrate that Double Sparsity can achieve both an $\frac{1}{16}$ token sparsity and an $\frac{1}{16}$ channel sparsity simultaneously, while incurring only a negligible accuracy loss across a broad array of benchmarks, including language modeling, question answering, and retrieval tasks. The sparsity directly leads to the reduction of memory access and runtime speedup. Double Sparsity accelerates the attention operation by up to $14.1\times$ at a sparsity level of $\frac{1}{16}$ on NVIDIA A10G and A100G GPUs, closely approaching the theoretical acceleration upper bound. It accelerates end-to-end inference for various workloads by up to $1.9\times$. When turning on offloading, it achieves a decoding throughput that is $16.3\times$ higher than the state-of-the-art offloading-based solutions at a sequence length of 256K.

## 2 Background

### 2.1 Preliminaries on Self-Attention and Notations

Attention computation is one of the major bottlenecks in LLM Inference, especially when the sequence length is large (tay2022efficient). This is caused by its quadratic computational complexity.
Let $d_{h}$ denote the head dimension, and $S$ denote the number of tokens.
We use the decoding step as an example to illustrate the self-attention computation.
Each token carries three tensors to embed its information, which are called query, key, and value.
In an attention layer, let $q\in\mathbb{R}^{d_{h}}$ represents the query tensor for input token, $K\in\mathbb{R}^{S\times d_{h}}$ represents the key tensor for all tokens, and $V\in\mathbb{R}^{S\times d_{h}}$ represents the value tensor for all tokens. The attention is obtained through the formula shown below:

$$ $y=softmax\left(\frac{q\cdot K^{T}}{\sqrt{d_{h}}}\right)\cdot V$ $$

### 2.2 Post-training Sparse Attention

In this work, we introduce the term ”post-training sparse attention,” analogous to ”post-training quantization.” Post-training sparse attention refers to techniques that exploit inherent model sparsity, such as token-level sparsity, to accelerate attention calculations without requiring additional training. In the field of LLMs, many works have utilized post-training sparse attention, including H2O, StreamingLLM (xiao2024efficient) and SparQ. However, these methods come with significant limitations, presenting serious challenges for post-training sparse attention.

## 3 Challenges in Post-Training Sparse Attention

In this section, we discuss prior research on post-training sparse attention, identifying the challenges and shortcomings that have prevented these approaches from achieving their full potential.
More related work is included in Section 7.

### 3.1 Retrieval Accuracy

One of the most challenging issues for post-training sparse attention is maintaining retrieval accuracy. For instance, StreamingLLM discards earlier tokens, while H2O selectively drops tokens based on previous attention scores.
Although discarding tokens can accelerate computations, this exclusion leads to the loss of critical information, potentially compromising the model’s retrieval accuracy. As highlighted in jelassi2024repeat, this issue is inherent to techniques that rely on discarding tokens, prompting the exploration of sparse attention methods that preserve the complete KV cache.

### 3.2 Hardware Friendliness

Achieving wall-clock speedup poses a greater challenge while maintaining model retrieval accuracy, particularly because some post-training sparse attention techniques are not hardware-friendly.
For instance, SparQ retains the complete KV cache and computes attention selectively on a subset of the KV cache based on the query. This approach theoretically allows for acceleration while maintaining accuracy.
However, SparQ’s method of selecting channels and tokens results in non-contiguous memory access, causing substantial L1/L2 cache misses and wasting GPU bandwidth with the standard 128-byte memory access.
Despite being designed to accelerate processing, SparQ achieves only a modest 1.3 times speed increase in attention computations.
Therefore, it is crucial to develop an algorithm that ensures continuous memory access patterns and avoids dynamic selection of channels to accelerate attention while preserving accuracy.

### 3.3 Memory Usage

Methods that preserve the complete KV cache inherently require substantial GPU memory consumption.
To mitigate the heavy memory demand, the FlexGen (sheng2023flexgen) approach offloads the KV cache of each layer to the GPU only during the computation phase.
However, a significant challenge arises because FlexGen needs to offload the complete KV cache, and the communication overhead can drastically affect overall system performance.
Considering that selected tokens constitute just a small fraction of all tokens, the time taken to offload these specific tokens to the GPU is considerably less than the time required for offloading the entire KV cache as in FlexGen.
By efficiently managing when and how data is transferred and processed, it’s possible to significantly reduce both the time and memory overhead typically associated with maintaining a full KV cache.

To address these challenges, we propose two post-training sparse attention techniques. In Section 4, we introduce Double Sparsity, which accelerates attention by up to 16 $\times$ with minimal additional memory consumption.
In Section 5, we present Double Sparsity-Offload, which reduces memory usage to 1/16 without increasing latency.

## 4 Double Sparsity

Based on the insights of Section 3, we propose Double Sparsity, a hardware-friendly and bandwidth-efficient post-training sparse attention mechanism.
This approach overcomes the challenges highlighted in previous post-training sparse attention techniques by ensuring no loss of information, as it maintains the entire KV cache.
To avoid the cache misses associated with runtime sorting, Double Sparsity utilizes offline calibration to pre-determine outlier channels for each transformer layer.
A compact label cache is employed to store outlier channel values from the Key cache, optimizing memory access patterns to leverage GPU’s preference for contiguous memory access.
Algorithm 1 and Figure 2 illustrate the decoding process of Double Sparsity.

Figure: Algorithm 1 Double Sparsity Decode
Refer to caption: extracted/5798647/figures/Llama-2-7b-hf-3d-v4.png

### 4.1 Offline Calibration

Offline calibration is a commonly used technique to identify channel sparsity, particularly effective for pinpointing outlier channels.
For example, AWQ (lin2023awq) utilizes offline calibration to identify salient weight channels that significantly impact model performance.
Inspired by this approach, we employ offline calibration to pre-determine the channels that most influence attention scores.
Attention computation can be expressed as $A=Q\cdot K^{T}$ , which can be broken down into $A=\sum_{i}^{d_{h}}S_{i}$ where $S_{i}=Q_{i}*K_{i}$. Due to channel sparsity, only a few $S_{i}$ have a significant impact on $A$.
Therefore, by conducting offline calibration on a small validation set, we can efficiently identify these critical channels by computing the $\underset{i}{argmax}\,S_{i}$.
Figure 9 in Appendix A illustrates the outlier channels identified by AWQ and Double Sparsity.

To validate the efficacy of outlier channels identified through offline calibration, we conducted a comparison in Appendix A between the outlier channel indices derived from offline calibration and those determined during the online decoding process.
A significant overlap between the two sets underscores the reliability of offline-calibrated outliers.
Figure 9 illustrates this relationship.
An observation from the comparison is that when the ratio surpasses 0.25, the overlap reaches 0.95.

### 4.2 Forwarding with Label Cache

After identifying the outlier channel indices, it becomes crucial to access them efficiently.
Reading these channels directly from the Key cache can lead to non-contiguous memory accesses, which significantly underutilized the bandwidth.
To alleviate non-contiguous memory accesses, we leverage a label cache to store pre-determined heavy channel values.
This label cache allows for continuous memory access when computing approximate attention, avoiding the need to retrieve non-contiguous segments from the Key cache.
During the prefilling stage, all heavy channel values from the Key cache are stored in the label cache; in the decoding phase, only the heavy channel values of new tokens are added.
Since approximate attention is not sensitive to precision, we can store the label cache in 4-bit.
This approach enables us to maintain a label cache that is only 1/16 the size of the K cache, facilitating contiguous memory access and significantly improving the hit rate of L1/L2 caches, thereby optimizing inference speed and efficiency.
In Appendix B.1, an ablation study was conducted to evaluate the impact of label caches. The results demonstrated that a label cache accelerates decoding speeds by 2 to 4 times compared to configurations without a label cache.

## 5 Reducing GPU Memory Usage with Double Sparsity-Offload

Building upon Double Sparsity, we propose the Double Sparsity-Offload technique to further reduce the GPU memory overhead in large language models.
This approach significantly diminishes the memory requirement to 1/16 of the original KV caches. By optimizing memory usage, Double Sparsity-Offload enables more efficient decoding, especially with limited GPU memory resources.

### 5.1 Prefetching Tokens with Double Buffer

The Double Sparsity-Offload algorithm introduces a double buffer prefetching system during for decoding process.
The complete KV cache is stored on the CPU, while the GPU maintains only the label cache and a double buffer.
During the decoding process, each layer processes its embeddings through the next layer’s query projection to generate an approximate query for the subsequent layer. This approximate query is then used to compute the next layer’s approximate attention. While the current layer’s attention and feed-forward network computations are being performed, the tokens corresponding to the approximate attention results for the next layer are offloaded to the GPU. This use of double buffering allows for a smooth and efficient overlap of computation and memory transfer.

### 5.2 Empirical Analysis: Embedding Similarity Between Layers

The feasibility of the Double Sparsity-Offload algorithm is based on the high degree of similarity between embeddings across consecutive layers.
To empirically validate this assumption, we conducted an analysis using the Pile validation dataset, applied to the Llama-2-7B model. We measured the cosine similarity of embeddings between every two consecutive layers throughout the model. The results show that apart from the first two layers, the second and third layers, and the very last layers (30 and 31), all other layer pairs exhibited a cosine similarity exceeding 90%, with the majority of layers showing similarities above 95%. These high similarity scores support the viability of utilizing prior layer embeddings to predict queries for subsequent layers in Double Sparsity-Offload.

### 5.3 Complexity Analysis

To understand the potential speedup of Double Sparsity, we need to analyze its Cache IO-Complexity since attention mechanisms are bandwidth-bounded.
Double Sparsity can be simplified into two steps: calculating approximate attention and computing attention over $k$ tokens.
Memory-wise, the total access comprises $O(d)$ bytes for $Q$, $O(S\times r)$ for the label cache, $O(2\times k\times d)$ for the KV cache, leading to a total of $O(S\times r+2\times k\times d)=O(\alpha\times S\times d+2\times\beta\times S
\times d)$.
Given that the approximate attention phase of Double Sparsity does not involve softmax operations, it allows for high parallelism compared to the following step.
Therefore, the overall IO complexity of Double Sparsity primarily depends on the latter step, which can be approximated as $O(2\times\beta\times S\times d)$.
This analysis reveals that Double Sparsity’s time complexity is linearly dependent on $\beta$, and the extra memory overhead is linearly proportional to $\alpha$.
Table 1 summarizes all the sparsity works discussed, specifying their overhead, complexity, and speedup.

**Table 1: Comparison of sparsity-related techniques. ‘SparQ (1xK)’ denotes single-dimension storage of the Key cache, while ‘SparQ (2xK)’ refers to dual-dimension storage of the Key cache.**
| Method | On-device Cache Size | Cache IO-Complexity | Min $\beta$ | Speedup |
| --- | --- | --- | --- | --- |
| H2O | $S\times\beta$ | $S\times\beta$ | 1/5 | Yes |
| SparQ (1xK) | $S$ | $S\times\beta$ | 1/8 | No |
| SparQ (2xK) | $S\times 1.5$ | $S\times\beta$ | 1/8 | Yes |
| AWQ | $S$ | $S$ | 1 | Yes |
| Double Sparsity | $S\times(1+\frac{\alpha}{2})$ | $S\times\beta$ | 1/16 | Yes |
| Double Sparsity-Offload | $S\times\frac{\alpha}{2}$ | $S\times\beta$ | 1/16 | Yes |

## 6 Experiment

In Section 6.1, we demonstrate that both Double Sparsity and Double Sparsity-Offload maintain robust performance with a sparsity setting of 1/16 across various benchmarks, including Wiki-2 perplexity (merity2016pointer), MultifieldQA (bai2023longbench), GovReport (huang2021efficient), TriviaQA (2017arXivtriviaqa), and MMLU (hendryckstest2021).
In key-value retrieval tasks, Double Sparsity significantly outperforms other post-training sparse attention techniques.
In Section 6.2, we compare Double Sparsity against state-of-the-art attention and end-to-end implementations.
Results show that Double Sparsity achieves up to a 16-fold acceleration in attention mechanisms and up to a twofold increase in overall end-to-end processing speed. Additionally, Double Sparsity-Offload achieves a 16-fold acceleration compared to FlexGen Offload.

### 6.1 Accuracy Evaluation

#### 6.1.1 Wiki-2 Perplexity

Wiki-2 perplexity is a benchmark derived from Wikipedia articles, offering a comprehensive test with its broad vocabulary and authentic text features.
A lower score indicates better model performance.
Table 2 illustrates the changes in perplexity across different sparsity levels for each model.

**Table 2: Perplexity of models at various sparsity levels. Note the minimal changes in perplexity from sparsity levels 1 to 1/16, with a significant performance gap emerging between levels 1/16 and 1/32.**
|  | Sparsity Level |  |  |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
| Model | 1 | 1/2 | 1/4 | 1/8 | 1/16 | 1/32 |
| Llama-7B | 5.68 | 5.69 | 5.69 | 5.72 | 5.80 | 7.66 |
| Llama-2-7B | 5.47 | 5.48 | 5.53 | 5.56 | 5.76 | 12.01 |
| Llama-2-7B (offloading) | 5.47 | 5.48 | 5.54 | 5.57 | 5.86 | 15.29 |
| Llama-2-7B-chat | 6.94 | 6.94 | 6.96 | 6.92 | 7.14 | 14.93 |
| Llama-2-7B-chat (offloading) | 6.94 | 6.94 | 6.97 | 6.92 | 7.33 | 20.08 |
| Mistral-7B | 5.25 | 5.25 | 5.26 | 5.27 | 5.37 | 14.55 |

To demonstrate the model’s performance at different sparsity levels and justify our selection of a sparsity level of 1/16, we constructed a 3D bar chart. According to Figure 11 in Appendix C, a noticeable shift in perplexity is observed as the sparsity level goes beyond 1/16.

To validate the robustness of Double Sparsity and the effectiveness of the 1/16 sparsity level, we conducted a series of ablation studies across various model configurations and conditions.
Table 3 demonstrates the effectiveness of Double Sparsity at a sparsity level of 1/16 across various model sizes, attention mechanisms, and MoE configurations.

**Table 3: Ablation study on different architectural models with different outlier types at 1/16 sparsity level. Note that GQA models are incompatible with K outlier channel.**
| Model | Architecture | Original | Double Sparsity |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
|  |  |  | random channel | q outlier | k outlier | qk outlier |
| Llama-2-7B | Single/MHA | 5.47 | 8.62 | 6.45 | 6.61 | 5.76 |
| Llama-2-7B-chat | Single/MHA | 6.94 | 10.1 | 7.8 | 9.44 | 7.14 |
| Mistral-7B | Single/GQA | 5.25 | 6.06 | 5.79 | N/A | 5.37 |
| Llama-2-70B | Single/GQA | 3.32 | 5.15 | 3.69 | N/A | 5.17 |
| Mixtral-8x7B | MoE/GQA | 3.84 | N/A | 3.84 | N/A | 17.3 |

#### 6.1.2 Long Context Benchmarks

We used Llama-2-7B to evaluate the performance of Double Sparsity across multiple long context benchmarks at various levels of sparsity, comparing its effectiveness with that of StreamingLLM and H2O.
As illustrated in Figure 3, Double Sparsity maintains its performance with nearly no drop in accuracy at a sparsity level of 1/16, outperforming other techniques.

Figure: Figure 3: Performance of different techniques across various sparsity levels for long context benchmarks. ‘DS’ and ‘DS-O’ refer to Double Sparsity and Double Sparsity-Offloading. ‘Stream’ refers to Streaming-LLM.
Refer to caption: extracted/5798647/figures/longbench-v7.png

#### 6.1.3 Key-Value Retrieval

The key-value retrieval benchmark is designed to assess a model’s in-context retrieval capabilities.
Our experiments compared Double Sparsity against other post-training sparsity techniques, including H2O, StreamingLLM, and RTN quantization (nagel2020down).
We also tested the performance of Double Sparsity with the Vicuna-7B-16K model to observe how accuracy changes as context length increases.
As shown in Figure 4, we demonstrate that Double Sparsity significantly surpasses the other techniques in key-value retrieval tasks.
Notably, Double Sparsity and Double Sparsity-Offload show equivalent performance, highlighting that the offloading mechanism exhibits almost no decay.

Figure: Figure 4: Retrieval accuracy across various sparsity levels and context lengths. ‘DS’ and ‘DS-O’ refer to Double Sparsity and Double Sparsity-Offloading. ‘Stream’ refers to Streaming-LLM. ‘RTN’ refers to RTN Quantization.
Refer to caption: extracted/5798647/figures/retrieval_plots-v8.png

### 6.2 Speedup Evaluation

#### 6.2.1 Setups

Hardware. Our experiments were conducted on two types of GPUs: the A10G and the A100-SXM.

Implementation. For the Double Sparsity Attention, we utilized PyTorch to compute approximate attention and select the top-k tokens. The kernel for attention over top-k tokens was designed using OpenAI Triton.
For end-to-end testing, we replaced the full attention mechanism in gpt-fast (pytorch2023accelerating) with our Double Sparsity Attention.
For Double Sparsity-Offload, we implemented asynchronous CPU to GPU memory copying using CUDA streams and DGL (wang2019dgl)’s gathering kernel.

Workload. We focused on high-workload scenarios to push the limits of Double Sparsity. This included a range of batch sizes from 4 to 32 and sequence lengths from 1024 to 16384.
For Double Sparsity-Offload, we extended testing to extreme conditions on the A100 GPU, exploring sequence lengths from 64K to 256K.
Given that gpt-fast’s KV cache is pre-allocated, the tokens-per-second throughput depends solely on the batch size and sequence length.

Baseline. For attention acceleration evaluations, we use the ‘scaled_dot_product_attention’ as our baseline. This implementation ranks among the fastest attention mechanisms, dynamically allocating computation among the most efficient options including FlashAttention-2 (dao2023flashattention2), Memory-Efficient Attention (xFormers2022), and the top-performing kernels from the PyTorch team. In the end-to-end speed evaluations of Double Sparsity, gpt-fast serves as the baseline, distinguished as the state-of-the-art for Llama models on the A100 GPU. It offers exceptionally low latency and throughput that surpasses that of the huggingface transformers by tenfold. For evaluating Double Sparsity-Offload, we compare it against FlexGen Offloading, which shares the same gpt-fast codebase and memory footprint.

Other Settings. Given Double Sparsity’s focus on the attention mechanism, both weights and activations were set to FP16 precision. Furthermore, considering the limitations imposed by Triton kernels on Torch compile options, neither Double Sparsity nor gpt-fast employed the Torch compiler.

#### 6.2.2 Attention Operator Speedup

Figure 5 provides a comprehensive view of the latency and speedup of Double Sparsity compared to ‘scaled_dot_product_attention’ across different batch sizes and sequence lengths.
On the A10G GPU, every case achieves at least a fivefold speedup, with more than half exceeding ninefold. Notably, Double Sparsity achieves a linear speedup at a sequence length of 4096 with large batch sizes. On the A100 GPU, nearly all cases see at least fourfold faster processing, with larger batches reaching up to tenfold speedup.
The greater speedup for smaller batches on the A10G might be due to the launch time of Triton kernels, which becomes significant when the kernel execution time on the A100 is short.

Figure: Figure 5: Latency and speedup of Double Sparsity Attention at various batch sizes and sequence lengths. ‘DS’ indicates double sparsity attention. ‘Flash’ indicates the ‘scaled_dot_product_attention’, which is the fastest of FlashAttention-2 and Memory-Efficient Attention.
Refer to caption: extracted/5798647/figures/attention_speedup-v7.png

#### 6.2.3 End-to-End Inference Speedup

Figure 6 (a)(b) presents the throughput comparison between Double Sparsity and gpt-fast, measured in tokens per second across various batch sizes and sequence lengths.
We deployed the Llama-2-7B model and maximized memory usage to achieve high workload conditions.
The results indicate that Double Sparsity yields a minimum speedup of 1.3x across all tested conditions. In certain scenarios, the speedup approached twofold, showcasing Double Sparsity’s overall efficiency.

Figure: Figure 6: Throughput (token/s) and speedup of Double Sparsity (Offloading) in end-to-end scenarios.
Refer to caption: extracted/5798647/figures/end2end_speedup-v8.png

In Figure 6 (c)(d), we compare the throughput of Double Sparsity-Offload to FlexGen under a constrained memory footprint, set at 1/16 of a full KV cache for both methods. Both techniques utilize a double buffer for asynchronous data copying.
The results show that Double Sparsity-Offload achieves a 4-8$\times$ speedup over FlexGen under regular workloads, and a 16$\times$ speedup in scenarios with long texts ranging from 64K to 256K in sequence length.

## 7 Related Work

##### Sparse Attention Inference

Due to the significant overhead of attention mechanisms, many studies have focused on exploiting attention sparsity to accelerate inference.
These efforts can be categorized under three main criteria: 1) static or dynamic sparse patterns; 2) the presence of token eviction; 3) accelerating pre-filling or decoding.
StreamingLLM (xiao2024efficient) and LM-Infinite (han2023lm) utilize static sparse patterns with token eviction to accelerate decoding. These approaches achieve inference acceleration by preserving only a small number of initial tokens along with local tokens.
H2O (zhang2024h2o) and Scissorhands (liu2024scissorhands) employ dynamic sparse patterns with token eviction for decoding, preserving only a small fraction of the KV cache called heavy hitters according to accumulated attention scores, while FastGen (ge2024model) uses adaptive sparse attention patterns for different attention heads.
MInference (jiang2024minference10acceleratingprefilling) serves as a prefilling acceleration method that retains all tokens. It first identifies sparse patterns within the model, and then leverages these identified patterns to compute the pre-filling stage.
SparQ (ribar2023sparq) and Quest (tang2024quest) implement dynamic sparse decoding while also preserving all tokens. SparQ filters the top-k tokens using heavy channels of queries. Quest segments tokens into multiple pages and computes attention on the top-k pages to facilitate the decoding process.

##### Sparse Attention Training

There are also many efforts to reduce attention complexity through training (qiu2020blockwise; ding2023longnet; tay2020sparse; chen2021scatterbrain).
For example,
Sparse transformer (child2019sparsetransformer) reduces the complexity to $O(n\sqrt{n})$ by introducing sparse factorization of the attention matrix.
Reformer (kitaev2019reformer) achieves $O(n\log{n})$ complexity via locality-sensitive hashing.
Longformer (beltagy2020longformer), BigBard (zaheer2020big), and Linformer (wang2020linformer) further reduce the complexity to linear.
Linear attention architectures have also been proposed in katharopoulos2020transformers.

##### Other Attention and Inference Optimizations

Despite efforts to sparsify the attention computation, there are many other optimizations for attention efficiency.
Common techniques include quantization and compression (hooper2024kvquant; liu2024kivi; kang2024gear; nawrot2024dynamic), efficient attention architecture like multi-query attention (shazeer2019fast) and group-query attention (ainslie2023gqa), and memory-efficient attention algorithms (rabe2021self; dao2022flashattention).
Alternatives to transformers include using the state space model to remove the attention mechanism (gu2021efficiently).
Other common inference optimizations for LLMs include batching yu2022orca, memory optimizations sheng2023flexgen; kwon2023vllm; aminabadi2022deepspeed, parameter sharing sheng2023slora; chen2023punica, speculative decoding stern2018blockwise; leviathan2023fast; miao2023specinfer, scheduling han2022microsecond; agrawal2023sarathi; patel2023splitwise; zhong2024distserve,
quantization xiao2023smoothquant; lin2023awq; dettmers2022gpt3; frantar2022optq, and sparsification frantar2023sparsegpt.

## 8 Future Directions and Conclusion

Future Directions.
Despite the progress made with Double Sparsity, several limitations remain that reveal promising directions for future research. It is challenging to perfectly overlap communication with computation.
Enhancing asynchronous capabilities to mask communication overheads presents a promising direction that allows for significant acceleration with a minimal memory footprint.

Conclusion.
In this work, we introduced Double Sparsity and Double Sparsity-Offload, innovative post-training sparse attention techniques.
Double Sparsity leverages offline calibration and label cache to achieve nearly lossless performance across various benchmarks at a 1/16 sparsity level.
Performance tests showed that Double Sparsity could accelerate attention computations by up to 16$\times$ and achieve an end-to-end speedup of 1.9$\times$.
Double Sparsity-Offload significantly reduced KV Cache memory usage to 1/16, outperforming the throughput of previous SOTA offloading techniques by 16 times.

## Appendix A Offline Calibration Illustration

The x-axis of the Figure 9 denotes the ratio of the selected top-k channels to the total number of channels, while the y-axis quantifies the degree of overlap between the offline and online outliers.

Figure: Figure 7: Outlier channels of AWQ and Double Sparsity.
Refer to caption: extracted/5798647/figures/offline-calibration-v3.png

## Appendix B Ablation Study

### B.1 Forward without Label Cache

To investigate the significance of the label cache in the forward pass of Double Sparsity, we conducted experiments comparing performance with and without the label cache.
As depicted in Table 4, label caches significantly enhance the forward pass, yielding a speedup ranging from 2 to 4 times.

**Table 4: Latency comparing performance With and Without Label Cache.**
| Batch | Seq Len | With Label Cache (ms) | Without Label Cache (ms) | Speedup |
| --- | --- | --- | --- | --- |
| 4 | 2048 | 0.165 | 0.279 | 1.7 |
| 4 | 4096 | 0.181 | 0.559 | 3.1 |
| 4 | 8192 | 0.504 | 1.250 | 2.5 |
| 4 | 16384 | 1.550 | 3.000 | 1.9 |
| 32 | 2048 | 0.467 | 1.960 | 4.2 |
| 32 | 4096 | 0.983 | 3.950 | 4.0 |
| 32 | 8192 | 3.600 | 9.540 | 2.6 |
| 32 | 16384 | 12.600 | 24.000 | 1.9 |

### B.2 Embedding Similarity Across Layers

Figure: Figure 10: Average cosine similarity of embeddings across all attention heads between layers 0-1, 1-2, 2-3, and 3-4 on the Pile dataset for Llama-2-7B model.
Refer to caption: extracted/5798647/figures/attn_sim_plot_layer-v4.png

## Appendix C Perplexity Selection Illustration

Figure 11 uses token-level sparsity as the x-axis, channel-level sparsity as the y-axis, and 10-perplexity values as the z-axis, where higher bars indicate better performance. A sudden shift in perplexity is observed as the sparsity level goes beyond 1/16.

Figure: Figure 11: Perplexity of models at different token-sparsity and channel-sparsity levels. Notably, the red bars, representing a sparsity level of 1/16 for both token and channel, show that the model’s performance remains largely consistent with the original model at this level.
Refer to caption: extracted/5798647/figures/3d-bar-v2.png

## Peer Reviews

confidence: 4
contribution: 2
initial_rating: 3
presentation: 3
questions: As stated in Weakness.
soundness: 2
strengths: This paper has a solid system implementation. The comprehensive system evaluation shows that Double-Sparse can lead to over 10 times acceleration when offloading. This system has also been shown to be compatible with quantization methods and has been implemented into SGLang, a SOTA LLM serving system.
summary: This paper introduces a new post-training sparse attention method. It implements two systems, including offloading and non-offloading ones, showing that with double-sparse, we can have high accuracy and low TPOT in different models, including MoE, GQA, and VLMs.
weaknesses: 1 Given that SparQ is already there, the paper does not explain why the important channels are static. 
2 Given that SparQ is already there, the accuracy results of SparQ are also expected to be shown, even if I can accept that SparQ is hard to have actual acceleration in GPUs.
3 InfLLM also has an on-device cache to accelerate decoding, but the paper does not well cite or discuss this fact.
4 Double-Sparse can also be seen as a special case of Loki by constraining the low-rank projectors in Loki to be a selective matrix (which means there is exactly one "1" in each row and others are zero). Given this fact, it's necessary to show the comparison with Loki, although I do not think Double-Sparse can outperform Loki. 
5 As far as I know, the sequence in LongBench is not that long (256K mentioned in the paper). To make the statement fair, I will ask for accuracy evaluations on benchmarks with long enough contexts. Perperlexity is not enough, as streamingLLM can also do well. 
6 The retrieval task is not standard. I will ask for evaluations on RULER to better understand the technique.

---

confidence: 4
contribution: 2
initial_rating: 3
presentation: 2
questions: Please answer my question in the weakness section. In addition, it would be great for the authors to provide more details in the rebuttal regarding the prefetching design.
soundness: 2
strengths: + Jointly channelwise and tokenwise pruning
+ Real GPU implementation
+ Good system performance
summary: This paper introduces Double Sparsity, a technique that jointly prunes tokens and channels by leveraging the static nature of channel sparsity, enabling offline calibration for runtime efficiency and precise identification of key tokens. The authors also propose an efficient implementation by offloading the entire KV cache to host memory and prefetching only essential tokens to GPU memory, significantly reducing GPU memory usage.
weaknesses: - While joint channelwise and tokenwise pruning is novel, it closely resembles headwise and tokenwise pruning, which has been explored in previous work [1], raising concerns about the paper's originality.
- The evaluation lacks comprehensiveness, as several LLM pruning baselines are not included ([2], [3], [4]).
- The writing quality requires substantial improvement, with several inaccuracies in mathematical notation. For instance, in line 200, Qi and Ki are not clearly described—it's unclear if they are vectors or scalars. Additionally, the explanation of GPU prefetching and pipelining is too vague, making it difficult to follow the precise implementation steps.


[1] https://hanlab.mit.edu/projects/spatten
[2] Lee, Chonghan, et al. "Token and Head Adaptive Transformers for Efficient Natural Language Processing." Proceedings of the 29th International Conference on Computational Linguistics. 2022.
[3] Ge, Suyu, et al. "Model tells you what to discard: Adaptive kv cache compression for llms." arXiv preprint arXiv:2310.01801 (2023).
[4] Zhao, Youpeng, Di Wu, and Jun Wang. "ALISA: Accelerating Large Language Model Inference via Sparsity-Aware KV Caching." arXiv preprint arXiv:2403.17312 (2024).

---

confidence: 5
contribution: 3
initial_rating: 8
presentation: 2
questions: 1. I'm curious if there's a sparsity law, e.g., what sparsity level can be reached at what context length, for what task, and model scale? Also, I would assume larger model might have more to discuss for channel sparsity, both from engineering perspective and from quality preserving perspective. 
2. How well does the method work with tensor parallel and pipeline parallel? I'm curious how the speed/memory bonus go with tp and pp size?
soundness: 4
strengths: 1. The insight into how existing KV management works are not feasible for actual hardware deployment is sharp and valid in its class. This direction was supposed to solve actual production scenarios, but most of the existing work actually overlook the hardware nature, e.g., IO pattern, fused operation, fragmentation, and so forth. It's good to say this paper point out these issues, which could make future work more solid.
2. The proposed solution is effective, as it generates much better wall-clock speed-up and memory saving. More importantly, the method is integrated SGLang. To the best of my knowledge, most of the methods in class can hardly be integrated into actual serving system like vLLM, SGLang, and TensorRT. 
3. Performance preserving is plausible.
summary: The paper designs offline calibration and label cache to make token and channel sparsity relatively more hardware friendly compared to existing sparse attention training and inference works.
With such design, the method could achieve decent wall-clock speed-up and memory reduction, while maintaining good context retrieval capabilities.
weaknesses: 1. Writing seems to be rushed and very unclear in many places. Please include a notation table and a taxonomy table, or at least declare the notation before or shortly after usage. 
2. The long context evaluation may be done on longer contexts, e.g., 128k, and more challenging tasks, e.g., RULER and BABILONG. From my perspective, as long as the method can work on 128k context with the 1/16 sparsity, I would be rather impressed. More complex eval can be saved for future work.
3. It would be good to see how more comprehensive benchmarks, e.g., MMLU, and long generation tasks, e.g., ChatArena. I'm generally fine with this point as some previous methods in the class already tested it.
4. It would be good if [1] can be cited, as it stated similar hardware insights and published earlier than this one, e.g., it's infeasible to manage small memory chunks at arbitrary location, KV management should be hardware-aware and compatible with actual inference/training frameworks like vLLM/SGLang/Megatron. I assume two works are parallel and it's okay if [1] is not included. 

[1] S2-Attention: Hardware-Aware Context Sharding Among Attention Heads

---

confidence: 5
contribution: 2
initial_rating: 5
presentation: 3
questions: My questions are written under the weaknesses section. If they can be addressed, I'd be happy to raise the score.
soundness: 3
strengths: Long-context inference is an important research direction nowadays, where attention occupies a bottleneck for compute/memory. In the calibration stage, this work draws on insights based on AWQ and uses offline pre-processing of outliers in the channel dimension. In the post-training/inference stage, the tokens that really need to be calculated are selected based on the attention scores of the topk. Compared with StreamingLLM, H2O, and Quest, comprehensive and detailed experimental data on Wiki-2 PPL and Longbench show better accuracy, which indeed proves that the work is reliable.
summary: This work focuses on a issues in Sparse Self-Attention at post-training stage and proposes the double sparsity from both token-level and channel-level based on previous observations. It uses two mechanisms: (i) select important channels through offline calibration in CPU, and (ii) select specific tokens to compute attention score during runtime inference. Experiments show that both accuracy (PPL, long-context benchmark) and efficiency (kernel-level, e2e) outperforms SOTA sparse attention works and dense models.
weaknesses: 1. I’m curious about the resources and time required for the offline calibration phase in your preprocessing, specifically for a model like Llama-3.1-8B. Ideally, we would not want this process to consume too many resources or take too much time.

2. Could you elaborate on which open-source experiment the key-value retrieval benchmark is based on? Additionally, could you provide comparison results with the baseline and related works on the latest Needle in a Haystack (https://github.com/gkamradt/LLMTest_NeedleInAHaystack) and RULER (https://github.com/zhang677/RULER)?

3. It seems to me that the concept of channel-sparsity is quite similar to some ideas in AWQ and QServe, while token-sparsity reminds me of previous work like Quest. Could you explain in detail your advantages and improvements in these areas?

Meta-review: This paper introduces a "Double Sparsity" method for LLM efficiency by combining token and channel sparsity. While it shows promising results and practical gains, reviewers largely question its novelty and want more comparions with relevant baselines. The evaluation lacks tests on longer contexts and some popular benchmarks. Presentation also needs clarity, especially in notations and GPU details. Although one reviewer strongly supports the approach, the majority do not. Unfortuately, this leads to a rejection. In a future revision, aditional evaluations, clearer explanations, and stronger novelty claims are needed.

Decision: Reject