OnCache: Learning Dynamic Caching Schedules for Efficient Diffusion Inference
Authors: Zhikang Xie, Xichen Ye, Yifan Wu, Yuxuan Liu, Qianlong Wang, Haoshen Yu, Peizhu Gong, Weizhong Zhang, Cheng Jin
Organizations: College of Computer Science and Artificial Intelligence, Fudan University · School of Data Science, Fudan University · Shanghai Key Laboratory of Intelligent Information Processing
Diffusion models have revolutionized generative tasks but incur high inference latency due to iterative denoising. Cache-based strategies accelerate inference by reusing intermediate features, yet they largely rely on static, sample-agnostic schedules. Our empirical analysis reveals two factors that these schedules overlook. (i) denoising dynamics and computational requirements vary across prompts, motivating adaptive computation allocation. (ii) sensitivity to caching errors varies across timesteps, so static schedules may reuse features at error-sensitive steps or waste computation at less sensitive ones. We therefore propose OnCache, a dynamic caching framework that makes prompt-adaptive decisions online about how much computation to allocate and when to refresh cached features. A policy is trained offline on paired compute and cache continuations from identical denoising states, using differences in terminal fidelity and the number of function evaluations (NFE) to account for the downstream consequences of each decision. To further improve the generation quality, a neural corrector compensates for caching-induced errors and mitigates their accumulation throughout the denoising trajectory. Both components are lightweight and introduce negligible additional inference latency. On FLUX.1-dev, OnCache achieves a nearly 3× generation speedup at 10242 resolution, with LPIPS of 0.156 and SSIM of 0.860. We further extend OnCache to video generation on Wan2.1-T2V-1.3B, achieving state-of-the-art efficiency--quality trade-offs across both modalities.
Figures & tables
Figure 2: A computation budget can be reallocated across samples and timesteps. (a) Moving one full evaluation between two samples improves both outputs at unchanged aggregate computation. (b) Changing refresh locations improves final-image fidelity for the same prompt (with the same total NFE). Lower LPIPS indicates closer agreement with the full reference.
Figure 3: OnCache inference framework. (a) Conditioned generation repeatedly applies an OnCache denoising step, producing intermediate latents. (b) The policy πθ,b observes the causal state zi and selects full computation ( ai=1 ) or cache reuse ( ai=0 ). Full computation refreshes the residual cache with Ri=Bi(hi,c)−hi ; cache reuse forms hˉi=hi+Rj , where j is the most recent refresh index. The corrector adjusts reused features before the output head; δi denotes the resulting adjustment to the denoiser output.
Method
Efficiency
Performance
Mean NFE
Gen. (s) ↓
Speedup ↑
LPIPS ↓
SSIM ↑
PSNR ↑
ImageReward ↑
Full30
30.000 / 30.000
6.064 / 19.455
1.00 × / 1.00 ×
– / –
– / –
– / –
0.965 / 1.040
TeaCache
10.033 / 10.040
2.118 / 6.701
2.86 × / 2.90 ×
0.349 / 0.397
0.663 / 0.685
17.48 / 17.00
0.929 / 0.961
TaylorSeer
10.000 / 10.000
2.370 / 7.269
2.56 × / 2.68 ×
0.219 / 0.232
0.753 / 0.776
20.21 / 20.34
0.937 / 0.985
ERTACache
10.000 / 10.000
2.097 / 6.659
2.89 × / 2.92 ×
0.214 / 0.266
0.768 / 0.771
21.21 / 20.82
0.956 / 1.000
SeaCache
10.003 / 9.982
2.127 / 6.689
2.85 × / 2.91 ×
0.179 / 0.217
0.805 / 0.810
22.64 / 22.17
0.951 / 0.991
Table 1: FLUX.1-dev on 1,000 COCO captions at 30 sampling steps. Each cell reports 5122 / 10242 resolution results. OnCache (w/o) disables the corrector; OnCache (w) is the full method. Bold/underlined scores mark the best/second-best results at each resolution.
Method
Efficiency
Performance
Mean NFE
Gen. (s) ↓
Speedup ↑
VBench ↑
LPIPS ↓
SSIM ↑
PSNR ↑
Full50
50.000
337.575
1.00 ×
81.44%
–
–
–
TeaCache
23.741
173.428
1.95 ×
76.04%
0.291
0.569
16.17
ERTACache
24.000
174.017
1.94 ×
80.73%
0.110
0.820
23.77
TaylorSeer
20.000
151.119
2.23 ×
80.55%
0.280
0.606
16.68
SeaCache
20.007
148.565
2.27 ×
81.04%
0.138
0.784
22.26
Table 2: Wan2.1-T2V-1.3B with 50 steps, 832×480 resolution, 81 frames, and five seeds. Quality scores for TeaCache and ERTACache are taken from the ERTACache paper [ 24 ] . We remeasured their runtimes in our environment using 15 prompts. The 95% bootstrap confidence intervals are 173.26–173.60 s and 173.77–174.25 s, respectively.
Figure 5: Qualitative comparison of image and video. Upper: six FLUX.1-dev images from COCO. Lower: four evenly spaced frames from two Wan2.1-T2V-1.3B videos. Gold boxes and insets mark shared regions. Appendix H gives further image comparisons.
Model
Config
Params
Size (MB)
Time (s)
FLUX
DP Init
–
–
2.091
+ Policy
51.7K
0.418
2.098 ( +0.33% )
+ Corrector
1.00M
4.003
2.113 ( +0.71% )
Wan
DP Init
–
–
147.137
+ Policy
4.36K
0.045
148.326 ( +0.81% )
+ Corrector
0.606M
2.424
148.365 ( +0.03% )
Table 3: Module size and generation time on FLUX and Wan.
Method
Target
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
w/o
8
8.000
0.2271
0.7541
21.839
w
8
8.000
0.2009
0.7861
22.512
w/o
10
10.000
0.1449
0.8364
24.770
w
10
10.085
0.1252
0.8602
25.447
w/o
12
12.045
0.1066
0.8808
26.303
w
12
12.030
0.0950
0.8935
26.747
Table 4: Frozen modules across budgets on 200 test captions. w/o and w denote OnCache without and with the corrector.
Figure 6: Error propagation on FLUX. Cumulative hidden-residual error (top) and latent deviation (bottom) from Full30, averaged over five prompts and five seeds at 5122 and 10 NFE.
Figure 7: Corrector component ablations. Fidelity on 200 captions under the same 10/30 schedule. Points and whiskers show the mean and sample standard deviation across three seed means.
Appendix figures & tables16 assets
Supplementary material from the paper’s appendix.
Appendix
Component
FLUX
Wan
GPU
NVIDIA H20
Python
3.11.18
CUDA
13.0
PyTorch
2.14.1+cu130
Diffusers
0.41.0
0.33.1
Transformers
5.20.2
4.49.0
Appendix
Table 5: Hardware / software for the main generation experiments.
Method
FLUX: 5122 , 30 steps
Wan: 50 steps
DP Init
Static schedule, 10 NFE
Static schedule, 20 NFE
OnCache (w/o)
b=−0.559 ; no corrector
b=3.93 ; no corrector
OnCache (w)
Same policy, with corrector
Same policy, with corrector
TeaCache
Adaptive gate; 10.033 NFE
Adaptive gate; 23.741 NFE
SeaCache
Spectral gate; 10.003 NFE
Spectral gate; 20.007 NFE
DiCache
One-block probe; 10.006 NFE
One-block probe; 23.718 NFE
Appendix
Table 6: Baseline settings for FLUX.1-dev and Wan2.1-T2V-1.3B. Shown NFE values are means from Tables 1 and 2 . OnCache (w/o) and (w) share the policy without and with the corrector; – denotes a method not compared.
Assignment
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
Our Policy
9.865
0.1482
0.8319
24.70
All-prompt permutation
9.865
0.1676
0.8124
23.72
Within-NFE permutation
9.865
0.1593
0.8203
23.84
Appendix
Table 7: Final-policy schedule assignment on 200 5122 captions at matched total computation. Bold marks the best scores.
Dataset
Pairs
d=−1
d=0
d=1
d=2
Mean d
Teacher set (64)
448
1
201
242
4
0.556
Diagnostic set (16)
112
0
38
68
6
0.714
Appendix
Table 8: Measured compute-minus-cache continuation NFE differences ( di ), accounting for the current and all subsequent actions.
Learner
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
Paired learner (Ours)
10.020
0.1425
0.8285
24.635
Unit cost target
9.995
0.1491
0.8219
24.281
Time inputs only
10.000
0.1452
0.8255
24.573
History/drift removed
10.000
0.1452
0.8255
24.573
Appendix
Table 9: Controlled target and input ablations fitted on the 64-caption teacher-trajectory set and evaluated on 200 5122 test captions without the corrector. Bold marks the best scores.
Test
Fit
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
2562
2562
9.594
0.1453
0.8032
22.652
5122
9.578
0.1486
0.8005
22.406
Mix
9.594
0.1466
0.8019
22.727
5122
2562
10.172
0.1592
0.8297
24.712
5122
10.203
0.1517
0.8354
24.804
Mix
10.156
0.1520
0.8348
24.849
Appendix
Table 10: Cross-resolution generalization of the policy after four training rounds on 64 captions. Bold marks the best fidelity.
Method
NFE
Latency (s) ↓
LPIPS ↓
SSIM ↑
PSNR ↑
Full30
30
4.8956
–
–
–
BudCache
10
1.8980
0.1452
0.8255
24.57
+ ERTACache
10
1.9878
0.1371
0.8303
24.63
+ TaylorSeer (order 1)
10
2.0905
0.1303
0.8281
23.88
+ TaylorSeer (order 2)
10
2.1597
0.1805
0.7871
22.47
+ Our corrector
10
1.9392
0.1286
0.8480
25.20
Appendix
Table 11: Frozen compensation under a shared 10-NFE schedule on 200 prompts at 5122 . Latency on one A100 GPU includes VAE decoding. Bold marks the best fidelity scores.
Objective
LPIPS ↓
SSIM ↑
PSNR (dB) ↑
Hidden
0.1399±0.0001
0.8267±0.0001
24.758±0.008
Velocity
0.1365±0.0053
0.8310±0.0034
24.889±0.147
Joint (Ours)
0.1358±0.0003
0.8352±0.0002
24.904±0.010
Appendix
Table 12: Loss objectives at 1,280 updates and NFE 10. Entries are means ± sample standard deviations across three fixed training seeds on the 200 test captions. Bold marks the best mean.
Method
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
BudCache
10.000
0.1452
0.8255
24.573
+ corrector
10.000
0.1286
0.8480
25.198
DiCache
10.005
0.1904
0.7963
22.712
+ corrector
10.000
0.1859
0.8074
23.242
Appendix
Table 13: Frozen corrector transfer on the 200 captions. NFE counts full evaluations and excludes DiCache’s one-block probes.
Figure 8: Plug-and-play corrector gains. Paired markers show mean fidelity before and after adding the same frozen corrector.
Stage
FLUX
Wan
Policy data collection
56.36
61.35
Policy fitting and optimization
53.45
95.28
Policy total
109.81
156.63
Corrector teacher trajectory collection
37.71
54.11
Corrector fitting
76.83
96.18
Corrector total
114.54
150.29
Appendix
Table 14: Offline collection and optimization time (minutes) on a single NVIDIA A100 GPU. Totals sum recorded stage durations.
Method
NFE
LPIPS ↓
SSIM ↑
PSNR ↑
Time (s) ↓
Speedup ↑
Full50
50.000
–
–
–
8.115
1.00 ×
ReCache + T1
13.000
0.1293
0.8478
23.882
2.742
2.96 ×
ReCache + T2
13.000
0.1364
0.8442
23.494
2.958
2.74 ×
OnCache (w/o)
13.238
0.1362
0.8426
23.561
2.394
3.39 ×
OnCache (w)
13.050
0.1272
0.8495
24.026
2.437
3.33 ×
Appendix
Table 15: 50-step comparison on 80 5122 captions. Time includes VAE decoding. Bold marks the best score in fidelity column.
Configuration
Device
Hours
ReCache + T1 (reported)
H100
22
ReCache + T2 (reported)
H100
23
OnCache (w/o)
A100
≈2.28
OnCache (w)
A100
≈2.81
Appendix
Table 16: Offline training cost for the 50-step comparison. ReCache reports H100 GPU hours; OnCache reports A100 GPU hours.
Figure S1 : Selected comparisons at 10242 resolution. The OnCache column (without corrector) has lower LPIPS than ERTACache and SeaCache on all twelve prompts. Values give full-image LPIPS to Full30 ( ↓ ), with actual NFE in parentheses.
Figure S2 : Comparisons at 5122 resolution. The OnCache column (without corrector) has lower LPIPS than TaylorSeer and BudCache on all twelve prompts at an NFE of ten per accelerated output. Values give full-image LPIPS to Full30 ( ↓ ), with actual NFE in parentheses.
Figure S3 : Selected Wan2.1-T2V-1.3B video comparisons. Each example shows four evenly spaced frames from paired videos (seed 0, 832×480 , 81 frames, 50 sampling steps). Values report actual NFE and mean LPIPS over all decoded frames against Full50. Gold boxes and insets mark matching regions; the train and butterfly show additional frames from the videos in the lower panel of Fig. 5 .
Diffusion model caching reuses features, activations, or attention states across denoising steps to reduce inference cost while preserving output quality.
Diffusion models have revolutionized generative tasks but incur high latency due to iterative denoising. While cache-based strategies accelerate inference by reusing intermediate features, they largely rely on static, sample-agnostic schedules. We argue that this rigidity overlooks two facts empirically validated in this paper: (i) generation difficulty varies across prompts, requiring adaptive resource allocation--complex inputs demand more computation while simpler ones require less; (ii) error sensitivity fluctuates across timesteps, where static policies may cache high-error steps or waste computation on low-error ones. We therefore propose OnlineCache, a dynamic caching framework that jointly learns when to cache and how to correct approximation errors. We leverage policy gradient to train a lightweight network for adaptive speed-quality trade-offs, and incorporate a learnable corrector to mitigate caching-induced errors. Both modules are jointly optimized under a bilevel optimization framework, with the policy targeting global generation quality and the corrector minimizing local errors. Our method automatically allocates computational resources across both samples and timesteps, improving overall generation quality. Extensive experiments demonstrate clear superiority. On FLUX.1-dev model, OnlineCache achieves nearly 3 speedup while preserving generation fidelity. On DiT and CogVideoX, it similarly delivers competitive acceleration without compromising quality; across all scenarios, it consistently outperforms existing cache-based acceleration baselines.
Zhikang Xie, Xichen Ye, Yifan Wu +5
College of Computer Science and Artificial Intelligence, Fudan University · School of Data Science, Fudan University · 3Shanghai Key Laboratory of Intelligent Information Processing
Modern diffusion models generate high-quality images and videos, but their iterative denoising process makes inference expensive. Feature caching accelerates sampling by reusing or predicting intermediate activations across neighboring denoising steps, exploiting the redundancy of computations along the reverse trajectory. In this work, we focus on the caching schedule: selecting which denoising steps should be fully recomputed. Existing schedules are either fixed (e.g. uniform) or chosen adaptively from per-step error heuristics; in both cases, the actual compute cost is a side-effect of hand-tuned thresholds rather than a quantity the user can specify. We propose ReCache, which inverts this: given a target budget k, it learns the recomputation schedule that maximizes generation quality, turning compute into a directly controllable input. ReCache trains via policy gradients, sidestepping backpropagation through full diffusion inference, and uses no labelled data. Generations from uncached inference serve as matching targets, paired with a reward for generation quality. ReCache is compatible with any caching mechanism, including feature reuse and feature forecasting; for each mechanism, a single trained policy adapts across computational budgets at inference time. ReCache consistently outperforms scheduling baselines: under a ×5.04 FLOPs reduction on FLUX, it reduces LPIPS by 31% (from 0.456 to 0.316) compared to DiCache; on Wan 2.1 at a ∼×2.6 speedup, it drops LPIPS by 65% (from 0.480 to 0.169) and boosts the VBench score by 7% (5.6 points, from 70.4 to 76.0) over uniform HiCache. Code is available at https://github.com/thecrazymage/ReCache.
Mishan Aliev, Eva Neudachina, Ilya Bykov +4
1HSE University, Russia · 2Yandex Research, Russia
Diffusion models achieve state-of-the-art video generation quality, but their inference remains expensive due to the large number of sequential denoising steps. This has motivated a growing line of research on accelerating diffusion inference. Among training-free acceleration methods, caching reduces computation by reusing previously computed model outputs across timesteps. Existing caching methods rely on heuristic criteria to choose cache/reuse timesteps and require extensive tuning. We address this limitation with a principled sensitivity-aware caching framework. Specifically, we formalize the caching error through an analysis of the model output sensitivity to perturbations in the denoising inputs, i.e., the noisy latent and the timestep, and show that this sensitivity is a key predictor of caching error. Based on this analysis, we propose Sensitivity-Aware Caching (SenCache), a dynamic caching policy that adaptively selects caching timesteps on a per-sample basis. Our framework provides a theoretical basis for adaptive caching, explains why prior empirical heuristics can be partially effective, and extends them to a dynamic, sample-specific approach. Experiments on Wan 2.1, CogVideoX, and LTX-Video show that SenCache achieves better visual quality than existing caching methods under similar computational budgets.