            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
