Torch Compile Model Advanced
Torch.compile for ComfyUI with a real off switch
- model
- MODEL
torch.compile traces your model's forward pass and hands it to a compiler backend that fuses and optimizes the underlying kernels - the payoff is faster sampling steps, the cost is a slow first call while it actually compiles. ComfyUI ships a basic compile node already; this one extends it with a choice of compile mode and, more usefully, a toggle so you can leave the node in your graph and switch compilation on or off without deleting and rewiring it every time you want to compare.
The knobs that matter
backend-inductororcudagraphs. Inductor is PyTorch's general-purpose compiler backend and the safer default.cudagraphscaptures and replays a CUDA graph instead - lighter warm-up in some cases, but more fragile about what kinds of models and control flow it can actually handle.compile_mode-default,reduce-overhead, ormax-autotune.defaultis the balanced choice.reduce-overheadtargets cases where kernel-launch overhead dominates (smaller/faster models running many quick steps).max-autotunespends real compile time searching for the fastest kernel variants - worth it for a long batch job, wasted effort for a single one-off generation, since the extra search time has to be paid back by enough runs to amortize it.enabled- defaults tofalse. Compile is opt-in here, and flipping it is the whole reason this node has an "advanced" edition of the stock one: leave the node wired in, toggle it per-run instead of rebuilding your graph.
Input: model (MODEL). Output: MODEL, compiled or not depending on enabled, wired onward exactly like the uncompiled model would be.
What actually happens when you flip it on
The first inference call after enabling compile is always slower than normal - that's the compile step itself happening, not a bug. After that, subsequent calls at the same shapes and settings should be faster. How much faster is genuinely inconsistent across setups: people report solid, real speedups combining torch.compile with other optimizations on Flux workloads, but also report cases - particularly Windows plus certain GPU/driver combinations - where compile adds overhead without a matching payoff, and get better results sticking to Linux. If you enable it and don't see a difference, that's a real, reported outcome, not just user error - worth benchmarking your own setup rather than assuming the win is universal.
Installing it
ComfyUI Manager: search "ComfyUI-utils-nodes." Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes
Restart ComfyUI. torch.compile itself ships with PyTorch - no separate install - but inductor in particular benefits heavily from having Triton available, which matters more on Windows than Linux.
Where people get burned
The big one: changing resolution mid-session, or swapping to a differently-shaped input, can force an expensive recompile - you'll eat that slow "first call" cost again without expecting it. Lock in your generation settings before you turn this on, not after. The community's other long-standing gripe was recompiles triggered every time you swapped a LoRA on a compiled model, which used to require extra patch-order workarounds to avoid - that friction has genuinely eased in recent PyTorch/ComfyUI versions, but if you're on an older stack and see a recompile every time you touch a LoRA, that's a known, historical rough edge, not something specific to this node.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| backend | COMBO | 2 options: inductor, cudagraphs | |
| compile_mode | COMBO | 3 options: reduce-overhead, default, max-autotune | |
| enabled | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |