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

Xinyin Ma, Gongfan Fang, M. B. Mi, Xinchao Wang

arXiv:2406.01733 · 2026-07-27 공개 · arXiv · PDF

diffusion-transformer fid-metric inference-speed differentiable-optimization cache-based-sampling u-vit-h-2 layer-caching l2c

Abstract

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

한국어 요약

한 줄 요약

L2C는 U-ViT-H/2에서 93.68%의 계층을 캐시하여 FID 0.01 미만의 손실로 추론 속도를 대폭 향상시킨다.

핵심 기여도

핵심 아이디어

기존의 디퓨전 트랜스포머는 추론 시 모든 계층을 매 스텝마다 실행해야 하므로 느리다. L2C는 트랜스포머의 계층 구조가 동일하다는 점을 활용하여, **시간 단계 간 계층의 중복 계산**을 캐시를 통해 제거한다. 이는 **캐시 가능한 계층을 동적으로 선택**하는 문제로 정의되며, 이 문제는 **지수적으로 증가하는 검색 공간**을 가지는 도전적인 최적화 문제이다. 이를 해결하기 위해, **입력 불변(input-invariant)이지만 시간 단계에 따라 변하는 라우터(router)**를 도입하고, 이 라우터를 **미분 가능한 최적화 목적 함수**를 통해 학습한다.

이러한 접근은 기존의 계층 제거(layer dropping)와는 달리 **모델 파라미터를 재학습하지 않아도 되는 장점**이 있다. 또한, **두 연속 단계 간 예측을 보간**하여 빠른 구성(모든 계층 캐시)과 느린 구성(모든 계층 실행) 사이의 최적 경로를 탐색한다.

기술적 접근법

주요 결과

의의 및 한계

L2C는 트랜스포머 기반 디퓨전 모델의 추론 효율성을 극대화하는 새로운 패러다임을 제시한다. 기존의 계층 제거 방식과 달리 **모델 재학습 없이도 성능 저하 없이 추론 속도를 향상**시킬 수 있다는 점에서 실용적 가치가 높다. 또한, **미분 가능한 최적화를 통해 캐시 결정을 자동화**함으로써 수작업 기반의 휴리스틱 접근을 대체한다.

그러나, **모델 아키텍처에 따라 캐시 가능성 차이가 크므로**, 모든 디퓨전 트랜스포머에 동일하게 적용할 수는 없다. 또한, **캐시 결정이 시간 단계에 따라 달라지므로**, 정적 계산 그래프 생성이 필요한 상황에서는 추가 최적화가 필요할 수 있다.

실용적 활용

L2C는 이미지 생성, 비디오 생성, 3D 생성 등 다양한 생성 모델에서 **빠른 추론이 요구되는 산업 현장**에 적용 가능하다. 특히, **대규모 트랜스포머 기반 디퓨전 모델을 사용하는 클라우드 서비스나 모바일 애플리케이션**에서 유용하게 활용될 수 있다.