Nodes/ComfyUI-HunyuanVideoWrapper/HunyuanVideo Torch Compile Settings
ComfyUI Node Runs on cloud

HunyuanVideo Torch Compile Settings

Squeeze more speed out of the transformer

By kijai·Created 2 years ago·Updated 12 months ago· 2,595
HunyuanVideo Torch Compile Settings
    • torch_compile_args
    backendinductor
    fullgraphfalse
    modedefault
    dynamicfalse
    dynamo_cache_size_limit64
    compile_single_blockstrue
    compile_double_blockstrue
    compile_txt_infalse
    compile_vector_infalse
    compile_final_layerfalse

    torch.compile traces your model's computation graph and generates optimized kernels for it, instead of running PyTorch's normal eager-mode Python loop. On a model as heavy as HunyuanVideo, that can be a real speedup - but it's not free, and this node is purely a settings bundle: it doesn't do anything by itself. Connect its output to compile_args on HyVideoModelLoader (or HyVideoVAELoader, which also accepts compile args) and that's what actually triggers compilation.

    The node's own description is the most important line in this whole article: it requires Triton, and torch 2.5.0 is recommended. If you don't have Triton installed, skip this node entirely rather than fight with it.

    The inputs that matter

    • backend - inductor (default, the standard PyTorch compiler backend) or cudagraphs, a lighter-weight alternative that captures and replays GPU operation sequences.
    • mode - default, max-autotune, max-autotune-no-cudagraphs, or reduce-overhead. max-autotune searches harder for the fastest kernel configuration at the cost of a much longer first-run compile; default is the sane starting point.
    • fullgraph - forces the whole model to compile as one graph rather than falling back to eager mode wherever compilation hits something it can't trace. Stricter, and more likely to just fail outright on an unsupported op rather than silently degrade.
    • dynamic - lets the compiled graph handle varying input shapes (different resolutions or frame counts) without recompiling each time. Leave off if you always run the same width/height/frame count and want the tightest optimization.
    • dynamo_cache_size_limit (default 64) - how many distinct compiled graph variants PyTorch will cache before falling back. Relevant mainly if you're varying shapes a lot.
    • compile_single_blocks / compile_double_blocks (both default on) - compile the transformer's main block stacks, where the bulk of compute happens.
    • compile_txt_in / compile_vector_in / compile_final_layer (all default off) - the smaller peripheral layers. Left off by default because they're a small fraction of total compute; the compile overhead usually isn't worth it for them.

    Output: torch_compile_args.

    How to install it

    Ships with the pack - no separate download. ComfyUI Manager: search ComfyUI-HunyuanVideoWrapper, install, restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kijai/ComfyUI-HunyuanVideoWrapper
    pip install -r ComfyUI-HunyuanVideoWrapper/requirements.txt
    

    then restart. Triton is the extra piece this node needs beyond the pack itself - it's a separate install (pip install triton on Linux; noticeably more friction on Windows), and it's the same dependency the wrapper's sageattn attention mode needs.

    Common issues & troubleshooting

    Errors mentioning Triton, or the compile step just fails. Triton isn't installed, or isn't a version that plays well with your torch install. This is a well-known rite of passage across the ComfyUI ecosystem, and it's worse on Windows than Linux. If you don't want to deal with it, don't use this node - the wrapper runs fine without compilation, just slower.

    First generation after connecting this node is much slower than normal, then later ones are fast. That's compilation happening - it's a one-time (per shape) cost, not a per-run cost. Don't judge the speedup from your first generation.

    Changed resolution or frame count and it recompiled from scratch. Expected unless dynamic is enabled - each distinct input shape triggers its own compile pass. If you're iterating across different sizes, either turn dynamic on (some speed cost) or accept the recompile tax each time you change shape.

    It compiled fine but you don't see much speedup. Try max-autotune for a more aggressive search, and make sure compile_single_blocks/compile_double_blocks are both on - those are where most of the model's compute lives.

    CategoryHunyuanVideoWrapper

    Inputs (10)

    NameTypeDefaultDescription
    backendCOMBOinductor2 options: inductor, cudagraphs
    fullgraphBOOLEANfalseEnable full graph mode
    modeCOMBOdefault4 options: default, max-autotune, max-autotune-no-cudagraphs, reduce-overhead
    dynamicBOOLEANfalseEnable dynamic mode
    dynamo_cache_size_limitINT640–1024torch._dynamo.config.cache_size_limit
    compile_single_blocksBOOLEANtrueCompile single blocks
    compile_double_blocksBOOLEANtrueCompile double blocks
    compile_txt_inBOOLEANfalseCompile txt_in layers
    compile_vector_inBOOLEANfalseCompile vector_in layers
    compile_final_layerBOOLEANfalseCompile final layer

    Outputs (1)

    NameTypeDescription
    torch_compile_argsCOMPILEARGS