LazyMAR: Accelerating Masked Autoregressive Models via Feature Caching

Feihong Yan, Qingyan Wei, Jiayi Tang, Jiajun Li, Yulin Wang, Xuming Hu, Huiqi Li, Linfeng Zhang

TL;DR

Masked Autoregressive (MAR) models, while promising for efficient image generation, are hampered by their inability to use standard KV caching due to bidirectional attention. This paper introduces LazyMAR, a training-free, plug-and-play framework that employs "Token Cache" and "Condition Cache" to exploit redundancies, achieving up to 2.83x acceleration with minimal quality degradation.

What Problem Does This Paper Address?

Autoregressive models have revolutionized natural language processing and are increasingly applied to image generation. However, their sequential nature leads to slow generation. Masked Autoregressive (MAR) models aim to overcome this by predicting tokens in parallel using bidirectional attention. While this improves efficiency, it conflicts with the standard Key-Value (KV) caching mechanism, which is crucial for accelerating autoregressive models. The bidirectional attention in MARs requires recomputing all token representations at each step, creating a computational bottleneck that negates much of the potential efficiency gains. This paper addresses this fundamental inefficiency by proposing novel caching strategies tailored specifically for MAR models.

Methods

LazyMAR introduces two primary caching mechanisms:

  • Token Cache: This mechanism exploits "Token Redundancy," observing that many tokens in adjacent decoding steps have similar representations. It caches features of tokens from previous steps and reuses them in later steps. To maintain quality, it selectively computes tokens that exhibit significant differences from their cached counterparts, prioritizing those with high cosine similarity to their cached values. This strategy is informed by an analysis of how different types of tokens (predicted, unpredicted, current, future) are affected by caching.
  • Condition Cache: This mechanism addresses "Condition Redundancy" arising from classifier-free guidance (CFG), which uses both conditional and unconditional pathways, doubling computation. The paper observes that the residual between the conditional and unconditional outputs in adjacent steps is much smaller than the individual outputs. Condition Cache stores this residual and uses it to approximate the unconditional pathway's output, effectively skipping one of the two branches and halving computation for CFG.

A crucial component of LazyMAR is the Periodic Cache-Reuse-Refreshment strategy. To prevent the accumulation of approximation errors from iterative caching, the system periodically disables caching, performs full computations, and refreshes the cache with ground-truth values. This ensures long-term stability and accuracy.

Datasets

The paper uses ImageNet for class-conditional generation experiments. Specifically, they evaluate on the ImageNet 256x256 resolution benchmark.

Key Insights and Ideas

  • MAR's KV Cache Incompatibility is a Bottleneck: The core problem is that bidirectional attention in MAR models fundamentally breaks standard KV caching, leading to significant inefficiency despite parallel decoding.
  • Redundancy is Key: The paper identifies two key redundancies in MARs: token similarity across steps and the small residual in CFG outputs.
  • Token Cache Selectivity Matters: Not all tokens are equal for caching. LazyMAR's success hinges on selectively caching tokens with high similarity to their previous states, while recomputing those with significant changes.
  • Value Matrix is a Better Caching Criterion: The paper finds that the value matrix in self-attention layers is a more reliable indicator for deciding whether to cache a token than token features themselves.
  • Condition Cache Halves CFG Cost: Exploiting the small residual in CFG pathways offers a straightforward way to cut computation by half for this common technique.
  • Periodic Refreshment is Crucial: To combat error accumulation from caching, a periodic refresh strategy is essential for maintaining generation quality over long sequences.

Key Results

LazyMAR achieves significant acceleration with minimal impact on generation quality:

  • Speedup: Up to 2.83x acceleration is reported on MAR models (e.g., LazyMAR-H, 64).
  • Quality: The method maintains comparable image generation quality, with only a 0.1 increase in FID score compared to the original MAR model.
  • Comparison to Step Reduction: LazyMAR outperforms simply reducing the number of decoding steps, achieving better FID and Inception Scores.
  • Ablation Studies: Both Token Cache and Condition Cache contribute to the overall speedup, with their combined use yielding optimal results. The proposed "LazyMAR" strategy (caching high-similarity tokens) outperforms other token selection strategies.

Limitations and Future Work

  • Error Accumulation Mitigation: While the periodic cache-reuse-refreshment strategy is effective, the paper acknowledges the potential for "progressive accumulation of approximation errors through iterative cache reuse." The periodic refreshment is a mechanism to mitigate this.
  • Training-Free and Plug-and-Play: A significant strength is that LazyMAR is training-free and can be applied to existing MAR models without retraining. This makes it highly practical.
  • Future Work: The paper doesn't explicitly detail future work, but the success of LazyMAR suggests potential for further optimization of the caching strategies, exploration of different refresh intervals, and application to other MAR architectures or related generative models.

Summary updated

BibTeX
@inproceedings{yan2025lazymar,
  author = {Feihong Yan and Qingyan Wei and Jiayi Tang and Jiajun Li and Yulin Wang and Xuming Hu and Huiqi Li and Linfeng Zhang},
  title = {{LazyMAR: Accelerating Masked Autoregressive Models via Feature Caching}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2025},
}
Figure