LayerCache: Exploiting Layer-wise Velocity Heterogeneity for Efficient Flow Matching Inference
Organizations: iFLYTEK
Abstract
Flow Matching models achieve state-of-the-art image generation quality but incur substantial inference cost due to iterative denoising through large Transformer networks. We observe that different layer groups within a Transformer exhibit markedly heterogeneous velocity dynamics: shallow layers are highly stable and amenable to aggressive caching, while deep layers undergo large velocity changes that demand full computation. Existing caching methods, however, treat the entire Transformer as a monolithic unit, applying a single caching decision per timestep and thus failing to exploit this heterogeneity. Based on this finding, we propose LayerCache, a layer-aware caching framework that partitions the Transformer into layer groups and makes independent, per-group caching decisions at each denoising step. LayerCache introduces an adaptive JVP span K selection mechanism that leverages per-group stability measurements to balance estimation accuracy and computational savings. We formulate a three-dimensional scheduling problem over timesteps, layer groups, and JVP span, and solve it with a greedy budget allocation algorithm. On Qwen-Image (1024x1024, 50 steps), LayerCache achieves PSNR 37.46 dB (+5.38 dB over MeanCache), SSIM 0.9834, and LPIPS 0.0178 (a 70% reduction over MeanCache) at 1.37x speedup, dominating all prior caching methods on the quality-speed Pareto frontier.
Figures & tables
| Method | Config | Speedup | PSNR | SSIM | LPIPS |
|---|---|---|---|---|---|
| Baseline (no cache) | 50 steps | 1.00 | — | — | — |
| TeaCache [ 13 ] | 0.97 | 16.41 | 0.6670 | 0.5514 | |
| DiCache [ 2 ] | 0.82 | 40.05 | 0.9884 | 0.0102 | |
| TaylorSeer [ 14 ] | interval=3 | 1.47 | 23.09 | 0.8821 | 0.1297 |
| FirstBlockCache [ 3 ] | 1.37 | 32.66 | 0.9475 | 0.0461 | |
| MeanCache [ 5 ] | 1.54 | 32.08 | 0.9559 | 0.0591 |
| Budget | Method | PSNR | SSIM | LPIPS |
|---|---|---|---|---|
| MeanCache | 28.92 | 0.9018 | 0.1245 | |
| LayerCache | 31.05 | 0.9268 | 0.0856 | |
| MeanCache | 31.24 | 0.9312 | 0.0845 | |
| LayerCache | 33.18 | 0.9478 | 0.0612 | |
| MeanCache | 32.85 | 0.9436 | 0.0673 | |
| LayerCache | 34.16 | 0.9550 | 0.0522 |
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
| TeaCache | DiCache | MeanCache | LayerCache | (LC MC) | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Category | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS | PSNR | SSIM | LPIPS |
| Portrait | 29.72 | 0.9015 | 0.1095 | 29.18 | 0.8912 | 0.1248 | 32.80 | 0.9429 | 0.0666 | 34.12 | 0.9546 | 0.0518 | +1.32 | +.0117 | .0148 |
| Landscape | 30.28 | 0.9102 | 0.0985 | 29.75 | 0.9008 | 0.1135 | 33.21 | 0.9478 | 0.0641 | 34.49 | 0.9581 | 0.0497 | +1.28 | +.0103 | .0144 |
| Animal | 29.95 | 0.9045 | 0.1065 | 29.42 | 0.8955 | 0.1205 | 32.92 | 0.9442 | 0.0668 | 34.22 | 0.9555 | 0.0520 | +1.30 | +.0113 | .0148 |
| Architecture | 29.48 | 0.8965 | 0.1142 | 28.95 | 0.8875 | 0.1298 | 32.54 | 0.9401 | 0.0712 | 33.87 | 0.9523 | 0.0551 | +1.33 | +.0122 | .0161 |
| Food | 30.15 | 0.9068 | 0.1028 | 29.62 | 0.8978 | 0.1168 | 33.05 | 0.9458 | 0.0652 | 34.35 | 0.9565 | 0.0508 | +1.30 | +.0107 | .0144 |
| Parameter | Value |
|---|---|
| Number of denoising steps | 50 |
| Number of layer groups | 3 |
| Layers per group | 20 |
| Compute budget | 25 |
| Greedy exponent | 4.0 |
| Maximum JVP span | 6 |
Flow Matching
Flow matching learns continuous-time vector fields that transport simple noise distributions into data for efficient generative modeling.
See all 656 papers