MEDA: Dynamic KV Cache Allocation for Efficient Multimodal Long-Context Inference

Zhongwei Wan, Hui Shen, Xin Wang, Che Liu, Zheda Mai, Mi Zhang

Introduction

Multimodal Large Language Models (MLLMs) are increasingly tasked with processing massive inputs, ranging from hour-long videos to hundreds of high-resolution images. While these models offer powerful reasoning capabilities, they face a significant "memory wall" due to the Key-Value (KV) cache. This cache stores previous computations to accelerate generation, but its size grows linearly with input length, often exceeding the memory limits of standard hardware.

The Problem: The Inefficiency of Uniform Allocation

Existing KV cache compression methods typically treat every layer of a neural network identically, assigning a uniform memory budget to each. However, research into MLLM internals reveals that this is highly inefficient. Some layers exhibit "dense" attention, requiring a broad view of the entire context, while others are "sparse," focusing on a few critical tokens. Forcing a uniform budget leads to significant information loss in dense layers and wasted capacity in sparse ones.

The MEDA Framework

To overcome these limitations, researchers introduced MEDA (Multimodal Attention Entropy-Guided Dynamic KV Cache Allocation). MEDA is a training-free framework that optimizes memory usage by dynamically allocating the KV cache based on the informational "entropy" of each layer.

The MEDA framework architecture, illustrating the transition from prompt encoding with cross-modal attention entropy calculation to dynamic KV cache allocation and merging in the decoding stage.

The framework consists of three primary components:

  1. Cross-Modal Attention Entropy: During the initial prompt encoding, MEDA calculates the entropy of attention weights between text and visual tokens. High entropy indicates a layer with diffused, complex interactions, while low entropy indicates highly focused attention.
  2. Dynamic Layer-wise Allocation: Using an inverse entropy softmax strategy, MEDA distributes the total memory budget. Layers with higher entropy are dynamically granted a larger portion of the KV cache to preserve their complex representations.
  3. Multimodal KV Pair Merging: Instead of simply deleting (evicting) unimportant tokens to fit the budget, MEDA uses a many-to-one merging strategy. It identifies the most important tokens and merges the information from their less important neighbors into them, ensuring the model retains a global understanding of the context.

Key Insights: The Non-Uniformity of Attention

The core insight behind MEDA is the observation that attention entropy is not uniform across the model's depth. Early layers in MLLMs tend to have much higher attention entropy as they process raw multimodal inputs. As information moves deeper into the network, attention often becomes more specialized and sparse.

Visualization of attention matrices for Layer 1 and Layer 24 alongside the cross-modal attention entropy across different datasets, highlighting the shift from dense to sparse attention patterns.

By acknowledging these patterns, MEDA ensures that the "dense" early layers have the resources they need to capture the full scope of the input, while "sparse" deeper layers are compressed more aggressively to save space.

Experimental Results

The researchers evaluated MEDA across a wide range of multimodal benchmarks, including MileBench, Video-ChatGPT, and WorldQA, using models like LLaVA-v1.5, LLaVA-NeXT, and InternVL-v1.5.

  • Efficiency: MEDA achieved up to a 72% reduction in KV cache memory usage.
  • Speed: The reduction in memory overhead enabled up to 2.82x faster decoding speeds compared to full-cache models.
  • Performance: On the MileBench benchmark, MEDA consistently outperformed state-of-the-art compression methods like H2O and SnapKV. In many tests, it matched the performance of the uncompressed "Full Cache" model while using only a fraction of the memory.

Conclusion and Future Work

MEDA provides a robust, "plug-and-play" solution for the memory challenges of long-context multimodal inference. By replacing static, uniform compression with dynamic, entropy-guided allocation and information merging, it enables models to handle vast amounts of data more efficiently. Future research may explore combining MEDA with other techniques like quantization to achieve even greater levels of compression.

Summary updated

BibTeX
@inproceedings{wan2025meda,
  author = {Zhongwei Wan and Hui Shen and Xin Wang and Che Liu and Zheda Mai and Mi Zhang},
  title = {{MEDA: Dynamic KV Cache Allocation for Efficient Multimodal Long-Context Inference}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.125},
}
Figure