TL;DR
MapFlow is a novel system that enables efficient prefix caching across different (heterogeneous) Large Language Models. By reusing attention maps—which capture universal token dependencies—rather than model-specific KV caches, MapFlow reduces prefill latency by 15–20% and improves system throughput by up to 25% in multi-model workflows without sacrificing generation quality.
What Problem Does This Paper Address?
Modern AI applications often chain multiple LLMs together. For example, a "router" might send a complex reasoning task to a large model (like Qwen-72B) and a simple formatting task to a smaller one (like Qwen-7B). These models often share a massive amount of context, such as long database schemas, system instructions, or conversation history.
Existing systems use "prefix caching" to speed up inference by saving the intermediate states (Key-Value or KV caches) of these shared prefixes. However, KV caches are tightly coupled to a specific model's architecture (its hidden dimensions and weights). If you switch from a 14B model to a 3B model, the cached KV states are useless, forcing the system to recompute the entire prefix from scratch. This "prefill bottleneck" leads to high latency and wasted compute in multi-model pipelines.
Methods
The authors introduce MapFlow, which shifts the focus from caching latent representations (KV states) to caching semantic structures (attention maps).
1. Attention Map Reuse
Unlike KV tensors, attention maps represent "which token attends to which." The authors observe that models sharing the same tokenizer exhibit remarkably similar attention patterns for the same text. MapFlow transfers these maps from a "sender" model to a "receiver" model.
2. Partial Recomputation & Linear Translation
Not all layers are created equal. MapFlow recomputes the first few layers of the receiver model to establish accurate hidden states and then reuses attention maps for the remaining layers. To bridge the gap between different numbers of attention heads, MapFlow uses a lightweight linear translation (a small learned matrix) to map sender heads to receiver heads.
3. System Optimizations
Storing raw attention maps is expensive because they grow quadratically ($O(L^2)$) with sequence length. MapFlow tackles this with:
- Block-level Sparse Compression: It identifies and stores only the most important "blocks" of the attention map (top-$p$ filtering), drastically reducing memory usage.
- Fused Retrieval Kernel: A custom GPU kernel that performs decompression, head translation, and value aggregation in a single pass, avoiding the need to ever materialize a massive, dense attention matrix in memory.
Datasets
The authors evaluated MapFlow across several diverse benchmarks:
- HotpotQA: For multi-hop question answering.
- LMSYS & ShareGPT4: For real-world conversation routing.
- Multi-News: For document summarization.
- RULER: Specifically used to test long-context performance (up to 20k tokens).
- 2WikiMultihopQA: Used to test how well the learned translation weights generalize to new datasets.
Key Insights and Ideas
- Attention is Universal: While internal model "thoughts" (KV states) are model-specific, the "structure of attention" is a transferable semantic primitive.
- Linearity Suffices: Surprisingly, a simple linear combination of heads from a larger model can accurately reconstruct the attention heads of a smaller model within the same family.
- The "Early Layer" Rule: The first few layers of a Transformer are often noisy or highly model-specific. By recomputing just the first 1–3 layers, the system maintains high accuracy while still saving the bulk of the prefill work.
- System-Algorithm Co-design: The speedups don't just come from the math; they come from the custom CUDA kernels that prevent memory bloat, which is the traditional death knell for $O(L^2)$ attention-based methods.
Key Results
- Latency: MapFlow reduces Time-to-First-Token (TTFT) by 15%–20% compared to full recomputation.
- Throughput: In multi-turn routing scenarios, it improves end-to-end throughput by up to 25% under the same latency constraints.
- Quality: Unlike previous attempts at cross-model reuse (like CacheBlend), MapFlow maintains generation quality (F1 and ROUGE scores) across heterogeneous pairs like Qwen-14B $\rightarrow$ 8B or Ministral-8B $\rightarrow$ 3B.
- Efficiency: In a three-model agentic workflow (14B $\rightarrow$ 8B $\rightarrow$ 3B), MapFlow saved up to 0.73 seconds per round, proving that compression costs are easily amortized across multiple downstream models.
Limitations and Future Work
- Shared Tokenization: Currently, MapFlow requires models to share the same tokenizer (e.g., staying within the Llama 3 or Qwen family). Extending this to models with different vocabularies would require complex token-level alignment.
- Memory at Extreme Scales: While sparsity helps, attention maps still occupy significant memory for extremely long contexts (100k+ tokens). The authors suggest exploring quantized or low-rank representations for even better scaling.
- Offline Calibration: The system requires a one-time offline training step to learn the head-mapping weights for each model pair, though this cost is small (a few GPU hours) and only needs to be done once per pair.
Summary updated