            CateKV: On Sequential Consistency for Long-Context LLM Inference
                                     Acceleration


    Haoyun Jiang 1 2 Haolin Li 3 Jianwei Zhang 2 Fei Huang 2 Qiang Hu 1 Minmin Sun 2 Shuai Xiao 2 Yong Li 2
                                          Junyang Lin 2 Jiangchao Yao 1


                             Abstract                                                   For all heads                                  For consistent heads
                                                                      Pre-filling                                               Pre-filling
          Large language models (LLMs) have demon-                        0.2   0.6   0.1   0.3   0.9    0.2                     0.2   0.6    0.1   0.3   0.9    0.2
          strated strong capabilities in handling long-
                                                                                              Evict KV pairs                                             Only retain
          context tasks, but processing such long contexts            Decoding
                                                                                                                                                      critical KV pairs
                                                                                                                                Decoding
          remains challenging due to the substantial mem-
                                                                                      KV cache          Query
          ory requirements and inference latency. In this
                                                                                (a) KV Eviction Algorithm                                    KV cache           Query
          work, we discover that certain attention heads ex-
          hibit sequential consistency in their attention pat-                          For all heads
                                                                      Decoding                                                          For adaptive heads
          terns, which can be persistently identified using a                                                                   Pre-filling

          coefficient-of-variation-based algorithm. Inspired                          KV cache                  Query            0.2   0.6    0.1   0.3   0.9    0.2
          by this observation, we propose CateKV, a hy-
                                                                                                                                                    Retain most KV
          brid KV cache method that retains only critical                             KV cache                          Query                            pairs
                                                                                                                                Decoding
          token information for consistent heads, thereby                       (b) KV Retrieval Algorithm

          reducing KV cache size and computational over-                 Context window             Observation window                        KV cache                 Query
          head, while preserving the majority of KV pairs                Evicted KV pairs           KV pairs for attention                      (c) Ours
          in adaptive heads to ensure high accuracy. We
          show the unique characteristics of our algorithm           Figure 1: Comparison of KV eviction, KV retrieval, and our
          and its extension with existing acceleration meth-         method. CateKV employs a hybrid KV cache method to
          ods. Comprehensive evaluations on long-context             reduce memory usage while maintaining high accuracy.
          benchmarks show that, while maintaining accu-
          racy comparable to full attention, CateKV reduces
          memory usage by up to 2.72× and accelerates                standing (Bairi et al., 2024; Jimenez et al., 2023). However,
          decoding by 2.18× in single-sample inputs, and             as context lengths grow, the autoregressive nature of the
          boosts throughput by 3.96× in batch scenarios.             mainstream LLM paradigm often leads to increased compu-
                                                                     tational costs, memory consumption, and thus the runtime,
                                                                     since we have to store and retrieve all key-value (KV) caches.
1. Introduction                                                      For example, using the Llama-3-8B-Instruct-262k (Gradient,
                                                                     2024b) model with FlashAttention, extending the context
With rapid development of large language models (LLMs),              from 1K to 1M tokens increases inference latency by over
many generalist models support context windows of 128K               3000 times (Jiang et al., 2024). Therefore, accelerating LLM
tokens or more (Achiam et al., 2023; Dubey et al., 2024;             inference in long contexts is both essential and imperative.
Bai et al., 2023a; GLM et al., 2024b; Team et al., 2023;
Abdin et al., 2024), enabling to effectively perform tasks           Existing methods for inference acceleration of LLMs under
like long-document question answering (Caciularu et al.,             long contexts can be categorized into two types: KV cache
2023; Wang et al., 2024), information retrieval (Zhang et al.,       eviction and KV cache retrieval strategies. KV eviction
2024a; Zhu et al., 2023), and repository-level code under-           strategies reduce the size of the KV cache by systematically
                                                                     discarding KV pairs based on predefined policies (Xiao
      1
    CMIC, Shanghai Jiao Tong University 2 Alibaba Group              et al., 2023; Zhang et al., 2023; Li et al., 2024; Cai et al.,
3
Fudan University.     Correspondence to: Jiangchao Yao               2024). However, this usually suffers from significant accu-
<sunarker@sjtu.edu.cn>, Shuai Xiao <shuai.xsh@gmail.com>.            racy loss, as the removal of essential information without
Proceedings of the 42 nd International Conference on Machine         comprehensive contextual understanding adversely affects
Learning, Vancouver, Canada. PMLR 267, 2025. Copyright 2025          task performance. In contrast, KV retrieval methods main-
by the author(s).                                                    tain accuracy by preserving all KV pairs in the cache and

                                                                 1
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

selectively retrieving relevant tokens during the decoding                • We identify that general sequential consistency exhibits
stage, thereby ensuring that no crucial information is omit-                in certain attention heads and dynamic activation in
ted (Tang et al., 2024b; Sun et al., 2024). Nevertheless,                   others, dividing the attention heads into consistent and
KV retrieval does not mitigate high memory usage, lim-                      adaptive heads, which naturally constructs the basic
iting scalable batch sizes and thus the throughput under                    for decoding acceleration with pre-filling experience.
long contexts. Furthermore, certain approaches (Jiang et al.,
                                                                          • We propose CateKV, a hybrid KV cache acceleration
2024; Xiao et al., 2024b; Tang et al., 2024a) recognize the
                                                                            algorithm leveraging sequential consistency. Employ-
heterogeneous sparsity patterns across different attention
                                                                            ing a coefficient-of-variation-based score, CateKV can
heads within the model and configure the heads with distinct
                                                                            precisely classify attention heads into two categories,
sparsification strategies during inference. While they show
                                                                            enabling efficient KV cache eviction while closely ap-
initial promise in accuracy and efficiency, they do not fully
                                                                            proximating the performance of full attention.
utilize the interplay between the pre-filling and decoding
phases to facilitate further optimization.                                • Extensive evaluations on popular benchmarks demon-
Different from previous methods, we explore leveraging                      strate that CateKV reduces memory usage and decod-
the experience in pre-filling stage to promote the decoding                 ing latency by 2.72× and 2.18× for single inputs, in-
stage. Specifically, our intuition is inspired by an interesting            creases throughput by 3.96× in batch scenarios, while
observation: certain attention heads exhibit sequentially                   maintaining performance comparable to full attention.
consistent attention patterns, spanning across the pre-filling              Further acceleration can be achieved by integrating our
and decoding stages, while some attention heads exhibit rich                plug-and-play method with other approaches.
activation dynamics during the whole process, as shown in
Figure 2. Besides, this phenomenon, reflecting the special             2. Related Work
head working mechanism, frequently existed in different
LLMs and their different layers. This indicates that if we             2.1. KV Cache Eviction Algorithm
can capture those modes at the pre-filling stage, we can               To save the significant time and space overhead as the in-
leverage the sequential consistency to only maintain a subset          put length increases, various approaches explore evicting
of crucial tokens for certain heads, which achieves both a             tokens to reduce both memory usage and computational
reduction of the KV cache and the speedup of attention                 cost. StreamingLLM (Xiao et al., 2023) introduces the phe-
computation during the decoding stage for LLM inference                nomenon of ”attention sink” and supports longer sequence
acceleration.                                                          by retaining only the KV pairs of attention sinks and recent
Based on the above analysis, we propose CateKV, a sim-                 tokens. H2O (Zhang et al., 2023) employs a low-cost evic-
ple, effective, and plug-and-play method designed to en-               tion strategy to maintain a fixed-size KV cache containing
hance LLM inference efficiency by leveraging sequential                heavy-hitters, based on the sum of historical attention scores.
consistency. CateKV uses an observation window during                  SnapKV (Li et al., 2024) uses the last tokens in the prompt
the pre-filling stage to identify critical tokens and employs          during the prefilling stage to select critical tokens for gener-
a coefficient-of-variation-based score to classify attention           ation in the decoding stage. PyramidKV (Cai et al., 2024),
heads into consistent and adaptive types, based on a ref-              PyramidInfer (Yang et al., 2024), and LazyLLM (Fu et al.,
erence dataset. In consistent heads, CateKV retains only               2024a) leverage attention distribution across layers to dy-
a small proportion of critical KV pairs, while in adaptive             namically adjust cache size, making cache allocation more
heads, it retains most, selecting tokens based on their impor-         efficient. Other methods like MagicPig (Chen et al., 2024),
tance derived from attention weights in the pre-filling stage,         Q-Hitter (Zhang et al., 2024b), ALISA (Zhao et al., 2024)
as shown in Figure 1. By such an effective routing manner              and , which combine KV cache eviction with quantization,
guided by sequential consistency, our method maintains the             hashing algorithms, or sparse windows, can also improve
performance merit of LLM inference and simultaneously                  inference efficiency. However, these methods induce non-
enjoys the acceleration gain. Our method is orthogonal to              negligible performance degradation, as they potentially evict
and combinable with many existing acceleration approaches,             certain tokens that are crucial for future generation.
and we conducted extensive experiments on widely used
benchmarks including RULER (Hsieh et al., 2024), Long-                 2.2. KV Cache Retrieval Algorithm
bench (Bai et al., 2023b), and NIAH (Kamradt, 2024), using             Unlike KV cache eviction algorithms, KV cache retrieval
models such as LLaMA-3-8B-Instruct-1048K (Gradient,                    algorithms retain a complete KV cache and dynamically
2024a), GLM-4-9B-1M (GLM et al., 2024a), LLaMA-3.1-                    retrieve important KV pairs to reduce inference latency. Fol-
8B (Meta AI, 2024) and Yi-9B-200K (AI et al., 2024) to                 lowing PageAttention (Kwon et al., 2023), Quest (Tang
demonstrate the effectiveness. In a nutshell, our contribu-            et al., 2024b) divides tokens into pages and devises an
tions are summarized as follows:                                       approximate attention score to retrieve the most relevant

                                                                   2
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

pages for the current decoding steps. InfLLM (Xiao et al.,                                  Layer 2 Head 30       Layer 10 Head 3    Layer 25 Head 18




                                                                        Pre-filling
2024a) adopts a strategy similar to Quest, offloading most
of the cache to the CPU to support longer prompts. Shad-
owKV (Sun et al., 2024) enhances the storage efficiency of




                                                                        Decoding
Quest by storing only low-rank key caches and offloading
value caches, allowing inference with large batch sizes and
context lengths. Others like SparQ (Ribar et al., 2023), In-
finiGen (Lee et al., 2024), and Loki (Singhania et al., 2024),                                                (a) Consistent head
                                                                                            Layer 6 Head 30       Layer 10 Head 18   Layer 22 Head 30
accelerate the selection of top-k critical tokens by reducing




                                                                      Pre-filling
the dimension. KV cache retrieval methods maintain per-
formance by preserving the entire KV cache but inevitably
incur increased inference latency and storage costs.




                                                                      Decoding
2.3. Head-wise Attention Classification
Another line of work classifies attention heads into distinct                                                 (b) Adaptive head
sparse patterns. MInference (Jiang et al., 2024) divides the
attention into A-shape, Vertical-Slash, and Block-Sparse              Figure 2: Visualization of attention weight heatmaps for
patterns, achieving acceleration during the pre-filling stage.        consistent heads and adaptive heads in the LongChat-7B
RazorAttention (Tang et al., 2024a) and DuoAttention (Xiao            model using a randomly selected text segment. In these
et al., 2024b) split heads into retrieval heads and streaming         figures, the vertical axis represents the attention of the head
heads to determine whether to implement full attention or             across different queries, with the first 20 rows corresponding
an attention mechanism similar to StreamingLLM (Xiao                  to the last 20 queries during the pre-filling stage, while
et al., 2023). Methods like AdaKV (Feng et al., 2024) and             the subsequent rows depict the attention weights across
HeadKV (Fu et al., 2024b) achieve more fine-grained clas-             consecutive decoding steps. These two types of heads exist
sification by allocating different budgets to each attention          in various layers and other popular models (Appendix A).
head. These methods focus on the features within individ-
ual heads or their variations, but overlook the patterns of
                                                                                      • Consistent heads are attention heads that exhibit stable
attention heads across the prefilling and decoding stages.
                                                                                        attention patterns of sequential consistency, focusing
                                                                                        on a limited set of tokens across all decoding steps.
3. Method
3.1. Sequential Consistency of Attention Heads                                        • Adaptive heads are attention heads characterized by
In this paragraph, we present an interesting observation                                variable attention distributions across decoding steps,
about the attention patterns across the pre-filling and de-                             which do not exhibit stable patterns and require a larger
coding stages. To illustrate this, we randomly selected a                               attention space for flexible token interactions.
text segment from Wikitext (Merity et al., 2016) as input
for the LongChat-7B (Li et al., 2023) model, examining
                                                                      3.2. How to Identify Consistent and Adaptive Heads?
how attention weights evolve throughout the generation pro-
cess. Figure 2 illustrates the attention heatmaps during the          Observation matrix As can be seen in Figure 2, the atten-
pre-filling and decoding stages for two types of attention            tion weights of the last query tokens at the pre-filling stage
heads. We observe that for certain attention heads, attention         effectively reflect the attention patterns. To save the com-
is concentrated on a few critical tokens, which show clear            putational cost, we set an observation window that contains
consistency across both the pre-filling and decoding stages.          the last query tokens of the input to identify head types and
This consistency allows us to identify critical tokens during         critical tokens. Additionally, since initial and recent tokens
the pre-filling stage, which can then guide the decoding              are typically important but do not influence the classification
process and help reduce computational costs. In contrast,             process, we temporarily exclude them during the identifi-
other attention heads exhibit attention distributions that vary       cation phase. Formally, let Linit , Lrec and Lobs respectively
significantly across decoding steps, maintaining a broader            denote the lengths of the initial tokens, recent tokens, and
attention scope without focusing on specific tokens at each           the observation window. Then, consider a head within a
step. For these heads, it is crucial to retain most of the KV         sample at the pre-filling stage, where the input includes the
pairs to ensure accurate predictions. For clarity, we provide         query Q, key K, and value V ∈ Rn×d , with n representing
the further claims for these two types of attention heads:            the input length and d representing the head dimension in
                                                                      the attention mechanism. We define the observation matrix

                                                                  3
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

                                                                                Algorithm 1 CateKV in an individual Head
                                                                                  Input: Q, K, V ∈ Rn×d , q ∈ R1×d , head type H, obser-
                                                                                  vation window size Lobs , selected chunk budget b, chunk
                                                                                  size cs, retention ratio η
                                                                                  Pre-filling Stage:
                                                                                  # Calculating token criticality          √
                                                                                                             T
                                                                                  A = softmax(Q[−Lobs :,:] K[:−L  obs ,:]
                                                                                                                          / d)
                                                                                  C= L
                                                                                       P obs
                                                                                         i=0 Ai,:
                                                                                  # Divide C into chunks and take maximum
                                                                                  Cchunk = BlockMax(C, cs)
                    (a)                                       (b)                 # Cache keys and values based on the indices of top-k elements
                                                                                  if H = consistent head then
Figure 3: (a) High similarity of classification results across                       ik = argtopk(Cchunk , b)
samples. We calculate the overlap rate between the classifi-                         cachek , cachev = Cache(K, V, ik , Lobs )
                                                                                  else
cation results of 200 randomly selected WikiText samples
                                                                                     ik = argtopk(Cchunk , nη)
and the overall classification result with r = 0.3. All sam-                         cachek , cachev = Cache(K, V, ik , Lobs )
ples exhibit an overlap rate exceeding 80% with the overall                       end if
result. (b) Frequency of adaptive head identification for                         Decoding Stage:
Llama-3B model in a reference dataset with r = 0.3. The                           # Retrieval keys and values from cache
frequency distribution is highly concentrated, enabling the                       if H = consistent head then
determination of a fixed head type based on these results.                           k, v = cachek , cachev
                                                                                  else
                                                                                     k, v = Retrival(q, cachek , cachev ) # all or query-aware
A within the observation window, as follows:
                                                                                  end if
                                                                                  output = Attention(q, k, v)
                                         T
                                                              !
                           Q[−Lobs :,:] K[L init :−Lrec ,:]
        A = softmax                     √                         ,   (1)
                                            d
                                                                                Now, we can obtain the score based on the coefficient of
where A ∈ RLobs ×(n−Lrec −Linit ) . In the following, we will                   variation for an attention head of a sample as follows:
identify consistent heads based on the characteristics of A.                                       q
                                                                                                           1
                                                                                                                       P               2
                                                                                                      (n−Lrec −Linit )  i (Ci − µ(C))
Coefficient of Variation (CV) Score Empirically, consis-                                  score =                                           (4)
tent heads exhibit two primary features in their observation                                                        µ(C)
matrices: a high degree of similarity among different rows                      where µ(C) = (n−Lrec1−Linit ) i Ci is the mean. With the
                                                                                                                P
and a small subset of columns that is sufficient to recall
                                                                                above equations, we can compute a score for each head
most of the attention weights. Inspired by this aspect, we
                                                                                under a sample. Then, for a specific LLM, we can obtain a
propose a coefficient-of-variation-based score to measure
                                                                                score matrix S ∈ Rl×h for all heads, where l and h represent
the concentration and similarity of attention within obser-
                                                                                the number of layers in the model and the number of heads
vation matrices A. Since the coefficient of variation (Abdi,
                                                                                in a layer, respectively. For a statistic head identification
2010) is highly sensitive to the magnitude of values, we
                                                                                rule, let r denote the proportion of adaptive heads, and Γ(r)
first binarize the observation matrix with a percentile-based
                                                                                represents the percentile threshold based on r. We can use
threshold k and a scaling factor α.
                                                                                the threshold to control the token eviction ratio. Then, we
       B = I (A ≥ Φ(k, α)) ∈ RLobs ×(n−Lrec −Linit )                  (2)       distinguish the head types of a specific sample as follows
                                                                                                  (
where I is the indicator function, and Φ(k, α) =                                                     consistent head, if Si,j > Γ(r)
                                                                                       Headi,j =                                          . (5)
Quantilek (A) × α represents the k-th percentile element                                             adaptive head,        if Si,j ≤ Γ(r)
in the matrix A, scaled by a factor of α. Then after binariza-
tion, we derive a frequency vector C to quantify the number
of times each token that is identified as critical, reflecting                  Reference-Based Static Identification Although head
the similarity and concentration of attention weights:                          identification can be performed dynamically for each sam-
                                                                                ple, it is actually expensive for memory management along
                    Lobs
                    X                                                           with the change of samples at the pre-filling stage. There-
              C=           Bi,: ∈ R(n−Lrec −Linit )                   (3)       fore, it is better to determine a fixed head type for the model,
                    i=0                                                         which can be directly used for inference. Surprisingly, we

                                                                            4
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration



                                                                                                     N
                                                                                                                     !
                                                                                                  1 X
                                                                          ∀f ∈ F, Phead E[f ] −         fn ≤ 2RN (F )
                                                                                                  N n=1
                                                                                       s
                                                                                         2 log 2δ
                                                                                     +            ≥ 1 − δ.             (6)
                                                                                           2N

                                                                     where RN (F ) is the conditional Rademacher average.
                                                                     Let P1 and P2 denote the probabilities of correctly classified
                                                                     consistent heads and adaptive heads, respectively, while P̄1
                                                                     and P̄2 represent the probabilities of misclassified consistent
                                                                     heads and adaptive heads, respectively. It is assumed that
                                                                     P1 + P2 = Phead and P̄1 + P̄2 = 1 − Phead . The probability
Figure 4: Attention weight recall curves for four methods.           in the above lemma can then be decomposed through a
The curves show the attention recall for each attention head,        fine-grained analysis as follows.
calculated on four patterns: consistent, streaming, quest, and
                                                                     Theorem 1: Let η1 and η2 denote the retention ratios for
top-k, on a 128k-length example. The attention recall values
                                                                     consistent heads and adaptive heads, respectively, while
are obtained by the mean of all decoding steps and sorted in
                                                                     η1∗ and η2∗ represent their corresponding optimal retention
descending order for all heads. The sparse budget is set to
                                                                     ratios. Define the retention accuracy for different cases
2048, and the chunk size is 8. The results indicate that the
                                                                     ri,j = ηi∗ 1[ηj > ηi∗ ] + ηj (1 − 1[ηj > ηi∗ ]) by comparing
consistent pattern outperforms the streaming pattern in terms
                                                                     the retention budgets with the optimal budgets. Additionally,
of overall attention recall, and approaches the performance
                                                                     assume that the hypothesis asserting the query attention
of the quest pattern that requires additional computation.
                                                                     score provides the best description in order with probability
                                                                     λ. Then, the token retention accuracy satisfies:

observe that the same head does exhibit similar attention                                                                      
patterns across different samples, and the identification re-             Ptoken = λ r1,1 P1 + r2,2 P2 + r2,1 P̄1 + r1,2 P̄2
sults based on CV scores are highly consistent. This inspires                    ≥ λ (min(r2,1 , r1,2 ) + [min(r1,1 , r2,2 )
us to use a reference dataset to calculate the frequency of
                                                                                    − min(r2,1 , r1,2 )] Phead ) .                 (7)
each head being identified as the consistent head, and then
derive the final model-wise identification result based on the
adaptive head ratio r, as shown in Figure 3, which comes             Remark 1: From the above theorem, three critical factors
to the final form of our method (termed as CateKV). After            influence the worst-case token retention accuracy (i.e., the
determining the type of each head, we retain only the most           lower bound):
important KV pairs for consistent heads, while for adaptive
heads, we preserve a majority based on the predefined re-               • λ: The effectiveness of identifying an efficient measure
tention ratio η. Specifically, we select the top-k KV pairs in            to characterize token correlation by the score order,
chunks, enabling seamless integration with retrieval-based                with as high a probability of correctness as possible.
methods. For the GQA model, the observation matrix A is                 • Budget control: The ability to appropriately set the re-
computed as the mean of A of the heads in a group. The                    tention budget in order to maximize gains by reducing
CateKV acceleration for LLMs is shown in Algorithm 1.                     the majority of tokens when heads are correctly clas-
                                                                          sified, while simultaneously mitigating the negative
3.3. Theory Analysis                                                      impact when heads are misclassified.
In this part, we present an analysis of the theoretical bound           • Phead : The accuracy of the CV-based method in clas-
on the eviction performance of CateKV.                                    sifying the head type during token reduction, which
Lemma 1: Let G represent the hypothesis class derived                     directly impacts the overall performance.
from the CV-based function, F denote the real-valued func-
tion class induced by the binary cross-entropy loss applied
                                                                     3.4. Further Discussion of CateKV
to G, and let N denote the sample size of the reference-
based dataset. Then, with probability at least 1 − δ, the            To show the distinction and effectiveness of attention pat-
following Rademacher complexity bound holds:                         terns discovered from the sequential consistency, Figure 4

                                                                 5
                     CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Table 1: Performance (%) of different models and various methods on RULER evaluated at length of 128K. The ’Cache’ in
the table refers to the retained KV cache size. CateKV outperforms other methods and comparable with full attention.
 Methods          Cache    N-S1    N-S2   N-S3 N-MK1 N-MK2 N-MK3 FWE N-MQ N-MV QA-1 QA-2                            VT     Avg.
 Llama-3-8B-1M     100%   100.00 100.00 100.00     98.96    98.96      41.67   71.88   98.69   96.35   73.96 50.00 78.75   84.10
 StreamingLLM       41%    51.04 51.04 51.04       40.63    35.42      22.92   75.69   45.31   39.58   78.13 45.83 31.46   47.34
 SnapKV             41%   100.00 100.00 100.00     98.96    98.96      30.21   71.53   98.44   97.13   73.95 51.04 79.17   83.28
 PyramidKV          41%   100.00 100.00 100.00     98.96    98.96      37.50   71.53   98.44   96.61   71.87 50.00 79.38   83.60
 Duoattention       41%   100.00 100.00 100.00     98.96    97.92      39.58   76.74   94.27   90.36   69.79 51.04 86.46   83.76
 CateKV             41%   100.00 100.00 100.00     98.96    97.92      41.67   71.88   98.44   96.88   73.96 50.00 85.63   84.61
 Phi-3-Mini-128K 100%     96.88   90.63   95.83    83.33    65.63      37.50   87.15   72.14   66.67   63.54 39.58 65.83   72.06
 StreamingLLM     41%     47.91   45.83   44.79    38.54    30.21      25.00   84.38   36.49   34.90   64.58 38.54 4.38    41.29
 SnapKV           41%     96.88   90.63   80.21    82.29    56.25      11.46   82.99   61.72   53.91   62.50 38.54 63.54   65.08
 PyramidKV        41%     96.88   90.63   84.38    83.33    57.29      13.54   78.47   66.15   59.64   62.50 39.58 62.29   66.22
 CateKV           41%     96.88   90.63   95.83    83.33    65.63      38.54   80.21   70.31   65.63   63.54 39.58 70.21   71.69
 Llama-3.1-8B      100%   100.00 100.00   98.96    98.96    90.63      63.54   71.53   98.96   95.31   81.25 46.88 68.54   84.55
 StreamingLLM       41%    51.04 51.04    51.04    39.58    34.38      40.63   71.18   44.27   39.84   85.42 40.63 28.33   48.11
 SnapKV             41%   100.00 100.00   98.96    98.96    89.58      46.88   69.10   98.96   94.01   81.25 46.88 68.96   82.80
 PyramidKV          41%   100.00 100.00   98.96    98.96    90.63      56.25   65.28   98.96   95.31   80.21 46.88 65.42   83.07
 Duoattention       41%   100.00 100.00   98.96    97.92    88.54      59.38   74.31   97.92   91.41   81.25 46.88 78.54   84.59
 CateKV             41%   100.00 100.00   98.96    98.96    88.54      61.46   71.88   98.96   94.27   81.25 46.88 74.79   84.66
 Yi-9B-200K        100%   100.00 100.00 98.96      85.42    63.54      18.75   89.24   66.41   32.55   45.83 38.54 35.00   64.52
 StreamingLLM       41%    47.92 52.08 50.00       39.58    37.50       7.29   90.28   33.33   14.84   44.79 36.46 18.13   39.35
 SnapKV             41%   100.00 100.00 95.83      85.41    43.75       3.13   83.33   66.41   33.33   46.88 40.63 38.96   61.47
 PyramidKV          41%   100.00 100.00 91.67      86.46    50.00       2.08   73.61   68.75   34.64   43.75 37.50 41.46   60.83
 CateKV             41%   100.00 100.00 100.00     84.38    70.83      18.75   92.01   62.24   34.64   43.75 37.50 45.00   65.76


compares attention weight recall for our consistent pattern,        et al., 2024) and Qwen2.5-7B (Bai et al., 2023a). The per-
streaming pattern (Xiao et al., 2023), Quest pattern (Tang          formance of CateKV was assessed on three challenging
et al., 2024b), and the upper-bound top-k pattern under the         benchmarks: RULER (Hsieh et al., 2024), LongBench (Bai
same sparse budget. As can be seen, all methods exhibit a           et al., 2023b), and Needle in a Haystack (NIAH) (Kamradt,
gap compared to the upper bound, indicating some informa-           2024). We built a reference set for head identification of
tion loss with current sparse attention approaches. There-          CateKV by emulating Variable Tracking task from RULER,
fore, retaining most KV pairs for certain heads is important        which is very distinct from the test set. The experiments
for maintaining accuracy. On the other hand, the attention          were carried out on a single NVIDIA A100-80G GPU.
recall of the consistent pattern closely approximates that of
the Quest pattern, applying the consistent pattern to heads
with sequential consistency can help KV retrieval methods
reduce memory usage and the cost of selecting critical to-          Baselines We compare CateKV with eviction-based al-
kens. Related works (Tang et al., 2024a; Xiao et al., 2024b)        gorithms StreamingLLM (Xiao et al., 2023), SnapKV (Li
classify attention heads into Retrieval Heads and Streaming         et al., 2024), PyramidKV (Cai et al., 2024), retrieval-based
Heads, which is similar to our method. However, from an             algorithms Quest (Tang et al., 2024b) and ShadowKV (Sun
attention recall perspective, the streaming pattern is only         et al., 2024), and the head-wise classification algorithm
effective for a small fraction of heads, otherwise deviating        Duoattention (Xiao et al., 2024b). In our experiments, all
significantly from full attention. This highlights that the         approaches maintained an exact pre-filling stage and utilized
consistent pattern achieves a higher compression rate than          sparse attention during the decoding stage. We also do not
the streaming pattern. We will discuss the comparison and           perform memory optimization like ShadowKV in the accu-
integration with these methods in the experimental section.         racy comparison. For fairness, when comparing with the
                                                                    KV eviction methods and head classification methods, we
                                                                    maintain the same KV cache size, while comparing with KV
4. Experiments                                                      retrieval methods, we integrate them under adaptive heads
4.1. Setup                                                          to ensure an equivalent computational budget. Given that
                                                                    Duoattention only provides attention patterns for Llama3
LLM and Benchmark We employed five widely used                      and Llama3.1 in the models used in our study, the com-
LLMs in long-context scenarios: LLaMA-3-8B-Instruct-                parison is restricted to these two models. When baselines
1048K (Gradient, 2024a), Phi-3-Mini-128K (Abdin et al.,             require a chunk size, we all set it to 8 to maintain consis-
2024), Llama-3.1-8B (Meta AI, 2024), Yi-9B-200K (AI                 tency. Further experimental details are in the Appendix B.1.

                                                                6
                       CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Table 2: Performance (%) of different models and various                                          Needle in A Haystack Llama-3-8B-1M w/ CateKV                  1.0
                                                                                              0
methods on LongBench. We present the average score of all                                    11
21 tasks. The “Budget” refers to the computational budget.                                                                                                      0.8
                                                                                             22




                                                                            Depth Percent (%)
Please refer to the Appendix B.3 for detailed data.                                          33
                                                                                                                                                                0.6
                                                                                             44
           Model            LLama-3 Phi-3 Llama-3.1    Yi     Qwen2.5                        56
                                                                                                                                                                0.4
 Methods     Cache Budget             Average Performance                                    67
                                                                                             78
 Full      100%    100%      31.27   34.00   33.68    33.02    30.03                                                                                            0.2
                                                                                             89
   +CateKV 42%      42%      31.48   33.73   33.70    32.83    29.92
                                                                                            100
 Quest     100%     3%       30.90   33.11   33.20    32.82    29.30                                                                                            0.0
   +CateKV 42%      3%       31.03   33.29   33.38    32.79    29.33




                                                                                                 20K
                                                                                                 90K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                    K
                                                                                                  1M
                                                                                                160
                                                                                                230
                                                                                                300
                                                                                                370
                                                                                                440
                                                                                                510
                                                                                                580
                                                                                                650
                                                                                                720
                                                                                                790
                                                                                                860
                                                                                                930
 ShadowKV 100%
   +CateKV 42%
                    3%
                    3%
                             30.77
                             30.94
                                     32.53
                                     32.45
                                             33.03
                                             32.96
                                                      32.41
                                                      32.21
                                                               28.57
                                                               28.51
                                                                                                                 Context Length

                                                                              Figure 5: Needle In A Haystack from 20K to 1M in Llama3
4.2. Effectiveness Evaluation
4.2.1. R ESULTS ON RULER                                                      Table 3: Performance of CateKV combined with Duoatten-
                                                                              tion and MInference on the RULER benchmark. The results
In this experiment, we test 12 synthetic tasks under the
                                                                              are tested on the Llama-3-8B-1M model.
context of 128K, with each task including 96 samples. To
ensure a fair comparison with other baseline methods, we                               Methods                   8K     16K     32K     64K     128K    256K     Avg.

focus here on the task-aware setting. The results are shown                            Duoattention             78.32   77.93   69.77   66.27   60.37   58.07   68.46
                                                                                       Duoattention w/ CateKV   89.93   91.08   89.96   86.44   84.57   81.59   87.26
in Table 1. Specifically, in CateKV , we set the adaptive                              MInference               91.33   92.28   89.66   84.97   84.57   81.10   87.32
head ratio r to 0.4, the retention ratio η to 1.0 and allocate a                       MInference w/ CateKV     91.32   92.13   89.71   85.90   85.14   82.27   87.74
sparse budget for consistent heads at 2048 (1.56%), retain-
ing approximately 41% of the KV cache size. Experimental
results demonstrate that our method outperforms baselines
                                                                              computational cost by more than half. Additional NIAH test
and is comparable to full attention, despite evicting over half
                                                                              results on other models are available in the Appendix B.4.
of the KV pairs. Besides, CateKV exhibits outstanding per-
formance in complex tasks such as multi-document QA and
                                                                               4.2.4. C ATE KV VS . D UOATTENTION
variable tracking while maintaining high accuracy in other
tasks. Due to the space limitation, we place results of more                  Duoattention (Xiao et al., 2024b) classifies attention heads
context lengths and combination with other retrieval-based                    into retrieval heads and streaming heads, similar to our
methods in Appendix B.2.                                                      approach. For a comprehensive comparison, we evalu-
                                                                              ate CateKV against DuoAttention across varying ratios of
4.2.2. R ESULTS ON L ONG B ENCH                                               adaptive/retrieval heads, ranging from 0.1 to 1.0. Figure 7
                                                                              shows that Duoattention’s accuracy notably declines when
LongBench (Bai et al., 2023b) is a comprehensive long-
                                                                              the proportion of retrieval heads falls below 0.3. In contrast,
context benchmark including 6 main categories and 21 di-
                                                                              CateKV sustains performance close to full attention even
verse tasks. Following ShadowKV (Sun et al., 2024), we test
                                                                              when the ratio of adaptive heads decreases to 0.1. This dis-
samples with lengths exceeding 4096 tokens. In CateKV,
                                                                              crepancy arises from the fundamental difference in attention
we set the adaptive ratio r and retention ratio η to 0.4 and
                                                                              patterns between our consistent head and their streaming
1.0 respectively. The budget for consistent heads is set to
                                                                              head. The consistent head in CateKV captures similarity
512. As shown in Table 2, CateKV enables a reduction in
                                                                              across different queries, whereas the streaming head pri-
KV cache size to 42% across five LLMs while maintain-
                                                                              marily focuses on the coverage of initial and recent tokens.
ing an accuracy decline of no more than 0.3% on average.
                                                                              This essential difference enables our method to complement
Furthermore, when integrated with KV retrieval methods
                                                                              DuoAttention, mitigating its performance degradation at low
like Quest (Tang et al., 2024b) and ShadowKV (Sun et al.,
                                                                              full attention head ratios. To validate this, we conducted
2024), CateKV facilitates a reduction in memory usage with
                                                                              experiments presented in Table 3. Specifically, we set the
only a minimal impact on accuracy, not exceeding a 0.2%
                                                                              retrieval head ratio in DuoAttention to 0.3, with the remain-
decrease, under the same computational budget.
                                                                              ing 0.7 as streaming heads. In contrast, “Duoattention w/
                                                                              CateKV” replaces part of the streaming heads with consis-
4.2.3. R ESULTS ON N EEDLE I N A H AYSTACK
                                                                              tent heads, resulting in a 0.2 consistent head ratio and a
As shown in Figure 5, on the Needle In A Haystack dataset,                    0.5 streaming head ratio. The results demonstrate that in-
CateKV demonstrates its robust ability to accurately identify                 corporating CateKV significantly improves DuoAttention’s
and extract relevant information from long contexts, rang-                    performance at low full attention head ratios, further vali-
ing from 20K to 1M tokens, while reducing memory and                          dating the effectiveness of our consistency pattern.

                                                                        7
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration




Figure 6: Comparison of decoding efficiency between CateKV and full attention. As the context length increases, both the
memory usage (a) and decoding latency (b) increase linearly, but CateKV exhibits a smaller slope compared to full attention.
OOM indicates that the GPU memory limit (80G) is exceeded; corresponding data is obtained by extrapolation.
4.2.5. E FFICIENT P RE - FILLING M ETHODS I NTEGRATION
CateKV is designed to accelerate the decoding stage and
can naturally integrate with prefilling acceleration methods.
We also combined CateKV with the efficient prefilling accel-
eration method, MInference (Jiang et al., 2024), and tested
it on RULER with contexts ranging from 8K to 256K. As
shown in Table 3, combining CateKV with MInference does
not lead to performance degradation and even a slight per-           Figure 7: Comparison of accuracy between our method and
formance improvement has been observed. This shows that              DuoAttention across different full attention head ratios.
sequential consistency within the heads is unaffected by the
pre-filling inference patterns, highlighting the robustness of
                                                                     4.3.2. BATCH - SAMPLE I NFERENCE
our method. Moreover, the additional acceleration of the
prefilling stage further improves the overall inference speed.       Batch-sample inference is a more common scenario in
                                                                     real-world applications. By evicting a portion of the KV
4.3. Efficiency Evaluation                                           pairs, CateKV supports larger batch sizes, thereby increas-
                                                                     ing throughput. To evaluate CateKV’s efficiency in batch-
To validate the efficiency of CateKV, we tested it under both        sample scenarios, we set each sample length to 40K and in-
single-sample and batch-sample inference scenarios.                  put them in batches, comparing throughput at the maximum
                                                                     batch size for both full attention and CateKV. The compar-
4.3.1. S INGLE - SAMPLE I NFERENCE                                   ative results across three models are presented in Table 4.
To evaluate the efficiency of CateKV during single-sample            With the generic settings, gains of up to 2.38× in batch
inference, we selected three models with different num-              size and 2.25× in throughput were achieved. Additionally,
bers of KV heads: Llama-3, Phi-3, and Yi. We compared                through further KV cache compression while maintaining
CateKV to full attention on these models by measuring mem-           accuracy, both batch size and throughput in the Llama-3
ory usage and decoding latency at the same input length. We          model were boosted to 4.33× and 3.96×, respectively.
observed that memory and latency reductions increase as the
context length grows (detailed in the Figure 6). To demon-           4.4. Ablation Study
strate optimal performance, we selected the maximum input
                                                                     The ablation studies focus on three key aspects of CateKV :
length that can be handled by full attention on a single A100
                                                                     (1) ratio of adaptive heads, (2) retention ratio in the adaptive
GPU. As shown in Table 4, under the generic settings of
                                                                     head, and (3) sparse KV cache budget in the consistent
r = 0.4 and η = 1.0, the Phi-3 model achieved reductions
                                                                     head. All experiments are conducted on the RULER-128K
of 2.11× in memory and 1.79× in latency by using CateKV.
                                                                     datasets using the Llama-3-8B-1M model.
By balancing efficiency and accuracy, CateKV further re-
duced memory usage by 2.72× and decoding latency by
                                                                     4.4.1. R ATIO OF A DAPTIVE H EADS
2.18× on Llama-3, with accuracy decline on RULER-128K
and Longbench tasks under 0.25%.                                     The ratio of adaptive heads r is a crucial hyperparameter bal-
                                                                     ancing accuracy and inference speed. As shown in Figure 7,
                                                                     the relationship between r and model performance does

                                                                 8
                       CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Table 4: Efficiency comparison between CateKV and Full Attention on a single A100 GPU. In the single-sample inference
task, we utilized texts of lengths 500K, 180K, and 650K as inputs for the following three models. For the batch-sample
inference task, the sample length was set at 40K, and the maximum feasible batch size was used for each method evaluated.
                                          Accuracy (Avg)                  Single-sample inference         Batch-sample inference
    Model                           RULER-128K       Longbench           Memory           Latency       Batchsize          Throughput
    Llama-3-8B-1M (8 KV heads)       84.10 (0.00)    31.27 (0.00)   77.72 (1.00×)      54.28 (1.00×)   12 (1.00×)         229.37 (1.00×)
    CateKV (r = 0.4, η = 1.0)       84.61 (+0.51)   31.48 (+0.21)   41.02 (1.89×)      32.75 (1.66×)   28 (2.33×)         511.46 (2.23×)
    CateKV (r = 0.3, η = 0.7)       83.85 (-0.25)   31.21 (-0.06)   28.59 (2.72×)      24.86 (2.18×)   52 (4.33×)         909.69 (3.96×)
    Phi-3-Mini-128K (32 KV heads)   72.06 (0.00)    34.00 (0.00)    75.11 (1.00×)      55.51 (1.00×)    4 (1.00×)         78.53 (1.00×)
    CateKV (r = 0.4, η = 1.0)       71.69 (-0.37)   33.73 (-0.27)   35.58 (2.11×)      31.06 (1.79×)   10 (2.50×)         167.11 (2.13×)
    CateKV (r = 0.3, η = 1.0)       71.48 (-0.58)   33.66 (-0.33)   29.02 (2.59×)      27.81 (2.00×)   14 (3.50×)         221.29 (2.82×)
    Yi-9B-200K (4 KV heads)          64.52 (0.00)   33.02 (0.00)    77.65 (1.00×)      56.30 (1.00×)   16 (1.00×)         292.55 (1.00×)
    CateKV (r = 0.4, η = 1.0)       65.76 (+1.24)   32.83 (-0.19)   41.62 (1.87×)      36.05 (1.56×)   38 (2.38×)         659.02 (2.25×)
    CateKV (r = 0.3, η = 0.8)       65.75 (+1.23)   32.78 (-0.24)   31.58 (2.46×)      29.96 (1.88×)   60 (3.75×)         980.86 (3.35×)




                        (a)                                             (b)                                         (c)
Figure 8: (a) The effect of adaptive head ratio on memory and decoding latency is approximately linear. (b) Impact of
retention ratio on accuracy in RULER-128K and decoding latency for 500K length input. (c) Minimal effect of sparse
budget in consistent heads on accuracy.

not exhibit a perfect inverse correlation. Rather, the per-              tings of r = 0.4 and η = 1.0, even when the sparse budget
formance remains relatively stable with decreasing r until               in the consistent head is reduced to approximately 0.78%
reaching a critical threshold (≈0.2), beyond which signifi-              (1024), CateKV still maintains comparable performance to
cant degradation occurs due to excessive reliance on critical            full attention in terms of average accuracy. This indicates
tokens during the prefilling stage. In terms of efficiency,              that, during inference, the consistent head only requires a
as shown in Figure 8(a), both memory usage and decoding                  minimal portion of the cache to perform its function, while
latency decrease almost linearly with decreasing r.                      the acquisition of global information relies primarily on
                                                                         adaptive heads, which retain the majority of KV pairs dur-
4.4.2. R ETENTION R ATIO IN A DAPTIVE H EAD                              ing the decoding stage. Since the sparse budget for the
                                                                         consistent head is a small fraction of the total cache, its im-
In adaptive heads, there is still a subset of tokens that are
                                                                         pact on memory usage and inference latency is negligible.
always not important. This enables a reduction in the pro-
portion of the KV cache retained within adaptive heads.
Figure 8(b) illustrates the impact of changes in the retention           5. Conclusion
ratio η on accuracy and latency. When η exceeds a certain
                                                                         We propose CateKV, a novel hybrid KV cache method that
threshold (≈0.6), the model maintains or even surpasses
                                                                         leverages sequential consistency to improve LLM inference
the performance achieved with the full KV cache. How-
                                                                         efficiency in long-context tasks. By using a coefficient-of-
ever, dropping below this threshold results in a significant
                                                                         variation-based algorithm, CateKV classifies attention heads
performance decline, indicating that adaptive heads heavily
                                                                         into consistent and adaptive types. It selectively retains crit-
depend on the majority of the KV cache. Additionally, a de-
                                                                         ical KV pairs in consistent heads and most pairs in adaptive
crease in η leads to a linear reduction in latency. In practical
                                                                         heads, reducing memory usage and decoding latency while
applications, it is essential to adjust both r and η to balance
                                                                         maintaining performance. Additionally, it can be easily
accuracy and memory consumption.
                                                                         integrated with other acceleration methods for further en-
                                                                         hancement. Extensive evaluations demonstrate that CateKV
4.4.3. S PARSE B UDGET IN C ONSISTENT H EAD
                                                                         achieves significant efficiency gains, including up to 2.72×
As illustrated in Figure 8(c), CateKV demonstrates strong                reduction in memory usage, 2.18× acceleration in decoding,
robustness across different sparse budgets. Under the set-               and a 3.96× throughput increase in batch scenarios.


                                                                    9
                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Acknowledgments                                                           Repository-level coding using llms and planning. Pro-
                                                                          ceedings of the ACM on Software Engineering, 1(FSE):
This work is supported by National Natural Science Founda-                675–698, 2024.
tion of China (No.62306178), STCSM (No.22DZ2229005),
111 plan (No. BP0719010).                                               Caciularu, A., Peters, M. E., Goldberger, J., Dagan, I.,
                                                                          and Cohan, A. Peek across: Improving multi-document
                                                                          modeling via cross-document question-answering. arXiv
Impact Statement
                                                                          preprint arXiv:2305.15387, 2023.
The primary objective of our research is to develop inference
                                                                        Cai, Z., Zhang, Y., Gao, B., Liu, Y., Liu, T., Lu, K., Xiong,
acceleration methods for large language models, aiming to
                                                                          W., Dong, Y., Chang, B., Hu, J., et al. Pyramidkv: Dy-
advance their efficiency and scalability. We explicitly state
                                                                          namic kv cache compression based on pyramidal informa-
that any depictions of violence in the datasets are wholly
                                                                          tion funneling. arXiv preprint arXiv:2406.02069, 2024.
fictional and are utilized exclusively for academic research
purposes. This work does not reflect, support, or justify               Chen, Z., Sadhukhan, R., Ye, Z., Zhou, Y., Zhang, J., Nolte,
any real-world violent actions. Additionally, this research               N., Tian, Y., Douze, M., Bottou, L., Jia, Z., et al. Mag-
was carried out independently, with no external funding or                icpig: Lsh sampling for efficient llm generation. arXiv
conflicts of interest influencing its outcomes. The study                 preprint arXiv:2410.16179, 2024.
strictly follows ethical guidelines, taking into account es-
                                                                        Dubey, A., Jauhri, A., Pandey, A., Kadian, A., Al-Dahle,
sential factors such as discrimination, bias, fairness, privacy,
                                                                         A., Letman, A., Mathur, A., Schelten, A., Yang, A., Fan,
security, and legal adherence, while maintaining the utmost
                                                                         A., et al. The llama 3 herd of models. arXiv preprint
integrity in the research process.
                                                                          arXiv:2407.21783, 2024.

References                                                              Feng, Y., Lv, J., Cao, Y., Xie, X., and Zhou, S. K. Ada-
                                                                          kv: Optimizing kv cache eviction by adaptive budget
Abdi, H. Coefficient of variation. Encyclopedia of research               allocation for efficient llm inference. arXiv preprint
  design, 1(5):169–171, 2010.                                             arXiv:2407.11550, 2024.
Abdin, M., Aneja, J., Awadalla, H., Awadallah, A., Awan,                Fu, Q., Cho, M., Merth, T., Mehta, S., Rastegari, M.,
 A. A., Bach, N., Bahree, A., Bakhtiari, A., Bao, J., Behl,               and Najibi, M. Lazyllm: Dynamic token pruning for
  H., et al. Phi-3 technical report: A highly capable lan-                efficient long context llm inference. arXiv preprint
  guage model locally on your phone. arXiv preprint                       arXiv:2407.14057, 2024a.
  arXiv:2404.14219, 2024.
                                                                        Fu, Y., Cai, Z., Asi, A., Xiong, W., Dong, Y., and Xiao, W.
Achiam, J., Adler, S., Agarwal, S., Ahmad, L., Akkaya, I.,                Not all heads matter: A head-level kv cache compression
  Aleman, F. L., Almeida, D., Altenschmidt, J., Altman, S.,               method with integrated retrieval and reasoning. arXiv
  Anadkat, S., et al. Gpt-4 technical report. arXiv preprint              preprint arXiv:2410.19258, 2024b.
  arXiv:2303.08774, 2023.                                               GLM, T., Zeng, A., Xu, B., Wang, B., Zhang, C., Yin, D.,
                                                                         Rojas, D., Feng, G., Zhao, H., Lai, H., Yu, H., Wang, H.,
AI, ., :, Young, A., Chen, B., Li, C., Huang, C., Zhang, G.,             Sun, J., Zhang, J., Cheng, J., Gui, J., Tang, J., Zhang, J.,
  Zhang, G., Li, H., Zhu, J., Chen, J., Chang, J., Yu, K.,               Li, J., Zhao, L., Wu, L., Zhong, L., Liu, M., Huang, M.,
  Liu, P., Liu, Q., Yue, S., Yang, S., Yang, S., Yu, T., Xie,            Zhang, P., Zheng, Q., Lu, R., Duan, S., Zhang, S., Cao, S.,
  W., Huang, W., Hu, X., Ren, X., Niu, X., Nie, P., Xu, Y.,              Yang, S., Tam, W. L., Zhao, W., Liu, X., Xia, X., Zhang,
  Liu, Y., Wang, Y., Cai, Y., Gu, Z., Liu, Z., and Dai, Z. Yi:           X., Gu, X., Lv, X., Liu, X., Liu, X., Yang, X., Song, X.,
  Open foundation models by 01.ai, 2024.                                 Zhang, X., An, Y., Xu, Y., Niu, Y., Yang, Y., Li, Y., Bai,
                                                                         Y., Dong, Y., Qi, Z., Wang, Z., Yang, Z., Du, Z., Hou,
Bai, J., Bai, S., Chu, Y., Cui, Z., Dang, K., Deng, X., Fan,
                                                                         Z., and Wang, Z. Chatglm: A family of large language
  Y., Ge, W., Han, Y., Huang, F., et al. Qwen technical
                                                                         models from glm-130b to glm-4 all tools, 2024a.
  report. arXiv preprint arXiv:2309.16609, 2023a.
                                                                        GLM, T., Zeng, A., Xu, B., Wang, B., Zhang, C., Yin, D.,
Bai, Y., Lv, X., Zhang, J., Lyu, H., Tang, J., Huang, Z.,                Zhang, D., Rojas, D., Feng, G., Zhao, H., et al. Chatglm:
  Du, Z., Liu, X., Zeng, A., Hou, L., et al. Longbench: A                A family of large language models from glm-130b to
  bilingual, multitask benchmark for long context under-                 glm-4 all tools. arXiv preprint arXiv:2406.12793, 2024b.
  standing. arXiv preprint arXiv:2308.14508, 2023b.
                                                                        Gradient. Llama-3-8b-instruct gradient 1048k, 2024a.
Bairi, R., Sonwane, A., Kanade, A., Iyer, A., Parthasarathy,              URL https://huggingface.co/gradientai/
  S., Rajamani, S., Ashok, B., and Shet, S. Codeplan:                     Llama-3-8B-Instruct-Gradient-1048k.

                                                                   10
                     CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Gradient. Llama-3-8b-instruct gradient 262k, 2024b.                   Singhania, P., Singh, S., He, S., Feizi, S., and Bhatele, A.
  URL https://huggingface.co/gradientai/                                Loki: Low-rank keys for efficient sparse attention. arXiv
  Llama-3-8B-Instruct-262k.                                             preprint arXiv:2406.02542, 2024.

Hsieh, C.-P., Sun, S., Kriman, S., Acharya, S., Rekesh, D.,           Sun, H., Chang, L.-W., Bao, W., Zheng, S., Zheng, N., Liu,
  Jia, F., Zhang, Y., and Ginsburg, B. Ruler: What’s the                X., Dong, H., Chi, Y., and Chen, B. Shadowkv: Kv
  real context size of your long-context language models?               cache in shadows for high-throughput long-context llm
  arXiv preprint arXiv:2404.06654, 2024.                                inference. arXiv preprint arXiv:2410.21465, 2024.
Jiang, H., Li, Y., Zhang, C., Wu, Q., Luo, X., Ahn, S., Han,          Tang, H., Lin, Y., Lin, J., Han, Q., Hong, S., Yao, Y., and
   Z., Abdi, A. H., Li, D., Lin, C.-Y., et al. Minference 1.0:          Wang, G. Razorattention: Efficient kv cache compression
   Accelerating pre-filling for long-context llms via dynamic           through retrieval heads. arXiv preprint arXiv:2407.15891,
   sparse attention. arXiv preprint arXiv:2407.02490, 2024.             2024a.
Jimenez, C. E., Yang, J., Wettig, A., Yao, S., Pei, K., Press,
                                                                      Tang, J., Zhao, Y., Zhu, K., Xiao, G., Kasikci, B., and Han,
  O., and Narasimhan, K. Swe-bench: Can language mod-
                                                                        S. Quest: Query-aware sparsity for efficient long-context
  els resolve real-world github issues? arXiv preprint
                                                                        llm inference. arXiv preprint arXiv:2406.10774, 2024b.
  arXiv:2310.06770, 2023.

Kamradt, G. Needle in a haystack - pressure testing llms,             Team, G., Anil, R., Borgeaud, S., Alayrac, J.-B., Yu, J., Sori-
  2024.                                                                 cut, R., Schalkwyk, J., Dai, A. M., Hauth, A., Millican,
                                                                        K., et al. Gemini: a family of highly capable multimodal
Kwon, W., Li, Z., Zhuang, S., Sheng, Y., Zheng, L., Yu,                 models. arXiv preprint arXiv:2312.11805, 2023.
 C. H., Gonzalez, J., Zhang, H., and Stoica, I. Efficient
 memory management for large language model serving                   Wang, M., Chen, L., Cheng, F., Liao, S., Zhang, X., Wu,
 with pagedattention. In Proceedings of the 29th Sym-                  B., Yu, H., Xu, N., Zhang, L., Luo, R., et al. Leave
 posium on Operating Systems Principles, pp. 611–626,                  no document behind: Benchmarking long-context llms
 2023.                                                                 with extended multi-doc qa. In Proceedings of the 2024
                                                                       Conference on Empirical Methods in Natural Language
Lee, W., Lee, J., Seo, J., and Sim, J. {InfiniGen}: Effi-              Processing, pp. 5627–5646, 2024.
  cient generative inference of large language models with
  dynamic {KV} cache management. In 18th USENIX                       Xiao, C., Zhang, P., Han, X., Xiao, G., Lin, Y., Zhang,
  Symposium on Operating Systems Design and Implemen-                   Z., Liu, Z., and Sun, M. Infllm: Training-free long-
  tation (OSDI 24), pp. 155–172, 2024.                                  context extrapolation for llms with an efficient context
                                                                        memory. In The Thirty-eighth Annual Conference on
Li, D., Shao, R., Xie, A., Sheng, Y., Zheng, L., Gon-                   Neural Information Processing Systems, 2024a.
  zalez, J. E., Stoica, I., Ma, X., and Zhang, H. How
  long can open-source llms truly promise on context                  Xiao, G., Tian, Y., Chen, B., Han, S., and Lewis, M. Ef-
  length?, June 2023. URL https://lmsys.org/                            ficient streaming language models with attention sinks.
  blog/2023-06-29-longchat.                                             arXiv preprint arXiv:2309.17453, 2023.
Li, Y., Huang, Y., Yang, B., Venkitesh, B., Locatelli, A.,            Xiao, G., Tang, J., Zuo, J., Guo, J., Yang, S., Tang, H.,
  Ye, H., Cai, T., Lewis, P., and Chen, D. Snapkv: Llm                  Fu, Y., and Han, S. Duoattention: Efficient long-context
  knows what you are looking for before generation. arXiv               llm inference with retrieval and streaming heads. arXiv
  preprint arXiv:2404.14469, 2024.                                      preprint arXiv:2410.10819, 2024b.
Merity, S., Xiong, C., Bradbury, J., and Socher, R.
                                                                      Yang, D., Han, X., Gao, Y., Hu, Y., Zhang, S., and
 Pointer sentinel mixture models.     arXiv preprint
                                                                        Zhao, H. Pyramidinfer: Pyramid kv cache compres-
 arXiv:1609.07843, 2016.
                                                                        sion for high-throughput llm inference. arXiv preprint
Meta AI. Introducing Llama 3.1, 2024. URL https:                        arXiv:2405.12532, 2024.
 //ai.meta.com/blog/meta-llama-3-1/. Ac-
 cessed: 2024-08-21.                                                  Zhang, X., Chen, Y., Hu, S., Xu, Z., Chen, J., Hao, M., Han,
                                                                        X., Thai, Z., Wang, S., Liu, Z., et al. bench: Extending
Ribar, L., Chelombiev, I., Hudlass-Galley, L., Blake, C.,               long context evaluation beyond 100k tokens. In Proceed-
  Luschi, C., and Orr, D. Sparq attention: Bandwidth-                   ings of the 62nd Annual Meeting of the Association for
  efficient llm inference. arXiv preprint arXiv:2312.04985,             Computational Linguistics (Volume 1: Long Papers), pp.
  2023.                                                                 15262–15277, 2024a.

                                                                 11
                     CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Zhang, Z., Sheng, Y., Zhou, T., Chen, T., Zheng, L., Cai,
  R., Song, Z., Tian, Y., Ré, C., Barrett, C., et al. H2o:
  Heavy-hitter oracle for efficient generative inference of
  large language models. Advances in Neural Information
  Processing Systems, 36:34661–34710, 2023.
Zhang, Z., Liu, S., Chen, R., Kailkhura, B., Chen, B., and
  Wang, A. Q-hitter: A better token oracle for efficient llm
  inference via sparse-quantized kv cache. Proceedings of
  Machine Learning and Systems, 6:381–394, 2024b.
Zhao, Y., Wu, D., and Wang, J. Alisa: Accelerating large
  language model inference via sparsity-aware kv caching.
  In 2024 ACM/IEEE 51st Annual International Symposium
  on Computer Architecture (ISCA), pp. 1005–1017. IEEE,
  2024.
Zhu, Y., Yuan, H., Wang, S., Liu, J., Liu, W., Deng, C.,
  Chen, H., Liu, Z., Dou, Z., and Wen, J.-R. Large language
  models for information retrieval: A survey. arXiv preprint
  arXiv:2308.07107, 2023.




                                                               12
                     CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

A. Further Observations
We expanded our exploration of sequential consistency to a wider selection of models, primarily focusing on the popular
models mentioned in the main text: Llama-3-8B-1M (Gradient, 2024a), Llama-3.1-8B (Meta AI, 2024), Phi-3-128K (Abdin
et al., 2024), and Yi-9B-200K (AI et al., 2024). In Figure 9, we visualized the attention weights heatmap for these four
models, illustrating the presence of both consistent and adaptive heads across various layers. This visualization supports the
generality of our observations. Consistent with the setup described in the main text, the heatmap in the figure comprises
attention weights associated with the last 20 query tokens during the pre-filling stage and all query tokens during the
decoding stage, employing a causal mask. And the samples are randomly excerpted from the WikiText-2 (Merity et al.,
2016) dataset.

B. Experiment Details
B.1. Implementation Details of Experiments
During the identification stage of CateKV, we employed an observation window and temporarily excluded initial tokens
and recent tokens from the context window. We set Lobs to 64, while Linit and Lrec were defined as 1/32 and 1/128 of the
sparse budget, respectively. We constructed the reference dataset based on the Variable Tracking task from the RULER
Benchmark, which comprises 100 samples, each with a length of 128K, distinct from the test set. The sparse budget was
set at 2048. According to the performance on the reference dataset, we selected the most appropriate percentile threshold
k and scaling factor α for each model. For the percentile threshold k, Llama3 and Llama3.1 were set at 0.996 and 0.984,
respectively, while other models were set at 0.99. For the scaling factor α, Llama3.1, and Yi were set at 0.8, while other
models were assigned a value of 1.0.
For the baseline methods, we configured the observation windows of SnapKV (Li et al., 2024) and PyramidKV (Cai et al.,
2024) to 32 and set the β in PyramidKV to 20. For StreamingLLM (Xiao et al., 2023), the initial tokens were set to 128.
Regarding Duoattention(Xiao et al., 2024b), we conducted experiments using the attention patterns provided by their code
available on GitHub.

B.2. Additional Results on RULER
B.2.1. P ERFORMANCE OF DIFFERENT CONTEXT LENGTHS ON RULER
We also conducted evaluations on various context lengths within the RULER benchmark. The Table 5 presents the
performance of CateKV on tasks with context lengths from 8K to 256K. CateKV is comparable to full attention in terms of
all lengths and average results and even shows slight improvements in performance at certain lengths when r = 0.4 and
η = 1.0.

                               Table 5: Performance of different context lengths on RULER

                      Methods               8K       16K      32K     64K      128K     256K     Avg.
                      Llama-3-8B-1M        91.47    92.87    90.31    86.44    84.10   79.79    87.50
                      CateKV               91.28    92.11    90.37    86.86    84.61   81.53    87.79
                      Phi-3-Mini-128K      92.02    91.42    91.24    87.89    72.06      -     86.93
                      CateKV               92.68    92.54    92.04    88.78    71.69      -     87.55
                      Llama-3.1-8B         94.78    94.95    94.61    93.02    84.55      -     92.38
                      CateKV               94.66    94.68    94.58    93.03    84.66      -     92.32
                      Yi-9B-200K           87.54    82.33    72.06    69.19    64.52      -     75.13
                      CateKV               87.17    81.68    71.85    69.25    65.76      -     75.14


B.2.2. C OMBINE WITH KV R ETRIEVAL M ETHODS
We combine CateKV with Quest (Tang et al., 2024b) and ShadowKV (Sun et al., 2024) and compare their performance with
the baseline under the same computational budget at a length of 128K. The results are shown in Table 6. CateKV helps

                                                             13
                     CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration

Table 6: Performance (%) of CateKV combined with KV retrieval methods. ’Budget’ refers to the computational budget for
sparse attention. CateKV can reduce memory. CateKV can help KV retrieval methods reduce memory usage to 41% while
maintaining accuracy.
 Methods              Budget N-S1      N-S2    N-S3 N-MK1 N-MK2 N-MK3 FWE N-MQ N-MV QA-1 QA-2 VT                      Avg.
 Llama-3-8B-1M         100%   100.00 100.00 100.00     98.96   98.96   41.67   71.88 98.69   96.35 73.96 50.00 78.75 84.10
 SnapKV                1.6%   100.00 100.00 14.58      98.96   96.88    0.00   61.11 98.44   96.88 68.75 48.96 79.38 72.00
 PyramidKV             1.6%   100.00 100.00 10.42      98.96   96.88    0.00   56.60 98.18   95.58 70.83 48.96 80.42 71.40
 Quest                 1.6%   100.00 100.00 100.00     98.96   97.92   19.79   58.33 98.96   96.61 72.91 52.08 80.20 81.31
 CateKV+Quest          1.6%   100.00 100.00 100.00     97.92   97.92   19.79   58.33 98.96   94.27 73.96 51.04 82.29 81.21
 ShadowKV              1.6%   100.00 100.00 100.00     97.92   93.75   21.88   75.69 98.96   96.09 72.92 50.00 78.96 82.18
 CateKV+ShadowKV       1.6%   100.00 100.00 100.00     97.92   89.58   21.88   75.35 98.70   94.79 71.88 51.04 81.25 81.86
 Phi-3-Mini-128K       100%    96.88   90.63   95.83   83.33   65.63   37.50   87.15 72.14   66.67 63.54 39.58 65.83 72.06
 SnapKV                1.6%    98.21   38.54   1.04    42.71   11.46    0.00   60.76 8.59     2.60 62.50 38.54 60.63 35.47
 PyramidKV             1.6%    97.92   39.58   0.00    46.88   11.46    0.00   56.94 10.16    2.08 59.38 39.58 60.42 35.37
 Quest                 1.6%    96.88   92.71   96.88   80.21   57.29   20.83   57.29 69.53   63.02 64.58 39.58 63.75 66.88
 CateKV+Quest          1.6%    96.88   92.71   96.88   80.21   57.29   18.75   55.56 68.75   64.32 64.58 39.58 62.50 66.50
 ShadowKV              1.6%    95.83   88.54   90.63   80.21   54.17   21.88   77.43 63.28   51.28 62.50 38.54 63.75 65.71
 CateKV+ShadowKV       1.6%    97.92   87.50   92.70   77.08   55.20   18.75   74.31 64.06   55.99 62.50 38.54 65.83 65.87
 Llama-3.1-8B          100%   100.00 100.00 98.96      98.96   90.63   63.54   71.53 98.96   95.31 81.25 46.88 68.54 84.55
 SnapKV                1.6%   100.00 100.00 41.67      98.96   79.17    0.00   59.72 97.14   91.67 81.25 44.79 62.92 71.44
 PyramidKV             1.6%   100.00 100.00 33.33      98.96   81.25    1.04   56.25 95.83   93.48 81.25 45.83 65.00 71.02
 Quest                 1.6%   100.00 100.00 100.00     98.96   78.13    4.17   59.03 98.70   94.01 80.21 50.00 68.96 77.68
 CateKV+Quest          1.6%   100.00 100.00 100.00     98.96   78.13    3.13   62.15 97.92   90.63 82.29 47.92 66.88 77.33
 ShadowKV              1.6%   100.00 100.00 98.96      98.96   77.08   13.54   70.49 98.18   90.36 81.25 48.96 64.17 78.50
 CateKV+ShadowKV       1.6%   100.00 100.00 100.00     98.96   73.96   13.54   65.97 98.44   90.89 80.21 50.00 67.08 78.25
 Yi-9B-200K            100%   100.00 100.00 98.96      85.42   63.54   18.75   89.24 66.41   32.55 45.83 38.54 35.00 64.52
 SnapKV                1.6%   100.00 93.75 5.21        80.21    6.25    0.00   75.69 54.95   18.23 40.63 36.46 52.92 47.02
 PyramidKV             1.6%   100.00 94.79 4.17        79.17    5.21    0.00   85.76 55.73   15.63 41.67 33.33 51.45 47.24
 Quest                 1.6%   100.00 97.92 98.96       85.42   64.58    4.17   67.01 66.14   38.39 42.71 36.46 48.33 62.51
 CateKV+Quest          1.6%   100.00 100.00 98.96      85.42   70.83    5.21   66.67 63.28   37.24 40.63 37.50 50.21 62.99
 ShadowKV              1.6%   100.00 100.00 97.92      87.50   60.42    2.08   75.35 59.64   34.11 43.75 37.50 54.79 62.76
 CateKV+ShadowKV       1.6%   100.00 100.00 97.92      84.38   58.33    2.08   82.29 59.38   33.85 43.75 36.46 47.29 62.14

reduce the memory usage of Quest and ShadowKV and significantly outperforms KV Eviction methods in terms of accuracy
with the same computational load.

B.3. Full Longbench Results
We present the complete experimental results for the Longbench in Table 7. We integrate CateKV with both the Full Attention
and KV retrieval methods, Quest(Tang et al., 2024b) and ShadowKV(Sun et al., 2024), and evaluate its performance on all
21 tasks in Longbench. The results showed that this integration did not lead to any significant drop in per-task accuracy, and
the average accuracy even outperformed the original methods, despite retaining only 42% of the KV cache size. For around
half of the tasks, the combination of CateKV with the original methods leads to a slight improvement in performance.

B.4. Additional Results in Needle In A Hystack
Figure B.4 displays the performance of the Llama3.1-8B, Phi-3-Mini-128K, and Yi-9B-200K models on the ’Needle In A
Haystack’ task. Compared to full attention, CateKV shows varied performance across different context windows and needle
depths, but maintains overall comparable performance. This suggests that CateKV does not significantly affect the models’
capacity to access and retrieve long-context semantic information.

B.5. Additional Results on Larger Models
We evaluated the performance of CateKV on larger models, setting the context length according to the maximum supported
by each model—128k for Qwen2.5-32B and Yi-34B-200K, and 16k for Phi-4-14B. As shown in Table 8, CateKV scales
effectively, achieving near full-attention accuracy on the 30B and 14B models, outperforming baseline methods such as
SnapKV and PyramidKV.


                                                               14
                   CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration




                                Table 7: Full LongBench results with Llama-3-8B-1M.

     Metrics                   Full   CateKV      Quest   CateKV+Quest           ShadowKV        CateKV+ShadowKV
     Average                  31.27    31.48      30.90         31.03              30.77               30.94
     NarrativeQA              18.61    18.64      19.54         17.93              18.43               17.74
     Qasper                   25.83    27.00      27.00         26.20              25.39               26.38
     MultiFieldQA-en          48.06    48.17      45.80         45.72              45.59               46.63
     MultiFieldQA-zh          33.76    33.68      34.23         33.37              34.23               33.65
     HotpotQA                 36.35    36.44      35.79         36.84              38.00               37.64
     2WikiMultihopQA          25.17    24.61      25.48         24.07              24.92               25.98
     MuSiQue                  21.08    20.41      20.18         19.56              20.70               20.22
     DuReader                 30.98    28.62      29.23         27.36              29.82               27.91
     GovReport                23.38    23.45      23.96         23.53              22.35               22.85
     QMSum                    25.45    24.74      24.59         24.66              24.67               24.29
     MultiNews                22.63    21.42      23.30         21.10              23.53               21.10
     VCSUM                    14.19    13.90      14.21         13.93              13.86               13.86
     TREC                     39.00    41.83      39.11         39.49              37.69               39.49
     TriviaQA                 16.81    16.91      16.67         16.73              17.08               16.91
     SAMSum                   26.46    26.59      26.66         25.16              26.02               25.61
     LSHT                     31.58    32.00      24.75         33.25              29.68               29.96
     PassageCount              1.00    1.00        1.00         1.00                1.00               1.00
     PassageRetrieval-en      81.00    80.50      74.50         80.50              80.00               80.50
     PassageRetrieval-zh      43.73    43.61      42.85         42.50              39.39               38.98
     LCC                      48.31    50.08      51.30         51.45              49.06               50.69
     RepoBench-P              43.21    47.58      48.73         48.27              43.84               48.45




                                Table 8: Performance (%) of CateKV on larger models
Methods        Cache   N-S1   N-S2    N-S3 N-MK1 N-MK2 N-MK3 FWE N-MQ N-MV QA-1 QA-2                            VT     Avg.
Qwen2.5-32B 100% 100.00 87.50         97.92    70.83   15.63     7.29    90.28   87.24   85.16   51.04 41.67   85.41   68.33
SnapKV       41% 100.00 88.54         51.04    69.79   12.50     2.08    88.54   76.82   76.82   51.04 41.67   85.83   62.06
PyramidKV    41% 100.00 87.50         46.88    66.67    8.33     1.04    84.02   66.93   67.71   48.96 41.67   84.79   58.71
CateKV       41% 100.00 86.46         95.83    71.88   14.58     6.25    89.58   86.88   86.28   50.00 43.75   86.67   68.18
Yi-34B-200K    100%    100.00 100.00 100.00    92.71   70.83    47.92    86.11   97.14   92.45   68.75 47.92   88.05   82.66
SnapKV          41%    100.00 97.92 80.21      90.62   22.92    17.71    81.25   91.15   72.14   67.71 47.92   86.25   71.32
PyramidKV       41%    100.00 100.00 68.75     91.67   26.04    12.50    82.99   91.15   79.43   69.79 47.92   86.46   71.39
CateKV          41%    100.00 100.00 100.00    92.71   73.96    47.92    85.12   97.14   91.15   67.71 46.88   87.08   82.47
Phi-4-14B      100%    100.00 97.92 100.00 100.00      97.92    100.00   98.96   98.96   99.22   80.21 67.71 100.00    95.08
SnapKV          43%    100.00 100.00 7.29 100.00       93.75     3.13    99.31   97.66   99.22   82.29 66.67 100.00    79.11
PyramidKV       43%    100.00 100.00 3.13 100.00       94.79     5.21    98.96   98.44   98.44   80.21 67.71 100.00    78.91
CateKV          43%    100.00 98.96 100.00 97.92       98.96    100.00   99.31   98.44   99.48   78.13 67.71 99.79     94.89




                                                           15
                    CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration


                             Consistent Head                                         Adaptive Head
Pre-filling
Decoding          Layer 5 Head 3         Layer 24 Head 7                Layer 5 Head 2          Layer 26 Head 3




                                                   (a) Llama-3-8B-1M

                             Consistent Head                                         Adaptive Head
                  Layer 5 Head 3         Layer 23 Head 7                Layer 5 Head 2          Layer 14 Head 0
Pre-filling
Decoding




                                                    (b) Llama-3.1-8B

                             Consistent Head                                         Adaptive Head
                  Layer 8 Head 3         Layer 28 Head 12               Layer 7 Head 14         Layer 26 Head 28
Pre-filling
Decoding




                                                  (c) Phi-3-Mini-128K

                             Consistent Head                                         Adaptive Head
                  Layer 8 Head 1         Layer 24 Head 1                Layer 5 Head 3          Layer 27 Head 2
Pre-filling
Decoding




                                                     (d) Yi-9B-200K

          Figure 9: Sequential consistency in Llama-3-8B-1M, Llama-3.1-8B, Phi-3-Mini-128K and Yi-9B-200K

                                                            16
                                      CateKV: On Sequential Consistency for Long-Context LLM Inference Acceleration




                       Needle in A Haystack Llama-3.1-8B-Instruct     1.0                              Needle in A Haystack Llama-3.1-8B-Instruct w/ CateKV     1.0
                  0                                                                                0
                 11                                                                               11
                                                                      0.8                                                                                       0.8
                 22                                                                               22
Depth Percent (%)




                                                                                 Depth Percent (%)
                 33                                                                               33
                                                                      0.6                                                                                       0.6
                 44                                                                               44
                 56                                                                               56
                                                                      0.4                                                                                       0.4
                 67                                                                               67
                 78                                                                               78
                                                                      0.2                                                                                       0.2
                 89                                                                               89
                100                                                                              100
                                                                      0.0                                                                                       0.0
                     20K
                     20K
                     30K
                     40K
                     50K
                     60K
                     60K
                     70K
                     80K
                     90K
                        K
                        K
                        K
                        K
                        K




                                                                                                      20K
                                                                                                      20K
                                                                                                      30K
                                                                                                      40K
                                                                                                      50K
                                                                                                      60K
                                                                                                      60K
                                                                                                      70K
                                                                                                      80K
                                                                                                      90K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                    100
                    100
                    110
                    120
                    128




                                                                                                     100
                                                                                                     100
                                                                                                     110
                                                                                                     120
                                                                                                     128
                                     Context Length                                                                       Context Length
                                (a) Llama-3.1-8B-Instruct                                                     (b) Llama-3.1-8B-Instruct w/ CateKV

                      Needle in A Haystack Phi-3-mini-128k-instruct   1.0                              Needle in A Haystack Phi-3-mini-128k-instruct w/CateKV   1.0
                  0                                                                                0
                 11                                                                               11
                                                                      0.8                                                                                       0.8
                 22                                                                               22
Depth Percent (%)




                                                                                 Depth Percent (%)


                 33                                                                               33
                                                                      0.6                                                                                       0.6
                 44                                                                               44
                 56                                                                               56
                                                                      0.4                                                                                       0.4
                 67                                                                               67
                 78                                                                               78
                                                                      0.2                                                                                       0.2
                 89                                                                               89
                100                                                                              100
                                                                      0.0                                                                                       0.0
                     16K
                     24K
                     32K
                     39K
                     47K
                     55K
                     63K
                     70K
                     78K
                     86K
                     94K
                        K
                        K
                        K
                        K




                                                                                                      16K
                                                                                                      24K
                                                                                                      32K
                                                                                                      39K
                                                                                                      47K
                                                                                                      55K
                                                                                                      63K
                                                                                                      70K
                                                                                                      78K
                                                                                                      86K
                                                                                                      94K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                    102
                    109
                    117
                    125




                                                                                                     102
                                                                                                     109
                                                                                                     117
                                                                                                     125
                                     Context Length                                                                       Context Length
                              (c) Phi-3-mini-128k-instruct                                                  (d) Phi-3-mini-128k-instruct w/ CateKV

                            Needle in A Haystack Yi-9B-200K           1.0                                    Needle in A Haystack Yi-9B-200K w/CateKV           1.0
                  0                                                                                0
                 11                                                                               11
                                                                      0.8                                                                                       0.8
                 22                                                                               22
Depth Percent (%)




                                                                                 Depth Percent (%)




                 33                                                                               33
                                                                      0.6                                                                                       0.6
                 44                                                                               44
                 56                                                                               56
                                                                      0.4                                                                                       0.4
                 67                                                                               67
                 78                                                                               78
                                                                      0.2                                                                                       0.2
                 89                                                                               89
                100                                                                              100
                                                                      0.0                                                                                       0.0
                     20K
                     30K
                     40K
                     60K
                     70K
                     80K
                        K
                        K
                        K
                        K
                        K
                        K
                        K
                        K
                        K




                                                                                                      20K
                                                                                                      30K
                                                                                                      40K
                                                                                                      60K
                                                                                                      70K
                                                                                                      80K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                                                                                                         K
                    100
                    110
                    120
                    130
                    150
                    160
                    170
                    190
                    200




                                                                                                     100
                                                                                                     110
                                                                                                     120
                                                                                                     130
                                                                                                     150
                                                                                                     160
                                                                                                     170
                                                                                                     190
                                                                                                     200




                                     Context Length                                                                       Context Length
                                       (e) Yi-9B-200k                                                                (f) Yi-9B-200k w/ CateKV

Figure 10: NIAH Results on Llama-3.1-8B-Instruct(Meta AI, 2024), Phi-3-mini-128k-instruct (Abdin et al., 2024) and
Yi-9B-200k (AI et al., 2024)




                                                                            17
