OnlineCache: Learning Dynamic Caching Policies with Error Correction for Efficient Diffusion Inference

Zhikang Xie, Xichen Ye, Yifan Wu, Haoshen Yu, Li chenan, Peizhu Gong, Weizhong Zhang, Cheng JinarXiv 2026

TL;DR

OnlineCache introduces a dynamic, instance-aware caching framework for diffusion model inference that learns exactly when to reuse intermediate features and how to correct the resulting errors. By framing caching as a sequential decision-making problem optimized via bilevel optimization, it delivers up to a 3× speedup on state-of-the-art models like FLUX.1-dev without sacrificing generation quality.

What Problem Does This Paper Address?

Diffusion models excel at generating high-fidelity images, videos, and audio, but their iterative denoising process makes them computationally expensive and slow during inference. To accelerate them, researchers often turn to feature caching—reusing intermediate representations across adjacent timesteps to skip heavy neural network evaluations.

However, existing cache-based methods rely on rigid, static schedules or local, greedy heuristics. The authors identify two major flaws in this "one-size-fits-all" approach:

  1. Sample-level heterogeneity: Complex prompts require more computation to resolve fine details, whereas simpler prompts can tolerate aggressive caching.
  2. Timestep-level heterogeneity: Error sensitivity fluctuates wildly throughout the denoising trajectory. Caching at highly sensitive steps destroys image quality, while computing at redundant steps wastes time.
Figure 1: Comparison of static strategy (ERTACache) and ours (OnlineCache) in different senarios of diffusion acceleration. (a) Under different prompt complexities, ERTACache adopts a uniform caching strategy, whereas OnlineCache dynamically adapts (e.g., 70.00% vs. 53.33% cache ratio), achieving improved generation quality under a comparable average speedup. (b) Under the same 66.67% caching ratio, ERTACache’s "one-policy-fits-all" strategy is suboptimal. In contrast, OnlineCache identifies critical timesteps and achieves a 37.48% reduction in L1 error, along with substantially improved perceptual quality.

Methods

OnlineCache reformulates the caching schedule as a Markov Decision Process (MDP) and introduces two lightweight Multi-Layer Perceptron (MLP) modules that plug into frozen, pre-trained diffusion backbones:

  • Policy Network ($\pi_\theta$): Evaluates the current state at each denoising step to make a binary decision—whether to cache (reuse the previous residual) or compute (run the full diffusion model block).
  • Error Corrector ($C_\phi$): If the policy chooses to cache, the corrector steps in to compensate for the approximation error and prevent trajectory drift.

Instead of feeding raw spatial tensors into the policy network (which is computationally prohibitive and resolution-dependent), OnlineCache extracts compact channel-wise statistical summaries (mean, standard deviation, and maximum absolute value) from the current latent state and the cached residual, alongside a time embedding.

Figure 2: Overall inference pipeline of OnlineCache, where the policy network dynamically determines caching decisions and the corrector compensates for cache-induced approximation errors.

The two modules are jointly trained using a Bilevel Optimization (BLO) framework:

  • Outer Loop (Policy): Optimized via policy gradient (REINFORCE) to maximize a global trajectory-level reward that balances visual quality (LPIPS and SSIM), a target cache ratio, and a stability penalty to prevent consecutive caching blowups.
  • Inner Loop (Corrector): Optimized via Mean Squared Error (MSE) to minimize local approximation errors specifically on steps where caching occurs.

To bypass the massive memory footprint (>400GB) of backpropagating through an entire diffusion trajectory, the authors implement a first-order approximation using Truncated Backpropagation Through Time (TBPTT) with a step-wise horizon ($k=1$).

Datasets

The authors evaluated OnlineCache across multiple models and modalities using the following datasets:

  • MSCOCO: Used for training and quantitative evaluation (800 samples) on the FLUX.1-dev model.
  • Parti-Prompts: Used to test cross-dataset generalization and acceleration ratio flexibility (1,632 samples).
  • ImageNet-256: Used to evaluate performance on the Diffusion Transformer (DiT-XL/2) architecture across 50k samples.
  • VBench Pipeline: Used to benchmark video generation quality on CogVideoX-2b.

Key Insights and Ideas

  • Latents Are Inherently Gaussian: The authors empirically validate that intermediate latent features across diffusion steps consistently exhibit stable, Gaussian-like distributions. This is theoretically driven by the KL-divergence constraints imposed during VAE pre-training. This insight justifies using simple channel-wise statistics ($\mu, \sigma$) as a highly effective, resolution-agnostic state representation for the policy network.
Figure 3: Statistical feature design for pol- icy input. We extract (µ(·), σ(·)) to char- acterize the latent distribution, motivated by the approximately Gaussian behavior of latent representations in diffusion models.
  • Caching Can Act as a Denoiser: Surprisingly, on DiT-XL/2, OnlineCache actually improved the Frechet Inception Distance (FID) compared to full-step inference. By selectively skipping redundant steps and applying error correction, the framework suppresses sampling noise inherent in imperfect ground-truth trajectories.
  • Bilevel Coupling is Essential: Training the policy conditional on the corrector's capacity ensures that the model only skips computation when it knows the corrector can successfully repair the induced error, leading to a superior Pareto frontier between efficiency and quality.

Key Results

  • FLUX.1-dev: OnlineCache achieved nearly a 3× speedup while preserving generation fidelity, consistently outperforming static baselines like ERTACache and heuristic methods like TeaCache.
  • DiT-XL/2: It delivered a 1.88× speedup under DPM++ sampling while unexpectedly improving the baseline FID from 3.47 to 3.28.
  • CogVideoX-2b: The framework extended seamlessly to video generation, achieving a 1.79× speedup without compromising video quality metrics.
  • Robust Generalization: The learned policy demonstrated strong zero-shot generalization across different resolutions (trained at 512×512, evaluated at 1024×1024) and even transferred successfully to closely aligned model architectures (from FLUX.1-dev to its distilled variant, FLUX.1-schnell).

Limitations and Future Work

  • Upfront Training Overhead: Unlike purely heuristic, training-free caching methods, OnlineCache requires a one-time training phase (e.g., ~26 hours on a single A100 GPU for FLUX.1-dev).
  • Suboptimal Local Equilibria: The first-order approximation and alternating coordinate-descent scheme used for bilevel optimization can theoretically converge to a suboptimal local equilibrium compared to an exact, fully unrolled trajectory solution.
  • Cross-Architecture Dependency: Because the policy network's input state vector relies on the specific channel dimensions ($D$) of a model's latent space, transferring a trained policy to a completely different backbone architecture (e.g., from a DiT to a traditional U-Net) requires retraining from scratch.

Summary updated

BibTeX
@misc{xie2026onlinecache,
  author = {Zhikang Xie and Xichen Ye and Yifan Wu and Haoshen Yu and Li chenan and Peizhu Gong and Weizhong Zhang and Cheng Jin},
  title = {{OnlineCache: Learning Dynamic Caching Policies with Error Correction for Efficient Diffusion Inference}},
  year = {2026},
  eprint = {2607.29398},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.29398},
}
Figure