TorchCompileModelAdvanced
In terms of technical implementation, this node allows users to select different compilation backends (such as inductor) and optimization modes (such as max-autotune).
Torch Compile Model Advanced
The TorchCompileModelAdvanced node, in its technical implementation, allows users to select different compilation backends (such as inductor) and optimization modes (such as max-autotune).
TorchCompileModelAdvanced is a ComfyUI node designed to optimize the inference performance of diffusion models. It leverages PyTorch's torch.compile functionality to compile key parts of the model into a more efficient format, thereby accelerating image generation. This node offers more granular control options compared to the basic compilation node.
Node Functionality
In its technical implementation, this node allows users to select different compilation backends (e.g., inductor) and optimization modes (e.g., max-autotune). It controls the compilation cache size by setting torch._dynamo.config.cache_size_limit and offers the option to compile only the Transformer blocks of the model, balancing compilation speed with optimization effectiveness.
Node Parameter Description - TorchCompileModelAdvanced
Connection Inputs (Inputs)
| Parameter Name | Data Type | Required | Default Value | Value Range/Options | Description |
|---|---|---|---|---|---|
model | MODEL | Yes | - | - | Receives the diffusion model to be optimized as the input object for compilation processing. |
Control Parameters (Parameters)
| Parameter Name | Data Type | Required | Default Value | Value Range/Options | Description |
|---|---|---|---|---|---|
backend | COMBO | Yes | inductor | "inductor", "cudagraphs" | Selects the backend engine used for PyTorch compilation. Options are inductor or cudagraphs. |
mode | COMBO | Yes | default | "default", "max-autotune", "max-autotune-no-cudagraphs", "reduce-overhead" | Optimization mode. |
dynamic | COMBO | Yes | false | "auto", "true", "false" | Enables dynamic shape tracing (true, false, or auto). |
fullgraph | BOOLEAN | Yes | False | - | Enable full graph mode |
compile_transformer_blocks_only | BOOLEAN | Yes | True | - | Compile only transformer blocks, faster compile and less error prone |
dynamo_cache_size_limit | INT | Yes | 64 | 0 - 1024 (Step: 1) | torch._dynamo.config.cache_size_limit |
debug_compile_keys | BOOLEAN | Yes | False | - | Print the compile keys used for torch.compile |
disable_dynamic_vram | BOOLEAN | No | False | - | Disable dynamic VRAM management to reduce memory fragmentation. |
Output
| Parameter Name | Data Type | Description |
|---|---|---|
| MODEL | MODEL | Outputs the compiled and optimized model for subsequent image generation steps. |
Usage Scenarios
In practical applications, when a user builds a workflow prioritizing generation speed, this node can be connected after the loaded model. By adjusting parameters such as compilation mode and dynamic shape tracing, users can experiment to achieve the best inference performance on different hardware (e.g., NVIDIA GPUs) without modifying the model itself.
Notes
This node is marked as an experimental feature, and its behavior may change with PyTorch version updates. Inappropriate parameter combinations may lead to compilation failures or runtime errors. Thorough testing is recommended before using it in critical workflows.
TorchCompileModelAdvanced Node Source Code Link
The TorchCompileModelAdvanced node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.