Head-Aware KV Cache Compression for Efficient Visual Autoregressive Modeling

Ziran Qin, Youru Lv, Mingbao Lin, Hang Guo, Zeren Zhang, Danping Zou, Weiyao Lin

TL;DR

Visual Autoregressive (VAR) models generate high-quality images efficiently but suffer from massive memory and computational costs due to accumulating KV caches. This paper introduces HACK, a novel head-aware KV cache compression framework that intelligently compresses caches based on distinct attention head functionalities, achieving significant memory reduction and speedup without sacrificing image quality.

What Problem Does This Paper Address?

Visual Autoregressive (VAR) models have emerged as a powerful alternative to traditional autoregressive models for image generation. Unlike "next-token" prediction, VAR models use a "next-scale" paradigm, generating multiple tokens in parallel across different resolutions. This allows for faster generation of high-quality content. However, a major bottleneck for VAR models during inference is the significant memory overhead and computational complexity stemming from the accumulation of Key-Value (KV) caches. In a standard VAR model, all KV pairs from previous scales are stored, leading to quadratic growth in memory and quartic growth in attention complexity ($O(n^4)$). This makes deploying VAR models, especially for high-resolution images, computationally prohibitive. Existing KV cache compression methods, primarily developed for Large Language Models (LLMs), are not directly applicable to VAR models due to fundamental differences in their attention mechanisms.

Methods

The core of HACK lies in its Head-Aware KV Cache Compression strategy. This approach is built upon a crucial observation: attention heads in VAR models can be broadly categorized into two types:

  • Contextual Heads: These heads focus on maintaining semantic consistency by attending to a small set of key tokens, exhibiting "vertical" attention patterns.
  • Structural Heads: These heads are responsible for preserving spatial coherence by attending to spatially adjacent tokens across scales, displaying "multi-diagonal" attention patterns.

HACK leverages this distinction through a three-step process:

  1. Offline Head Classification: An unsupervised, training-free classification scheme is employed. It analyzes the attention variance across different samples and scales to distinguish between contextual and structural heads. Heads with low variance are classified as contextual, while those with high variance are structural.
  2. Asymmetric Head Budget Allocation: Based on the classification and the observed sensitivity of each head type to compression (structural heads are more sensitive), HACK allocates asymmetric KV cache budgets. Contextual heads receive smaller budgets, while structural heads get larger ones. This is achieved by defining a contextual head ratio ($\alpha$) and a per-head budget ($B$), leading to individual budgets ($B_c$ and $B_s$) for each type.
  3. Pattern-Specific Compression Strategies: Tailored compression strategies are applied to each head type:
  4. Contextual Heads: A "TOPK" selection strategy is used, retaining KV pairs with the highest cumulative attention scores. A merging operation is applied at the final scale to reintegrate evicted tokens.
  5. Structural Heads: A scale-aware strategy is employed, prioritizing tokens from the initial and recent scales, and then using subset attention to select intermediate-scale tokens based on their importance.

This head-aware approach allows HACK to effectively reduce the theoretical attention complexity from $O(n^4)$ to $O(Bn^2)$, where $B$ is the average compressed cache length per head.

Datasets

The paper evaluates HACK on several benchmarks and models:

  • Text-to-Image Generation:
    • Infinity-2B and Infinity-8B (Han et al., 2024)
    • Hart (Tang et al., 2024)
    • Benchmarks used for evaluation include GenEval, ImageReward (IR), HPSv2.1 (HPS), and MJHQ30k (using FID and CLIP scores).
  • Class-Conditional Generation:
    • VAR-d30 (Tian et al., 2024)
    • Evaluated on ImageNet-1K using FID, Inception Score (IS), Precision, and Recall.

No new datasets were introduced in this paper.

Key Insights and Ideas

  • Functional Dichotomy of Attention Heads: The most significant insight is that attention heads in VAR models are not monolithic. They exhibit distinct, stable functional roles (semantic vs. structural) that are largely invariant to specific input samples. This provides a strong inductive prior for optimizing attention mechanisms.
  • Compression Sensitivity Varies by Head Type: Structural heads are much more sensitive to compression than contextual heads. Aggressively compressing structural heads leads to severe spatial distortions, while contextual heads can tolerate higher compression ratios with less impact on semantic quality. This justifies the asymmetric budget allocation.
  • Head-Awareness is Crucial for VAR Compression: One-size-fits-all compression methods, effective in LLMs, fail to generalize to VAR models because they don't account for these functional differences. HACK's head-aware approach is key to its success.
  • Offline Classification is Sufficient and Efficient: The paper demonstrates that a simple, offline classification based on attention variance, using a small number of samples, is highly effective and stable. This avoids the need for computationally expensive online classification or retraining.
  • HACK Preserves Quality Even at High Compression: The results show that HACK can achieve substantial compression (up to 70%) without degrading image quality, and in some cases, even surpassing full KV cache performance by removing redundancy.

Key Results

  • Significant Memory Reduction and Speedup: HACK achieves up to 70% KV cache compression. For example, on Infinity-8B, it provides a 1.75x memory reduction and a 1.57x speedup.
  • Preservation of Generation Quality: HACK consistently maintains high generation quality across various metrics (FID, IS, Precision, Recall, ImageReward, GenEval, HPS, CLIP) and models, even at extreme compression ratios (e.g., 90%).
  • Superiority over Baselines: HACK outperforms existing eviction-based and merging-based KV cache compression methods, especially at higher compression ratios, where baselines often exhibit significant performance degradation.
  • Reduced Attention Complexity: HACK reduces the theoretical attention complexity from $O(n^4)$ to $O(Bn^2)$.
  • Robustness to Hyperparameters: The method shows consistent performance across a wide range of hyperparameter settings for contextual head ratio and budget allocation, indicating its robustness.

Limitations and Future Work

  • Limitations:
    • The paper primarily focuses on optimizing attention modules. Other components of VAR models, such as Feed-Forward Networks (FFNs), are not directly addressed for efficiency gains.
  • While HACK is effective, it relies on an offline classification step. Although this step is fast and data-efficient, it is still an additional preprocessing stage.
  • Future Work:
    • Synergy with Other Efficiency Techniques: Exploring combinations of HACK with orthogonal efficiency methods like collaborative decoding, quantization, and token pruning for FFNs could lead to further improvements.
  • Generalizability to Other AR Models: The insights into head functionality and compression strategies could be extended to conventional autoregressive visual generation models beyond the next-scale VAR paradigm.
  • Online Classification: Investigating online head classification methods might offer dynamic adaptation, though the current offline approach is shown to be highly effective and efficient.

Summary updated

BibTeX
@inproceedings{qin2026head,
  author = {Ziran Qin and Youru Lv and Mingbao Lin and Hang Guo and Zeren Zhang and Danping Zou and Weiyao Lin},
  title = {{Head-Aware KV Cache Compression for Efficient Visual Autoregressive Modeling}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i30.39686},
}
Figure