                      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
