Skip to content

Disable SageAttention for Hunyuan3D v2.1 DiT#12772

Merged
comfyanonymous merged 1 commit intoComfy-Org:masterfrom
paulomuggler:fix/hunyuan3d-sage-attention
Mar 17, 2026
Merged

Disable SageAttention for Hunyuan3D v2.1 DiT#12772
comfyanonymous merged 1 commit intoComfy-Org:masterfrom
paulomuggler:fix/hunyuan3d-sage-attention

Conversation

@paulomuggler
Copy link
Copy Markdown
Contributor

@paulomuggler paulomuggler commented Mar 4, 2026

Summary

SageAttention produces NaN in the Hunyuan3D v2.1 DiT, causing empty meshes and a crash in save_glb:

ValueError: zero-size array to reduction operation maximum which has no identity

This adds low_precision_attention=False to both optimized_attention calls in the v2.1 DiT, following the same pattern as ACE Step 1.5 (#12297). SageAttention falls back to pytorch attention for Hunyuan3D only.

Diagnosis

Debug logging on the VAE decode input confirmed the DiT output is entirely NaN when SageAttention is active. The 3D occupancy prediction requires higher precision at voxel boundaries than SageAttention's quantized kernels provide. Image/video diffusion tolerates this precision loss; 3D does not.

Fixes #10943

Test plan

  • Hunyuan3D 2.1 image-to-3D produces valid mesh with --use-sage-attention enabled
  • Image/video workflows still use SageAttention (unaffected)

🤖 Generated with Claude Code

SageAttention's quantized kernels produce NaN in the Hunyuan3D v2.1
diffusion transformer, causing the downstream VoxelToMesh to generate
zero vertices and crash in save_glb.

Add low_precision_attention=False to both optimized_attention calls in
the v2.1 DiT (CrossAttention and Attention classes), following the same
pattern used by ACE (ace_step15.py). This makes SageAttention fall back
to pytorch attention for Hunyuan3D only, while all other models keep
the SageAttention speedup.

Root cause: the 3D occupancy/SDF prediction requires higher numerical
precision at voxel boundaries than SageAttention's quantized kernels
provide. Image and video diffusion tolerate this precision loss.

Fixes: Comfy-Org#10943

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

📝 Walkthrough

Walkthrough

This change modifies the HunyuanDIT attention implementation by explicitly setting low_precision_attention=False in two forward paths. The parameter is passed to the optimized_attention function calls within the CrossAttention and Attention modules. This ensures that the attention computation uses high-precision computation paths rather than potentially lower-precision alternatives. The change affects the internal execution path of the attention kernel without modifying the surrounding logic or expected outputs.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: disabling SageAttention for Hunyuan3D v2.1 DiT by passing low_precision_attention=False to optimized_attention calls.
Linked Issues check ✅ Passed The PR directly addresses issue #10943 by preventing NaN outputs in the DiT that were causing save_glb to crash on zero-size arrays, matching the objective of enabling successful Hunyuan3D 2.1 workflows.
Out of Scope Changes check ✅ Passed The changes are narrowly scoped to the Hunyuan3D v2.1 DiT file, adding only two parameters to control attention precision without affecting image/video workflows or other components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining why low_precision_attention=False is being added to the optimized_attention calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@comfyanonymous comfyanonymous merged commit 8cc746a into Comfy-Org:master Mar 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zero-size array to reduction operation maximum which has no identity is:issue

2 participants