KJNodes/torchcompilegenerated

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

model
MODEL
backend
inductor
fullgraph
mode
default
dynamic
false
compile_transformer_blocks_only
dynamo_cache_size_limit
64
debug_compile_keys
disable_dynamic_vram
KJNodes

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 NameData TypeRequiredDefault ValueValue Range/OptionsDescription
modelMODELYes--Receives the diffusion model to be optimized as the input object for compilation processing.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
backendCOMBOYesinductor"inductor", "cudagraphs"Selects the backend engine used for PyTorch compilation. Options are inductor or cudagraphs.
modeCOMBOYesdefault"default", "max-autotune", "max-autotune-no-cudagraphs", "reduce-overhead"Optimization mode.
dynamicCOMBOYesfalse"auto", "true", "false"Enables dynamic shape tracing (true, false, or auto).
fullgraphBOOLEANYesFalse-Enable full graph mode
compile_transformer_blocks_onlyBOOLEANYesTrue-Compile only transformer blocks, faster compile and less error prone
dynamo_cache_size_limitINTYes640 - 1024 (Step: 1)torch._dynamo.config.cache_size_limit
debug_compile_keysBOOLEANYesFalse-Print the compile keys used for torch.compile
disable_dynamic_vramBOOLEANNoFalse-Disable dynamic VRAM management to reduce memory fragmentation.

Output

Parameter NameData TypeDescription
MODELMODELOutputs 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.

The TorchCompileModelAdvanced node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…