Unofficial implementation of ali-vilab/TeaCache for ComfyUI
Timestep Embedding Aware Cache (TeaCache) is a training-free caching approach that estimates and leverages the fluctuating differences among model outputs across timesteps, thereby accelerating the inference. TeaCache works well for Image Diffusion models, Video Diffusion Models, and Audio Diffusion Models.
TeaCache has now been integrated into ComfyUI and is compatible with the ComfyUI native nodes. ComfyUI-TeaCache is easy to use, simply connect the TeaCache node with the ComfyUI native nodes for seamless usage.
Installation via ComfyUI-Manager is preferred. Simply search for ComfyUI-TeaCache in the list of nodes and click install.
ComfyUI/custom_nodes/
To use TeaCache node, simply add TeaCache For Img Gen
or TeaCache For Vid Gen
node to your workflow after Load Diffusion Model
node or Load LoRA
node (if you need LoRA). Generally, TeaCache can achieve a speedup of 1.5x to 3x with acceptable visual quality loss. The following table gives the recommended rel_l1_thresh for different models:
| | FLUX | PuLID-FLUX | HunyuanVideo | LTX-Video | CogVideoX | |:---------------:|:-----------------:|:------------------:|:------------------:|:---------------:|:---------------:| | rel_l1_thresh | 0.4 | 0.4 | 0.15 | 0.06 | 0.3 | | speedup | ~2x | ~1.7x | ~2x | ~1.7x | ~2x |
The demo workflows (teacache_flux, teacache_pulid_flux, teacache_hunyuanvideo, teacache_ltx_video, teacache_cogvideox) are placed in examples folder.
To use Compile Model node, simply add Compile Model
node to your workflow after Load Diffusion Model
node or TeaCache
node. Compile Model uses torch.compile
to enhance the model performance by compiling model into more efficient intermediate representations (IRs). This compilation process leverages backend compilers to generate optimized code, which can significantly speed up inference. The compilation may take long time when you run the workflow at first, but once it is compiled, inference is extremely fast. The usage is shown below:
https://github.com/user-attachments/assets/b3aca64d-c2ae-440c-a362-f3a7b6c633e0
https://github.com/user-attachments/assets/8fce9b48-2243-46f1-b411-80e4a53f6f7d
https://github.com/user-attachments/assets/de8f5400-e885-446d-936f-c026a78ba5c2
Thanks to TeaCache repo owner ali-vilab/TeaCache: Timestep Embedding Tells: It's Time to Cache for Video Diffusion Model