SnapKV: LLM Knows What You are Looking for Before Generation

Authors: yuhong  li
yingbing  huang
bowen  yang
bharat  venkitesh
acyr  locatelli
hanchen  ye
tianle  cai
patrick  lewis
deming  chen
  cohere
Venue: NeurIPS_cc_2024_Conference
Published: 2024-05-15 17:38:09

Abstract: Large Language Models (LLMs) have made remarkable progress in processing extensive contexts, with the Key-Value (KV) cache playing a vital role in enhancing their performance. However, the growth of the KV cache in response to increasing input length poses challenges to memory and time efficiency. To address this problem, this paper introduces SnapKV, an innovative and fine-tuning-free approach that efficiently minimizes KV cache size while still delivering comparable performance in real-world applications.

We discover that each attention head in the model consistently focuses on specific prompt attention features during generation. Meanwhile, this robust pattern can be obtained from an `observation' window located at the end of the prompts. Drawing on this insight, SnapKV automatically compresses KV caches by selecting clustered important KV positions for each attention head. Our approach significantly reduces the growing computational overhead and memory footprint when processing long input sequences. Specifically, SnapKV achieves a consistent decoding speed with a 3.6x increase in generation speed and an 8.2x enhancement in memory efficiency compared to baseline when processing inputs of 16K tokens. At the same time, it maintains comparable performance to baseline models across 16 long sequence datasets. Moreover, SnapKV can process up to 380K context tokens on a single A100-80GB GPU using HuggingFace implementation with minor changes, exhibiting only a negligible accuracy drop in the Needle-in-a-Haystack test. Further comprehensive studies suggest SnapKV's potential for practical applications.

Main paper: 
 introduction: 
 Many leading LLMs have started to handle longer contexts, overcoming the difficulties in context maintenance and attention mechanism scalability, such as GPT-4 [1] and Command-R [2] with context length 128K, Claude-3 [3] with 200K, and Gemini-Pro-1.5 with 1M [4] . Despite their impressive capabilities, LLMs still face significant challenges when dealing with long context prompts. Specifically, the KV cache in attention calculation becomes less efficient when processing long context. During inference time, as prompt length increases, the decoding latency per step grows linearly due to the attention calculation across past KVs. Moreover, the large KV cache requires significant memory capacity, increasing hardware demands and limiting model scalability. x "Snap" ! Figure 1 : The graph shows the simplified workflow of SnapKV, where the orange area represents the cluster of features per head selected by SnapKV. These features are then used to form new Key-Value pairs concatenated with the features in the observation window. Together, the selected prefix and observation windows constitute the new KV cache utilized for the generation.There are many approaches to mitigate these problems, such as KV cache eviction during generation stage [5] [6] [7] [8] . However, most of these methods lack a detailed evaluation in long-context settings. Moreover, they mainly focus on compressing the KV cache appended during decoding steps, while overlooking the realistic problem of compressing KV cache for prompts, which is typically the bottleneck in memory efficiency. In practical applications like chatbots and agents, where prompts range from multi-turn conversations to extensive articles or codebases [1, [9] [10] [11] , prompts are often much larger than generated responses such as summaries and code pieces, thus creating significant inference latency and memory utilization overhead. Additional challenge lies in compressing KV cache for such vast prompts without losing crucial information for accurate generation, especially in scenarios with various noisy contexts.In our paper, we find an vital attention allocation phenomenon: only a subset of prompt tokens convey essential information for response generation, and these tokens remain unchanged during generation. To validate the robustness, we design extensive experiments across diverse prompts in terms of length, format, and content. From our observations, we derive an innovative and intuitive method, SnapKV, which can smartly identify the attention allocation pattern and compress the KV cache for long sequence prompts without compromising the model's accuracy. With its comprehensive design, SnapKV demonstrates its effectiveness on various datasets and can be easily integrated into popular deep-learning frameworks with just a few code adjustments. Our contributions are as follows:• We design experiments to explore the attention allocation pattern during generation, focusing on two key questions:1. Is there a consistent attention allocation pattern for input sequence tokens? 2. Is it feasible to identify this pattern prior to the generation stage?Our finding suggests that for LLMs, the attention allocation of most input sequence tokens stay consistent during generation. Thus, LLMs knows what you are looking for before generation.• Inspired by our observations above, we develop an efficient and fine-tuning-free algorithm, SnapKV, which efficiently identifies critical attention features and compresses KV cache correspondingly with minimal model modification (See Fig. 1 ).• We evaluate SnapKV across diverse LLMs and long-sequence datasets. SnapKV shows comparable accuracy with full KV caching method while achieving improved decoding speed and memory efficiency. Meanwhile, we conduct the pressure test with Needle-in-a-Haystack to further demonstrate its memory efficiency and information retrieval ability. 
related works: 
 Many previous works compress the KV cache by selectively dropping KVs using different algorithms.In StreamLLM [5] , only the most recent tokens and attention sinks (first few tokens) are retained to reduce the KV cache size, making it lose the important information carried by the discarded middle tokens 2 . Heavy-Hitter Oracle (H2O) [6] introduces a policy that greedily drops KVs during generation based on a scoring function derived from cumulative attention. While this approach effectively compresses the KVs appended to the cache during generation, it overlooks compression of prompt KVs, which is crucial for reducing memory and computational overhead. Building on a similar concept, Adaptive KV Compression (FastGen) [8] implements a dual-phase algorithm that encompasses four KV cache compression policies. Initially, it identifies optimal policies through profiling results obtained from prompt encoding. Subsequently, it dynamically evicts caches during the generation phase based on these policies. Nonetheless, it faces the similar problem with H2O. ScissorHands [7] focuses on identifying and retaining pivotal tokens that exhibit a consistent attention weight pattern with previous token windows during generation steps. However, this method concentrates solely on the window of previous pivotal tokens in generation and neglects the extensive prompt that contains essential information for generating accurate responses. This oversight could lead to an inability to extract detailed information from prompts.In summary, existing methods have not effectively addressed the challenges encountered in realworld applications, where prompts are exceptionally long yet require accurate information retrieval. Although these techniques may reduce the KV cache size during generation, they do not address the primary challenges of understanding complex prompt contexts, leaving critical issues unresolved.Question: Does the paper discuss the limitations of the work performed by the authors?Answer: [Yes] Justification: we discuss the limitations and future directions in conclusion Sec. 6Guidelines:• The answer NA means that the paper has no limitation while the answer No means that the paper has limitations, but those are not discussed in the paper.• The authors are encouraged to create a separate "Limitations" section in their paper.• The paper should point out any strong assumptions and how robust the results are to violations of these assumptions (e.g., independence assumptions, noiseless settings, model well-specification, asymptotic approximations only holding locally). The authors should reflect on how these assumptions might be violated in practice and what the implications would be.• The authors should reflect on the scope of the claims made, e.g., if the approach was only tested on a few datasets or with a few runs. In general, empirical results often depend on implicit assumptions, which should be articulated.• The authors should reflect on the factors that influence the performance of the approach. For example, a facial recognition algorithm may perform poorly when image resolution is low or images are taken in low lighting. Or a speech-to-text system might not be used reliably to provide closed captions for online lectures because it fails to handle technical jargon.• The authors should discuss the computational efficiency of the proposed algorithms and how they scale with dataset size.• If applicable, the authors should discuss possible limitations of their approach to address problems of privacy and fairness.• While the authors might fear that complete honesty about limitations might be used by reviewers as grounds for rejection, a worse outcome might be that reviewers discover limitations that aren't acknowledged in the paper. The authors should use their best judgment and recognize that individual actions in favor of transparency play an important role in developing norms that preserve the integrity of the community. Reviewers will be specifically instructed to not penalize honesty concerning limitations. 
observations: 
 In this section, we present our observations regarding the attention allocation patterns in the Query-Key matrix during token generation. Our analysis utilizes samples from Ultrachat [12] , a multi-turns, high-quality instruction dataset consisting of 1.4 million dialogues. We further filter the sequences with response length greater than 512 and prompt length greater than 3k. Our findings are concluded into two key observations as follows:• Pattern can be identified before generation. In this experiment, we split the attention features of input sequence of each layer into multiple windows, each with 128 tokens, and calculate the averaged attention weights of the last 20 windows separately. To understand the attention allocation patterns along input sequences, we calculate the overlap rates between important attention features of input sequence (those with high average attention weights) identified by each window and the actual ones used by generation. The experimental results are shown in Fig. 2 .We observe that the last window of input sequence recognizes highly similar attention allocation pattern with the actual generation.• Pattern is consistent during generation. We study if the positions of features identified as crucial in the last window of input sequence maintain their significance in the subsequent token generation. In the experiment, we split the generated tokens into 4 windows for every layer, each spanning 128 tokens, to compute the averaged overlap rates of these windows versus the last window of input sequence. As shown in Fig. 3 , active attention features of input sequence obtained from the last window exhibit remarkable consistency throughout the generation process, as evidenced by high overlap rates.Question: For each theoretical result, does the paper provide the full set of assumptions and a complete (and correct) proof?Answer: [NA] Justification: we do not include any theoretical results in this paper.Guidelines:• The answer NA means that the paper does not include theoretical results.• All the theorems, formulas, and proofs in the paper should be numbered and crossreferenced.• All assumptions should be clearly stated or referenced in the statement of any theorems.• The proofs can either appear in the main paper or the supplemental material, but if they appear in the supplemental material, the authors are encouraged to provide a short proof sketch to provide intuition.• Inversely, any informal proof provided in the core of the paper should be complemented by formal proofs provided in appendix or supplemental material.• Theorems and Lemmas that the proof relies upon should be properly referenced. 
snapkv: 
 In the attention mechanism, the growth in prompts will significantly increase time complexity for generation due to the Query-Key matrix multiplication. SnapKV addresses this issue by maintaining a constant amount of prompt KVs during generation, significantly reducing serving times for longcontext LLMs. To structure our method coherently, we propose the following terminologies:• Prompt Length (L prompt ): The total length of the user-provided input.• Observation Window (L obs ): The last segment of the prompt. This window is crucial for analyzing the influence of different contexts on attention allocation patterns. • Prefix Length (L prefix ): The length of the input preceding the observation window. It is part of the prompt and does not include the observation window. Overall, we have:EQUATION• Voting: The process of calculating attention weights for each query within the observation window across all heads, aggregating these weights to highlight the prefix positions that are considered most significant. For a single batch of sequence, formally:EQUATIONEQUATIONwhere Top k (C, k) selects the indices I of the top k values in tensor C per head. k is defined as ⌊(1p) × L prefix ⌋, where p stands for the compression rate. The tensor W obs ∈ R N ×Lobs×Lprefix represents the subset of the prompt softmax-normalized attention features over N heads. • Hit Rate: We define attention features above a predefined threshold θ during generation as important features. The hit rate, H, is the number of important features successfully selected by the previous voting process over the total number of important features. H quantifies the effectiveness of the voting mechanism and is calculated as follows:EQUATIONEQUATIONA cur ∈ R N ×Lprefix represents the attention features between the current generated query and prefix keys. M selects attention features by indices. The threshold operation filters A cur to retain only features with values over θ, indicating important attention activations. The O measures the overlap between attention features selected by M threshold_cur and M vote_obs , quantifying the alignment of the current attention with previously identified important features. The hit rate H is then computed as the ratio of the sum of overlap O to the sum of important features M threshold_cur , providing a metric for the efficacy of the attention mechanism in recognizing and emphasizing important attention features within the context. We use H(M threshold_cur , M vote_obs ) to denote combination of Eq. 7 and Eq. 8.The core approach of SnapKV involves identifying and selecting the most crucial attention features per head to create the compressed KV cache. Listing 1 shows the PyTorch-style pseudo code of SnapKV. Overall, SnapKV operates through two stages as follows:• Vote for important previous features. By the voting process defined above (Eq. 2), we select the important attention features based on the observation window. Sec. 3 highlights the consistency of the attention allocation pattern within observation windows throughout the generation, suggesting that these selected attention features are also vital for subsequent generation. Furthermore, we implement clustering to retain the features surrounding the selected attention features (Sec. 4.3). Line 8-17 shows the pseudo code of the voting process.• Update and store compressed keys and values. We concatenate the selected attention features with all features within the observation window, which encompasses all features containing the necessary prompt information. Line 18-24 shows the compressing process. The concatenated KVs are stored for later use in generation, thereby saving memory usage. To understand the robustness of the observation window-based algorithm, we analyze its hit rate on multiple long documents QA datasets including QMSum [13] , a query-based multi-domain meeting summarization; Openreview [14] , a collection of papers from openreview.net; SPACE [15] , an extractive opinion summarization in quantized transformer spaces. The model we probe is Mistral-7B-Instruct-v0.2. Overall, we want to answer the following two questions:1. Does the nature of instructions in the prompt affect the hit rate? 2. Does the context and instruction positioning affect the hit rate?We analyze whether instructions will affect the selection of important features even if the provided context is the same. Our experiment utilizes different instructions on the same document and selects the important features based on the observation window that consists of both the instructions and their corresponding responses. Then we calculate the hit rates between important features selected by different instruction-response pairs (A, B) within the same document by using H(M vote_A , M vote_B ) Hit rate (%) as previously defined. By varying the instructions, we observe that different instructions prioritize different prefix attention features, as indicated by the descending trend in hit rates shown in Fig. 4 .Our findings reveal an interesting aspect of KV cache in LLMs: the important attention features change with different instructions. This variability challenges the effectiveness of static compression methods that depend on constant weighted importance or fixed policies [7, 6, 8] . Thus, the complex relationship between context and related KV cache emphasizes the need for context-aware compression strategies and highlights the capability of SnapKV that recognizes this dynamic. In contrast, context-independent compression fail in capturing the dynamic, resulting in a misalignment between the attention distribution during profiling and inference, diminishing the generation quality of LLMs.Our analysis also extends to the significance of instruction positioning on the interpretability of LLMs and their selection of important features. We calculate the average hit rate for the responses using the same observation window size as in the previous experiment. Our results shown in Fig. 5 indicate that across all three datasets, the hit rates are consistently high regardless of whether instructions are positioned before or after extensive supplementary contexts. This consistency suggests that SnapKV is able to identify attention allocation patterns regardless of the question's positions.In LLMs, information retrieval and generation rely on features with high attention weight and are supplemented by copying the rest of features in context using induction heads [16] . Hence, naively selecting the top features results in retaining only portions of details and then losing the completeness of the information. For example, such compression might cause the LLMs to retrieve only the country code of a phone number and hallucinate the rest. Our experiment also revealed that only selecting the features with the highest weights is insufficient (Sec. 5.2). Such sparse selection risks compromising HuggingFace implementation with only a few lines of code changed. The x-axis denotes the length of the document (the "haystack") from 1K to 380K tokens; the y-axis indicates the position that the "needle" (a short sentence) is located within the document. For example, 50% indicates that the needle is placed in the middle of the document. Here LWMChat with SnapKV is able to retrieve the needle correctly before 140k and with only a little accuracy drop after. Meanwhile, the original implementation encounters OOM error with 33k input tokens (white dashed line).the contextual integrity encapsulated in between features, thereby reducing accuracy. Based on the insights, we propose a fine-grained clustering algorithm utilizing a pooling layer shown in Line 13.Question: Does the paper fully disclose all the information needed to reproduce the main experimental results of the paper to the extent that it affects the main claims and/or conclusions of the paper (regardless of whether the code and data are provided or not)?Answer: [Yes]Justification: we include needed experiment details in Sec. 5Guidelines:• The answer NA means that the paper does not include experiments.• If the paper includes experiments, a No answer to this question will not be perceived well by the reviewers: Making the paper reproducible is important, regardless of whether the code and data are provided or not.• If the contribution is a dataset and/or model, the authors should describe the steps taken to make their results reproducible or verifiable.• Depending on the contribution, reproducibility can be accomplished in various ways. For example, if the contribution is a novel architecture, describing the architecture fully might suffice, or if the contribution is a specific model and empirical evaluation, it may be necessary to either make it possible for others to replicate the model with the same dataset, or provide access to the model. In general. releasing code and data is often one good way to accomplish this, but reproducibility can also be provided via detailed instructions for how to replicate the results, access to a hosted model (e.g., in the case of a large language model), releasing of a model checkpoint, or other means that are appropriate to the research performed.• While NeurIPS does not require releasing code, the conference does require all submissions to provide some reasonable avenue for reproducibility, which may depend on the nature of the contribution. For example , with an open-source dataset or instructions for how to construct the dataset). (d) We recognize that reproducibility may be tricky in some cases, in which case authors are welcome to describe the particular way they provide for reproducibility.In the case of closed-source models, it may be that access to the model is limited in some way (e.g., to registered users), but it should be possible for other researchers to have some path to reproducing or verifying the results. 
experiments: 
 In our experimental setup, we explore the performance of SnapKV across models that can handle extended prompt sequence contexts. First, we deliver a pressure test and benchmark the speed of LWM-Text-Chat-1M [17] , which is state-of-the-art regarding its context length. We then conduct an ablation study on Mistral-7B-Instruct-v0.2 to understand the influence of pooling on the model's information retrieval performance. We assess model performances using the LongBench [18] dataset. Further experiments on compatibility with other acceleration strategies, such as parallel decoding [19] , are elaborated in Appendix A. To assess the overhead of SnapKV during the prefilling stage, we present time and memory analysis results in Appendix B.LWM-Text-Chat-1M [17] is a 7B instruction-fine-tuned model with up to one million context length. In this section, we conduct a pressure test on this model and examine its algorithmic efficiencies.The Needle-in-a-Haystack test [20] challenges the model to accurately retrieve information from a specific sentence ("needle") concealed within an extensive document (the "haystack"), with the sentence placed at a random location. Typically, sentences that are inserted in the middle of prompts are harder to retrieve. To rigorously evaluate SnapKV's capabilities, we extended the document length to 380k tokens which is the longest content that can be processed by a single A100-80GB GPU. We configured the prompt KV cache size to 1024, enabling SnapKV to select the most crucial 1024 attention features from the prompt for answer generation, with a maximum pooling kernel size of 5 and an observation window size of 16, both of which are hyperparameters that can be customized. The compelling outcomes in Fig. 6 from the Needle-in-a-Haystack test underscore SnapKV's potential to precisely manage small details on extremely long input contexts with a 380x compression ratio. We further benchmark the speed of LWM-Text-Chat-1M under different batch-size settings using SnapKV. We set the maximum KV cache size as 2048 for SnapKV, and fix the generation length at 512 to ensure a fair comparison. There are two main takeaways from our experiment on decoding speed and prompt sequence length on various batch sizes, as shown in Fig. 7 . First, as the input sequence length increases, the decoding latency of the baseline implementation escalates linearly. Conversely, the SnapKV-optimized model maintains a constant decoding speed since the compressed KV cache size of prompt stays the same regardless of input sequence length and there is no extra update during the inference. For instance, at a sequence length of 16k and a batch size of 2, the decoding time for the baseline model surpasses 100 ms, whereas for SnapKV-optimized model, the decoding time consistently remains below 40 ms, achieving approximately a 3.6x speedup. Second, with the same batch size, the model integrated with SnapKV can decode significantly longer sequences. For example, at a batch size of 2, the baseline model encounters an OOM error beyond 16k input tokens, whereas the SnapKV-enhanced model extends this limit to 131k input tokens, indicating an approximately 8.2x improvement. This demonstrates SnapKV's effectiveness in minimizing memory consumption.We perform an ablation study on Mistral-7B-Instruct-v0.2 to assess the impact of our pooling technique, a straightforward but efficient method for consolidating information through clustering. Our evaluation utilizes the modified LongEval-Lines benchmark [21] , incorporating randomly generated pairs and averaged scores. LongEval-Lines presents a greater challenge compared to Needle-in-a-Haystack because it involves identifying key-value pairs in noisy contexts of the same format, while in Needle-in-a-Haystack, the relevant information is more distinctly separated from other contexts. We apply max pooling with a kernel size of 5 and use the observation window with a size of 16, which are hyperparameters and could be customized according to different models. As illustrated in our results (Fig. 8 ), we find that pooling significantly enhances retrieval accuracy compared to methods not utilizing pooling. We hypothesize that this is because the initial portions of critical token clusters are weighted higher by attention mechanisms. Typically, large language models tend to copy the tokens surrounding the initial portions to keep the contextual integrity. However, naively compressed KV cache breaks this mechanism and could lead to partially correct results (Fig. 8 ). Note that throughout our experiments, the choice between max pooling and average pooling did not yield significant differences in performance.We evaluate SnapKV on these four models using LongBench [18] , a multi-task benchmark designed to rigorously evaluate long context understanding capabilities across various datasets, spanning single and multi-document QA, summarization, few-shot learning, synthetic tasks, and code completion.The average prompt length of LongBench ranges from 5k to 7k, and more details can be found in Appendix D. We choose LWM-Text-Chat-1M with 1 million context length, LongChat-7b-v1.5-32k, Mistral-7B-Instruct-v0. results also indicate the effectiveness of SnapKV in compressing the prompt KV cache. For these 4 models, the average input token length is around 13k. Thus, using 1024, SnapKV achieves an average compression rate of 92%, and using 4096, it reaches 68%, all with negligible drops in accuracy. We compare SnapKV and H2O on the LongBench dataset to further demonstrate the performance of SnapKV. To fairly evaluate the accuracy, we set the prompt capacity for H2O to 4096. As Table 1 shows, SnapKV delivers significantly better performance than H2O. Even with 1024 prompt KV caches, SnapKV on Mistral-7B-Instruct-v0.2 achieves better performance than H2O with 4096 caches on 11 out of 16 benchmarks.In SnapKV, we introduce two key hyperparameters: observation window size and pooling kernel size. To further assess the robustness of our method, we perform a sensitivity analysis on Mistral-7B-Instruct-v0.2 with these hyperparameters using the LongBench dataset. As shown in Table 2 , different configurations yield the best score across various types of tasks, with no single configuration consistently outperforming others. This indicates that SnapKV demonstrates robustness across a range of configurations.Additionally, to better understand the effectiveness of the pooling strategy, we conduct an experiment with a kernel size of 1, representing a configuration without pooling. This analysis focuses primarily on non-retrieval tasks, complementing the retrieval task results in Sec. 5.2. The findings indicate that, in eight out of nine tasks, the model accuracy with pooling exceeds that of configurations without pooling, underscoring the importance of pooling in SnapKV.Question: Does the paper provide open access to the data and code, with sufficient instructions to faithfully reproduce the main experimental results, as described in supplemental material?Answer: [Yes]Justification: we provide psudo code in Listing. 1 to implement SnapKV and include needed experiment details in Sec. 5Guidelines:• The answer NA means that paper does not include experiments requiring code.• Please see the NeurIPS code and data submission guidelines (https://nips.cc/ public/guides/CodeSubmissionPolicy) for more details.• While we encourage the release of code and data, we understand that this might not be possible, so "No" is an acceptable answer. Papers cannot be rejected simply for not including code, unless this is central to the contribution (e.g., for a new open-source benchmark).• The instructions should contain the exact command and environment needed to run to reproduce the results. See the NeurIPS code and data submission guidelines (https: //nips.cc/public/guides/CodeSubmissionPolicy) for more details.• The authors should provide instructions on data access and preparation, including how to access the raw data, preprocessed data, intermediate data, and generated data, etc.• The authors should provide scripts to reproduce all experimental results for the new proposed method and baselines. If only a subset of experiments are reproducible, they should state which ones are omitted from the script and why.• At submission time, to preserve anonymity, the authors should release anonymized versions (if applicable).• Providing as much information as possible in supplemental material (appended to the paper) is recommended, but including URLs to data and code is permitted. 
discussions: 
 SnapKV is an effective yet straightforward solution that compresses the KV cache to mitigate the computational and memory burdens of processing extensive prompts. Observing that specific tokens within prompts gain consistent attention from each head during generation, our methodology not only retrieve crucial information but also enhances processing efficiency. Despite its strengths, SnapKV's scope is primarily confined to the generative aspect of models, specifically targeting the KV cache during the generation. This limitation implies that SnapKV cannot extend a model's long context capability if the model inherently struggles with long contexts or exhibits poor performance. Additionally, SnapKV's design does not cover the processing of the prompt inference, which limits its effectiveness in scenarios where the system cannot handle prompts of extensive length. Nonetheless, our contributions offer significant insights and tools for the community, paving the way for more refined approaches on managing the challenges of large-scale language modeling. The appendix provides more experiments with parallel decoding and the discussion about generation speedup.In this section, we provide a novel perspective on employing KV cache compression synergistically with parallel decoding [23] [24] [25] [26] [27] . Parallel decoding leverages a lightweight model or an adaptor to draft initial tokens, which are subsequently verified by larger LLMs. This strategy effectively reduces memory overhead, a critical concern given the autoregressive nature of LLMs that renders them more memory-intensive than computationally demanding. Specifically, in LLMs, each decoding step involves generating a single token, with the transfer of weights between High Bandwidth Memory (HBM) and cache contributing to significant overhead [28, 29] .Our investigation incorporates SnapKV with Medusa [19]3 , a cutting-edge parallel decoding framework that utilizes multiple classifiers and tree attention mechanisms for drafting tokens, subsequently verified by LLMs. One of the challenges identified is the issue of speculative decoding in processing long sequences since generating multiple tokens per decoding step introduces computational bottlenecks during long sequence processing, such as query-key matrix multiplication tiling [30] . By maintaining a constant size for the KV cache associated with prompts during generation, SnapKV enhances generation efficiency.Empirical results shown in Figure 9 highlight the performance across various prompt lengths, with Mistral-7B-Instruct-v0.24 undergoing a maximum of 128 generation steps unless preemptively halted. The experiments utilized a subset of the QASPER [31] , with a fixed prompt instructing the LLM to summarize the paper. The truncation strategy adopted aligns with LongBench [18] standards, by removing the context in the middle to achieve the desired sequence length for benchmarking.The findings indicate a slowdown in Medusa's performance as sequence lengths extend, a challenge effectively mitigated by SnapKV's intervention, which achieved a 1.3x speedup for sequences with 10k length compared to Medusa and a 2.2x speedup compared to the native decoding. This improvement underscores the potential of combining KV cache compression with parallel decoding frameworks to enhance LLM efficiency, particularly in long-context scenarios. We evaluate the prefilling time and memory usage on Mistral-7B-Instruct-v0.2 with input sequence lengths ranging from 5k to 45k in Fig. 10 . The results show no overhead in either aspect. SnapKV only introduces extra top-k and pooling operations which are trivial regarding computation complexity compared with original prefilling calculations. To better assess SnapKV's effectiveness across different stages, we documented a detailed time breakdown for Mistral-7B-Instruct-v0.2 during both the prompting and generation stages. We configured the model to consistently generate 512 tokens, facilitating a direct comparison with the prompting stage. As illustrated in Fig. 11 , generation time dominates the whole processing time for LLMs over input sequences, introducing significant overhead. While the generation time for the original model increases with input length, SnapKV maintains a consistent decoding speed regardless of input length, significantly reducing generation time. Especially, SnapKV is able to achieve balanced prompting time and generation time with input length smaller than 100k. Here we provide more statistical information on LongBench in Table 3 to provide more insights on our results in 5.3. Israel hasn't had the time to sew anything. Autumn encourages Israel to prioritize in life. There will be photos of the dress on the site soon. Israel is excited to see it.Autumn has sewn a dress and hasn't shown it to Israel yet. Israel hasn't had the time to sew anything. Autumn encourages Israel to prioritize in life. There will be photos of the dress on the site soon. Israel is excited to see it.You are given a scientific article and a question. Answer the question as concisely as you can, using a single phrase or sentence if possible. If the question cannot be answered based on the information in the article, write "unanswerable". If the question is a yes/no question, answer "yes", "no", or "unanswerable". Do not provide any explanation.[ Characterizing Political Fake News in Twitter by its Meta-DataJulio Amador Díaz LópezAxel Oehmichen Miguel Molina-Solana( j.amador, axelfrancois.oehmichen11, mmolinas@imperial.ac.uk ) Imperial College London This article presents a preliminary approach towards characterizing political fake news on Twitter through the analysis of their meta-data.In particular, we focus on more than 1.5M tweets collected on the day of the election of Donald Trump as 45th president of the United States of America. We use the meta-data embedded within those tweets in order to look for differences between tweets containing fake news and tweets not containing them.…… Question: How is the ground truth for fake news established?Answer:The ground truth for fake news is not claimed in the article.The ground truth for fake news is not claimed in the article as the categorization is far from perfect due to the ambiguity of fake news and human judgement involved in the process.The dataset is not claimed to be a ground truth due to the ambiguity of fake news and human judgement involved in the categorization process.The dataset is not claimed to be a ground truth due to the ambiguity of fake news and human judgement involved in the categorization process.SnapKV: 2048SnapKV: 1024Answer the question based on the given passages. Only give me the answer and do not output any other words.The following are given passages. Passage 1: List of Unbreakable Kimmy Schmidt episodes Unbreakable Kimmy Schmidt is an American sitcom created by Tina Fey and Robert Carlock, starring Ellie Kemper in the title role, that has streamed on Netflix since March 6, 2015. Originally set for a 13-episode first season on NBC for spring 2015, the show was sold to Netflix and given a two-season order. The fourth and final season concluded on January 25, 2019. On May 8, 2019, it was announced that the series would return with an interactive special, which premiered on May 12, 2020. During the course of the series, 52 episodes of Unbreakable Kimmy Schmidt were released over four seasons. Ellie Kemper stars in the title role of Unbreakable Kimmy Schmidt.Ellie Kemper stars in the title role of Unbreakable Kimmy Schmidt.Ellie Kemper stars in the title role of Unbreakable Kimmy Schmidt. • The claims made should match theoretical and experimental results, and reflect how much the results can be expected to generalize to other settings.• It is fine to include aspirational goals as motivation as long as it is clear that these goals are not attained by the paper.Question: Does the paper specify all the training and test details (e.g., data splits, hyperparameters, how they were chosen, type of optimizer, etc.) necessary to understand the results?Answer: [Yes] Justification: for every experiment, we mention all the needed details in Sec. 5Guidelines:• The answer NA means that the paper does not include experiments.• The experimental setting should be presented in the core of the paper to a level of detail that is necessary to appreciate the results and make sense of them.• The full details can be provided either with the code, in appendix, or as supplemental material. 
experiment statistical significance: 
 Question: Does the paper report error bars suitably and correctly defined or other appropriate information about the statistical significance of the experiments?Answer: [Yes] Justification: all experiments detailed results are included in Sec. 5Guidelines:• The answer NA means that the paper does not include experiments.• The authors should answer "Yes" if the results are accompanied by error bars, confidence intervals, or statistical significance tests, at least for the experiments that support the main claims of the paper.• The factors of variability that the error bars are capturing should be clearly stated (for example, train/test split, initialization, random drawing of some parameter, or overall run with given experimental conditions).• The method for calculating the error bars should be explained (closed form formula, call to a library function, bootstrap, etc.)• The assumptions made should be given (e.g., Normally distributed errors).• It should be clear whether the error bar is the standard deviation or the standard error of the mean.• It is OK to report 1-sigma error bars, but one should state it. The authors should preferably report a 2-sigma error bar than state that they have a 96% CI, if the hypothesis of Normality of errors is not verified.• For asymmetric distributions, the authors should be careful not to show in tables or figures symmetric error bars that would yield results that are out of range (e.g. negative error rates).• If error bars are reported in tables or plots, The authors should explain in the text how they were calculated and reference the corresponding figures or tables in the text. 
experiments compute resources: 
 Question: For each experiment, does the paper provide sufficient information on the computer resources (type of compute workers, memory, time of execution) needed to reproduce the experiments?Answer: [Yes] Justification: we mention computer resources we use for experiments and provide the memory and latency information, which could all be found in Sec. 5Guidelines:• The answer NA means that the paper does not include experiments.• The paper should indicate the type of compute workers CPU or GPU, internal cluster, or cloud provider, including relevant memory and storage.• The paper should provide the amount of compute required for each of the individual experimental runs as well as estimate the total compute.• The paper should disclose whether the full research project required more compute than the experiments reported in the paper (e.g., preliminary or failed experiments that didn't make it into the paper). 
code of ethics: 
 Question: Does the research conducted in the paper conform, in every respect, with the NeurIPS Code of Ethics https://neurips.cc/public/EthicsGuidelines?Justification: we keep all information credential and strictly follow the NeurIPS Code of Ethics.Guidelines:• The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.• If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics.• The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction). 
broader impacts: 
 Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed?Answer: [Yes] Justification: we discuss the contribution and weakness in discussion Sec, 6Guidelines:• The answer NA means that there is no societal impact of the work performed.• If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact.• Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations.• The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster.• The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology.• If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML). 
safeguards: 
 Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)?Answer: [NA] Justification: we do not release any new models or datasets in the paper.Guidelines:• The answer NA means that the paper poses no such risks.• Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters.• Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images.• We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort.12. Licenses for existing assets Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?Answer: [Yes]Justification: we credit all mentioned assets in reference Guidelines:• The answer NA means that the paper does not use existing assets.• The authors should cite the original paper that produced the code package or dataset.• The authors should state which version of the asset is used and, if possible, include a URL.• The name of the license (e.g., CC-BY 4.0) should be included for each asset.• For scraped data from a particular source (e.g., website), the copyright and terms of service of that source should be provided.• If assets are released, the license, copyright information, and terms of use in the package should be provided. For popular datasets, paperswithcode.com/datasets has curated licenses for some datasets. Their licensing guide can help determine the license of a dataset.• For existing datasets that are re-packaged, both the original license and the license of the derived asset (if it has changed) should be provided.• If this information is not available online, the authors are encouraged to reach out to the asset's creators. 
new assets: 
 Question: Are new assets introduced in the paper well documented and is the documentation provided alongside the assets?Answer: [NA]Justification: we provide a new algorithm that can be used on many existing models, and do not introduce any more assets.Guidelines:• The answer NA means that the paper does not release new assets.• Researchers should communicate the details of the dataset/code/model as part of their submissions via structured templates. This includes details about training, license, limitations, etc.• The paper should discuss whether and how consent was obtained from people whose asset is used.• At submission time, remember to anonymize your assets (if applicable). You can either create an anonymized URL or include an anonymized zip file. 
crowdsourcing and research with human subjects: 
 Question: For crowdsourcing experiments and research with human subjects, does the paper include the full text of instructions given to participants and screenshots, if applicable, as well as details about compensation (if any)?Answer: [NA] Justification: we do not include crowdsourcing nor research with human subjects. All are based on existing automatic evaluator and models.Guidelines:• The answer NA means that the paper does not involve crowdsourcing nor research with human subjects.• Including this information in the supplemental material is fine, but if the main contribution of the paper involves human subjects, then as much detail as possible should be included in the main paper.• According to the NeurIPS Code of Ethics, workers involved in data collection, curation, or other labor should be paid at least the minimum wage in the country of the data collector. 
institutional review board (irb) approvals or equivalent for research with human subjects: 
 Question: Does the paper describe potential risks incurred by study participants, whether such risks were disclosed to the subjects, and whether Institutional Review Board (IRB) approvals (or an equivalent approval/review based on the requirements of your country or institution) were obtained?Answer: [NA] Justification: we do not include crowdsourcing nor research with human subjects. All are based on existing automatic evaluator and models.Guidelines:• The answer NA means that the paper does not involve crowdsourcing nor research with human subjects.• Depending on the country in which research is conducted, IRB approval (or equivalent) may be required for any human subjects research. If you obtained IRB approval, you should clearly state this in the paper.• We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution.• For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review.https://github.com/mit-han-lab/streaming-llm?tab=readme-ov-file#faqhttps://github.com/FasterDecoding/MedusaTGI trained Medusa heads 
 
 Appendix:  


Decision: This paper discussed an important problem in improving the efficiency of long context inference. The solution is solid with good novelty, and the experimental section is well designed to verify the design of the proposed solution.

Reviews: review: paper_summary: paper_summary: The paper introduces a method for minimizing KV cache size in LLMs. The authors offer the insight that attention heads focus on specific prompt attention features (tokens and their feature representation) during generation. This pattern can be discovered via an observation window at the end of the prompt. The new method, SnapKV, compresses KV caches by selecting clustered important KV positions for each attention head. As a result, the computational overhead and memory footprint are significantly reduced for long inputs. The method is evaluated across various LLMs and datasets showing its efficiency in practical applications.
strength_weakness: strength_weakness: The impact on model accuracy for very long context (more than 100K tokens) is not thoroughly explored.
questions: questions: How sensitive is the method to the observation window size, or the pooling kernel size?
It would be useful to include some more details about the performance measures used in Table 1.
limitations: limitations: yes
paper_summary: paper_summary: This paper presents a training-free KV cache compression approach. This approach builds off of the observation that the model consistently focuses on particular features during generation, and that these features can be detected when the prompt is passed in. Their approach uses a small “observation window” of queries at the end of the prompt to detect which previous keys must be retained, and then prunes out other key / value pairs. They also incorporate a pooling-based approach in order to maintain contextual information around important tokens. Through these methods, they attain generation speedups and reduced memory consumption for long context length tasks, while maintaining accuracy.
strength_weakness: strength_weakness: - This paper doesn’t accelerate the prompt processing step (even though it is explicitly targeting long prompt processing), which could present a bottleneck for tasks with long input lengths and short generation lengths
- The paper lacks benchmarking experiments to justify that their approach doesn’t add any overheads to the prompt processing step (due to having to use the observation window to identify important tokens, which likely needs to be applied separately from FlashAttention)
- They do not provide sufficient justification for their pooling approach, and their ablations are insufficient to show its effectiveness (they show accuracy benefits on one task, but for other tasks with less sparse attention distributions than retrieval this may actually degrade performance by prioritizing less important tokens that are near important ones). It would be good to ablate the impacts of pooling on non-retrieval tasks as well (eg. few-shot ICL) which may have a flatter attention distribution, and where pooling may lead to retrieving less of the actual important information that is required.
questions: questions: - For Table 1, it would be good to also include the average input prompt sizes for the different tasks (in order to get a sense of the relative compression that is attained by going to fixed cache sizes of 1K, 2K, 4K)
limitations: limitations: Yes
paper_summary: paper_summary: This paper analyzes the issue of high storage pressure in KV caches within long-context scenarios and proposes a method for KV cache compression. Specifically, it calculates the attention weights between the last 16 Q tokens and K, and utilizes pooling and topK to determine the KV pairs to retain. The paper tests four models—LWM-1M, Mistral-32K, LongChat-32K, and Mixtral-32K—on two tasks, LongBench and Needle In A Haystack. The results show a 2% drop on the GovReport task and a reduction to 140K context on the Needle In A Haystack task, while in other tasks, the results are generally consistent with full attention. The decoding stage latency is reduced by 3.6x.
strength_weakness: strength_weakness: 1. The experimental section is limited, with tests conducted only on two benchmarks, making it difficult to demonstrate the method's generalizability and effectiveness. For the Needle In a Haystack task, only the results of LWM-1M with SnapKV are tested, lacking comparison with full attention, other baselines, and results from other models. Additionally, the tested context windows are relatively short, only up to 380K.
2. The paper uses a pooling method in the approximate stage and claims it is for more efficient pooling. However, Fig. 8 shows significant performance improvements with pooling, leading to doubts about whether the important Keys identified by the observation Query remain unchanged during the decoding stage, especially in retrieval tasks or tasks like Needle in the haystack.
questions: questions: 1. Do you have additional baseline results for the Needle In A Haystack test, such as those for H20 or the full-attention model?
2. Are there any results from more demanding long-context benchmarks, such as RULER[1] or InfiniteBench[2]? I am particularly curious about how SnapKV would perform on tasks akin to KV retrieval[2]. Furthermore, do you have experimental results from other, more capable long-context language models, such as Yi-200K[3] or LLaMA-3-1M[4]?
3. Have you conducted experiments on contexts longer than those reported, and if so, could you share those results?
4. Regarding the speedup data in Sec 5.1.2, are these results based on the vLLM freamwork? If not, could you provide results for vLLM, as they would more accurately reflect the degree of speedup improvement in real-world scenarios?
5. Typo: In Fig. 8, the right image's label "without" should be corrected to "with."

- [1] RULER: What’s the Real Context Size of Your Long-Context Language Models?
- [2] InfiniteBench: Extending Long Context Evaluation Beyond 100K Tokens
- [3] https://huggingface.co/01-ai/Yi-34B-200K
- [4] https://huggingface.co/gradientai/Llama-3-8B-Instruct-Gradient-1048k
limitations: limitations: Please refer to the weaknesses section.

Comments: title: Official Comment by Reviewer Akz1
Rebuttal Response
comment: Thanks for your valuable feedback. From the experiments, SnapKV with pooling performs better than without it in most cases, but indeed, various tasks require different configurations, including observation windows and pooling kernel sizes. We will continue refining our work and discuss this situation in future versions.
Thanks for your valuable feedback! We will continue refining our paper in the future version.
Thank you for your detailed response. I understand the motivation behind the pooling method; however, I remain skeptical about the fundamental reasons for the gains attributed to pooling. It would be beneficial to include more analysis in future versions. Overall, SnapKV represents an excellent piece of work in KV cache compression, with clear motivation and significant application potential. I have raised my score to 6.
Thank you for your work in your rebuttal.
- For the first question, the author's response clearly demonstrates that their approach doesn't add runtime overhead in the prefill phase.
- I also appreciate the inclusion of the average prompt sizes for each task, as this helps understand the compression achieved in each case.
- For the pooling ablation (Q2), the data does not seem as clear as suggested that the pooling approach yields consistent benefits. When compared with the configuration used in the paper, the average accuracy is actually higher for the configuration without pooling, and it does not seem like any of the configurations are consistently superior. I still feel that the benefits of pooling across a diverse range of tasks are unclear.