LazyMAR: Accelerating Masked Autoregressive Models via Feature Caching

October 24, 2025 ยท View on GitHub

LazyMAR: Accelerating Masked Autoregressive Models via Feature Caching

๐ŸŽ‰ Accepted to ICCV 2025 ๐ŸŽ‰

๐Ÿ“– Abstract

Masked Autoregressive (MAR) models have emerged as a promising approach in image generation, expected to surpass traditional autoregressive models in computational efficiency by leveraging the capability of parallel decoding. However, their dependence on bidirectional self-attention inherently conflicts with conventional KV caching mechanisms, creating unexpected computational bottlenecks that undermine their expected efficiency.

To address this problem, this paper studies the caching mechanism for MAR by leveraging two types of redundancy:

  • Token Redundancy indicates that a large portion of tokens have very similar representations in the adjacent decoding steps, which allows us to first cache them in previous steps and then reuse them in the later steps.
  • Condition Redundancy indicates that the difference between conditional and unconditional output in classifier-free guidance exhibits very similar values in adjacent steps.

Based on these two redundancies, we propose LazyMAR, which introduces two caching mechanisms to handle them one by one. LazyMAR is training-free and plug-and-play for all MAR models. Experimental results demonstrate that our method achieves 2.83ร— acceleration with almost no drop in generation quality.

๐Ÿ“‹ Dependencies

  • Python >= 3.8
  • CUDA >= 11.8
  • PyTorch >= 2.2.2

๐Ÿ›  Installation

Download the code:

git clone https://github.com/feihongyan1/LazyMAR.git
cd LazyMAR

Environment Setup

A suitable conda environment named lazymar can be created and activated with:

conda env create -f environment.yaml
conda activate lazymar

Pre-trained Models

Download pre-trained VAE and LazyMAR models (weights are provided by MAR):

LazyMAR ModelFID-50KInception Score#paramsDownload Link
LazyMAR-B2.45281.3208MDropbox
LazyMAR-L1.93297.4479MDropbox
LazyMAR-H1.69299.2943MDropbox

VAE Model: Download the pre-trained VAE model from Dropbox

Place the downloaded checkpoints in pretrained_models/ directory:

pretrained_models/
โ”œโ”€โ”€ mar/
โ”‚   โ”œโ”€โ”€ mar_base/
โ”‚   โ”‚   โ””โ”€โ”€ checkpoint-last.pth
โ”‚   โ”œโ”€โ”€ mar_large/
โ”‚   โ”‚   โ””โ”€โ”€ checkpoint-last.pth
โ”‚   โ””โ”€โ”€ mar_huge/
โ”‚       โ””โ”€โ”€ checkpoint-last.pth
โ””โ”€โ”€ vae/
    โ””โ”€โ”€ kl16.ckpt

๐Ÿš€ Run and Evaluation

Image Generation with LazyMAR

Generate 50k images for evaluation on ImageNet-256:

CUDA_VISIBLE_DEVICES=0,1 torchrun --master_port=26586 --nproc_per_node=2 \
  --nnodes=1 --node_rank=0 eval.py \
  --num_images 50000 \
  --eval_bsz 128 \
  --num_iter 64 \
  --lazy_mar

Baseline MAR (without LazyMAR)

To compare with the baseline MAR model without acceleration:

CUDA_VISIBLE_DEVICES=0,1 torchrun --master_port=26586 --nproc_per_node=2 \
  --nnodes=1 --node_rank=0 eval.py \
  --num_images 50000 \
  --eval_bsz 128 \
  --num_iter 64

Key Arguments

  • --lazy_mar: Enable LazyMAR acceleration (training-free and plug-and-play)
  • --num_iter: Number of autoregressive iterations (default: 64)
  • --eval_bsz: Batch size for evaluation (default: 128)
  • --num_images: Number of images to generate (default: 50000)
  • --model: Model architecture choice: mar_base, mar_large, or mar_huge (default: mar_huge)
  • --cfg: Classifier-free guidance scale (default: 3.25)

๐Ÿ“Š Performance

LazyMAR achieves significant speedup while maintaining generation quality on ImageNet 256ร—256 class-conditional generation.

Testing Hardware: NVIDIA GeForce RTX 3090 GPU

Main Results (64 Decoding Steps)

ModelLatency (GPU)Latency (CPU)FLOPsSpeedupFID โ†“IS โ†‘
MAR-H1.74s116.61s69.06T1.00ร—1.59299.1
LazyMAR-H0.75s43.12s24.38T2.83ร—1.69299.2
MAR-L0.93s59.66s35.05T1.00ร—1.82296.1
LazyMAR-L0.40s22.82s12.52T2.80ร—1.93297.4
MAR-B0.47s28.97s15.49T1.00ร—2.32281.1
LazyMAR-B0.21s11.08s5.54T2.80ร—2.45281.3

๐ŸŽฏ Key Features

  • โšก High Acceleration: Achieves 2.83ร— speedup with 64.7% FLOPs reduction and minimal quality loss
  • ๐Ÿ”Œ Training-Free & Plug-and-Play: No retraining required, simple integration via --lazy_mar flag
  • ๐Ÿ’ก Dual Caching Mechanisms: Leverages both token redundancy and condition redundancy
  • ๐Ÿ’พ Memory Efficient: Intelligent caching reduces redundant computations

๐Ÿ‘ Acknowledgements

  • Thanks to MAR for their great work and codebase upon which we build LazyMAR.
  • Thanks to the community for the pre-trained VAE models.

๐Ÿ“ง Contact

If you have any questions, feel free to contact us through email:

๐Ÿ“ฎ 3120235162@bit.edu.cn

๐Ÿ“Œ Citation

If you find our work useful, please consider citing:

@InProceedings{Yan_2025_ICCV,
    author    = {Yan, Feihong and Wei, Qingyan and Tang, Jiayi and Li, Jiajun and Wang, Yulin and Hu, Xuming and Li, Huiqi and Zhang, Linfeng},
    title     = {LazyMAR: Accelerating Masked Autoregressive Models via Feature Caching},
    booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
    month     = {October},
    year      = {2025},
    pages     = {15552-15561}
}

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Enjoy!


โญ If you find this project helpful, please consider giving it a star! โญ