HSWQ Torch Compile
Torch.compile for HSWQ models, with defaults that don't explode on tiled upscales
- model
- MODEL
torch.compile is free speed on the right model, and a debugging nightmare on the wrong defaults. Most ComfyUI users meet it through KJNodes' TorchCompileModelAdvanced, which is fine until you run it with an HSWQ-quantized model inside a multi-tile upscale and the graph starts recompiling per tile, or CUDA graph mode starts fighting the memory pool. This node is the HSWQ pack's version: based on that same KJNodes node, but with defaults tuned so it doesn't blow up in the workflows this pack actually runs.
What it does
It takes a loaded MODEL, clones it, and applies torch.compile through ComfyUI's own comfy_api.torch_helpers.set_torch_compile_wrapper - no KJNodes import required (the attribution to kijai stays in the README regardless; it's GPL-3.0-derived work). The defaults are the interesting part:
backend= inductor - the safe pick. The tooltip is blunt: use inductor with USDU; CUDA graphs often fail on multi-tile /cudaMallocAsyncpools.mode= max-autotune-no-cudagraphs - the "no-cudagraphs" half is deliberate, and it's the whole reason the defaults are safe with dynamic tile shapes.fullgraph= off,dynamic= off. Keep them that way for HSWQ ConvRot and Distorch paths; the node's block-only compile mode targets known transformer blocks (layers,double_blocks,single_blocks,transformer_blocks,blocks…) rather than the whole model when it can.
There's also a Windows-specific hardening layer: other extensions can raise inductor's compile_threads, which forces a process-pool spawn that re-imports ComfyUI's main.py after sys.path has been modified and crashes with ModuleNotFoundError: No module named 'utils.install_util'. This node forces serial compilation (compile_threads=1, worker_start_method=subprocess) and shuts down already-warmed spawn pools before applying the wrapper.
The inputs that matter
model- the MODEL to compile; output is a compiled MODEL clone you wire into your sampler.backend-inductor(default) orcudagraphs. Only reach forcudagraphson fixed-resolution, non-tiled work.mode-default/max-autotune/max-autotune-no-cudagraphs(default) /reduce-overhead.dynamo_cache_size_limit(64) andforce_parameter_static_shapes(on) - knobs for the common symbolictorch.Sizeerrors under nested tracing of quantized cast paths.patch_distorch_weight_cast(on) - marks the Distorch/dynamic-VRAM cast helpers as eager graph breaks, which keeps them from blocking compilation.disable_dynamic_vram(optional) - clones withdisable_dynamic=Truewhen the ComfyUI build supports it.
Where it goes and what to expect
Placement matters: after your HSWQ Checkpoint Loader (SDXL) or UNet Loader (and any LoRA), before the sampler or the HSWQ Ultimate SD Upscale. That's the pipeline the defaults were tuned against.
Two expectations to set before you hit Run. First, the first generation compiles - expect a long stall while inductor does its thing, then fast subsequent runs. That's normal and it's not a hang. Second, if you're doing multi-tile Ultimate SD Upscale, leave backend on inductor. The README's rule of thumb is one sentence: avoid CUDA graphs with multi-tile USDU. If you follow that, the "why is my workflow recompiling every tile" and the CUDA graph pool errors both stay away.
Install is the pack install - ComfyUI Manager or git clone https://github.com/ussoewwin/ComfyUI-HSWQ-Loader-and-Tools into custom_nodes, then restart. This is a node you'll mostly use in the HSWQ workflows the pack is built around; if you just want torch.compile for a plain fp16 model, KJNodes' original is the more battle-tested place to be.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| model | MODEL | — | |
| backend | COMBO | inductor | Use inductor with USDU. cudagraphs often fails on multi-tile / cudaMallocAsync pools. |
| fullgraph | BOOLEAN | false | Full graph mode. Keep False for HSWQ ConvRot / Distorch paths. |
| mode | COMBO | max-autotune-no-cudagraphs | HSWQ default avoids CUDA graphs (USDU / dynamic shapes). |
| dynamic | BOOLEAN | false | Dynamic shape tracing. Prefer off unless tile shapes vary every step. |
| dynamo_cache_size_limit | INT | 640–1024 | torch._dynamo.config.cache_size_limit |
| force_parameter_static_shapes | BOOLEAN | true | torch._dynamo.config.force_parameter_static_shapes — helps avoid symbolic weight Size errors. |
| patch_distorch_weight_cast | BOOLEAN | true | Mark comfy.ops cast_bias_weight etc. as eager (Distorch / dynamic VRAM). |
| debug_compile_keys | BOOLEAN | false | Log compile keys |
| disable_dynamic_vramopt | BOOLEAN | false | Clone model with disable_dynamic=True when ComfyUI supports it. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MODEL | MODEL | — |