Imagine you’re an artist painting a masterpiece. Instead of starting from scratch every time you want to add a detail, you might reuse a sketch or a stencil for the repetitive parts. In the world of AI, diffusion models—the engines behind tools like Midjourney or FLUX—do something similar, but they are notoriously "perfectionists." They insist on recalculating every single brushstroke, dozens of times, for every single image.
OnCache is a new framework that teaches these models how to take smart shortcuts. It learns exactly when it can "cheat" by reusing previous calculations and when it needs to buckle down and do the hard work, resulting in a 3x speedup without sacrificing the stunning quality we’ve come to expect.
TL;DR
Diffusion models are slow because they repetitively run massive neural networks. OnCache replaces rigid, "one-size-fits-all" schedules with a dynamic policy that decides—on the fly—when to reuse old data and when to refresh it based on the specific image being generated. By adding a tiny "corrector" network to fix minor errors, it achieves state-of-the-art speed and fidelity for both images and video.
What Problem Does This Paper Address?
Generating an image with a diffusion model is an iterative process called "denoising." You start with pure static and slowly refine it over 30 to 50 steps. Each step requires a full pass through a massive Transformer backbone (a "DiT").
Researchers have tried "caching"—reusing the internal features from step 5 in step 6 to save time. However, most existing methods use static schedules. They might say "refresh the cache every 3 steps," regardless of whether you're generating a simple blue sky or a complex crowd of people.
The authors of OnCache noticed two big flaws in this approach:
- Sample Heterogeneity: Some prompts are just harder than others. A simple beach scene can tolerate more "cheating" than a detailed bird (see Figure 2 below).
- Timestep Heterogeneity: Some moments in the generation process are more critical than others. Reusing a cache at the wrong time can lead to blurry textures or structural "ghosting."
Methods
OnCache introduces a two-part system that acts like a smart manager and a diligent assistant:
- The Policy (The Manager): This is a lightweight module that looks at the current state of the image and the prompt. It makes a binary choice: Compute (do the full work) or Cache (reuse the previous result). It’s trained using "paired continuations"—the researchers essentially let the model try both paths from the same point and measured which one gave the best "bang for the buck" in terms of quality versus speed.
- The Corrector (The Assistant): Even a smart shortcut introduces a little bit of error. The Corrector is a tiny neural network that "nudges" the cached features to make them look more like what a fresh calculation would have produced.
The beauty of this system is its efficiency. Both the policy and the corrector are so small that they add less than 1% to the total computation time, yet they allow the model to skip roughly two-thirds of the heavy lifting.
Datasets
The researchers put OnCache through its paces on several heavy-hitting models and benchmarks:
- FLUX.1-dev: A state-of-the-art image generation model.
- Wan2.1-T2V-1.3B: A cutting-edge video generation model.
- MS-COCO: Used 1,000 captions to test image quality.
- VBench: A comprehensive benchmark for video generation quality.
Key Insights and Ideas
- The "Zero-Cost" Refresh: One of the most counter-intuitive findings was that doing a full calculation now can actually save time later. By refreshing the cache at a critical moment, the model stays "on track," allowing it to reuse that fresh data for more steps down the line.
- Dynamic is Better than Static: By allowing the Number of Function Evaluations (NFE) to vary between images, OnCache produces better results than methods that force every image into the same 10-step budget.
- Error Compensation: The "Corrector" isn't just a gimmick; it reduces the relative output error by nearly 20%, which is often the difference between a crisp image and one that looks slightly "off."
Key Results
OnCache sets a new bar for efficient generation:
- 3x Speedup: On the FLUX model, it achieves nearly triple the speed at high resolutions ($1024^2$).
- Superior Fidelity: It consistently beats other popular acceleration methods (like TeaCache or ERTACache) across metrics like LPIPS (perceptual similarity) and SSIM (structural similarity).
- Video Mastery: When applied to video generation, it achieved a VBench score just 0.09% below the full-speed reference while running significantly faster.
Limitations and Future Work
While OnCache is a massive leap forward, the authors note a few areas for growth:
- Offline Training: The policy and corrector need to be trained "offline" for a few hours before they can be used. While this is a one-time cost, it means you can't just plug it into a brand-new model architecture instantly.
- Architecture Specifics: Currently, the system is optimized for Transformer-based models (DiTs). Adapting it to older U-Net architectures might require different "causal state" features.
In the grand scheme, OnCache proves that the path to faster AI isn't just about bigger GPUs—it's about teaching our models to be as clever as they are creative.
Summary updated