arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.01733cs.LGcs.CV
收藏

Learning-to-Cache:通过层缓存加速Diffusion Transformer

Learning-to-Cache: Accelerating Diffusion Transformer via Layer Caching

National University of Singapore(新加坡国立大学);Huawei Technologies Ltd(华为技术有限公司)

Xinyin Ma, Gongfan Fang, Michael Bi Mi, Xinchao Wang

AI总结:

针对Diffusion Transformer推理慢的问题,提出Learning-to-Cache (L2C)方案,通过动态层缓存移除冗余计算,在保持生成质量的同时大幅加速推理。

摘要:

Diffusion Transformers最近在各种任务中展示了前所未有的生成能力。然而,这一令人鼓舞的结果伴随着推理缓慢的代价,因为每个去噪步骤都需要在具有大规模参数的transformer模型上进行推理。在本研究中,我们做出了一个有趣且有些令人惊讶的观察:通过引入缓存机制,扩散transformer中很大比例层的计算可以被轻易移除,甚至无需更新模型参数。例如,在U-ViT-H/2的情况下,我们可以在缓存步骤中移除高达93.68%的计算量(所有步骤中为46.84%),而FID的下降不到0.01。为了实现这一点,我们引入了一种名为Learning-to-Cache (L2C)的新方案,该方案学习为扩散transformer以动态方式进行缓存。具体而言,通过利用transformer中层的相同结构以及扩散的顺序特性,我们将每层视为缓存的基本单元,探索时间步之间的冗余计算。为了解决深度模型中识别需要缓存和移除的层所面临的指数级搜索空间挑战,我们提出了一种新颖的可微优化目标。随后优化一个输入不变但随时间步变化的路由器,最终可以生成一个静态计算图。实验结果表明,在相同的推理速度下,L2C在很大程度上优于DDIM和DPM-Solver等采样器,以及先前基于缓存的方法。代码可在https://github.com/horseee/learning-to-cache获取。

英文摘要:

Diffusion Transformers have recently demonstrated unprecedented generative capabilities for various tasks. The encouraging results, however, come with the cost of slow inference, since each denoising step requires inference on a transformer model with a large scale of parameters. In this study, we make an interesting and somehow surprising observation: the computation of a large proportion of layers in the diffusion transformer, through introducing a caching mechanism, can be readily removed even without updating the model parameters. In the case of U-ViT-H/2, for example, we may remove up to 93.68% of the computation in the cache steps (46.84% for all steps), with less than 0.01 drop in FID. To achieve this, we introduce a novel scheme, named Learning-to-Cache (L2C), that learns to conduct caching in a dynamic manner for diffusion transformers. Specifically, by leveraging the identical structure of layers in transformers and the sequential nature of diffusion, we explore redundant computations between timesteps by treating each layer as the fundamental unit for caching. To address the challenge of the exponential search space in deep models for identifying layers to cache and remove, we propose a novel differentiable optimization objective. An input-invariant yet timestep-variant router is then optimized, which can finally produce a static computation graph. Experimental results show that L2C largely outperforms samplers such as DDIM and DPM-Solver, alongside prior cache-based methods at the same inference speed. Code is available at https://github.com/horseee/learning-to-cache

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑