Repository navigation
Studio Windows ROCm: decode compile only off for wide-head VAEs, fp64 kept, nested-safe SDPA guard - #18582
Merged
Conversation
…de-head VAEs The platform check returned False for every Windows ROCm VAE before looking at it, so a VAE with no attention head wider than 256 also lost decode compile. The gate now inspects the VAE's attention modules (an uninspectable VAE or module still counts as wide), keeping the guarantee that a wide-head VAE never compiles past the routing, env override included.
fp32_math_sdpa upcast every input with .float(), so an fp64 call ran fp32 scores and overflowed where stock SDPA stays finite. Only fp16 / bf16 upcast now; fp32 and fp64 run in their own precision.
The guard read query.shape first, which raises on a strided NestedTensor, so a CPU nested SDPA call failed in a Windows ROCm process instead of dispatching. The device is checked first and a nested CUDA query is judged by size(-1).
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three fixes to the Windows ROCm attention routing added in #17953 and #17960, found in a recheck of the kernel PRs. Each is its own commit.
1. VAE decode compile is dropped only for wide-head VAEs
#17953 keeps the Windows ROCm VAE decode eager so a compiled decode cannot skip the attention routing that keeps head dim 512 off the fused SDPA kernels. But
_vae_decode_compile_allowedreturned False on the platform alone, before looking at the VAE or theUNSLOTH_DIFFUSION_COMPILE_VAEsetting. A VAE with no attention head wider than 256 (attention-free video VAEs, or a narrow AutoencoderKL) lost decode compilation too, even when the env asked for it.diffusion_vae_attn_chunked.py: newvae_has_untrusted_head(vae). It walks the same attention modules the routing patches and reads each head dim (inner_dim // headson diffusersAttention). Any head wider than 256, any attention module whose head dim it cannot read (the single-head blocks of Wan, Qwen-Image and HunyuanImage), and any VAE it cannot inspect count as wide.diffusion_speed.py: on Windows ROCm_vae_decode_compile_allowedreturns False only whenvae_has_untrusted_headis True. The check still runs before the U-Net shortcut and the env override, so a wide-head VAE never compiles past the routing there.Studio's own AutoencoderKL and AutoencoderKLFlux2 VAEs have a single-head mid-block at 512, so they stay eager on Windows ROCm exactly as before.
2. fp64 stays fp64 in the wide-head math path
fp32_math_sdparan.float()on Q, K and V and cast only the result back, so an fp64 call was silently reduced to fp32. With fp64[1, 1, 3, 512]operands filled with1e20, stock SDPA returns finite output while the routed path overflowed and returned NaN. It now upcasts only fp16 and bf16; fp32 and fp64 run in their own precision. Half inputs keep the existing fp32 upcast, soUNSLOTH_VAE_ATTN_HALF_MATH=0is unchanged. Studio loads VAEs in fp16, bf16 or fp32, so this only matters to code handing a double VAE to the routed attention.3. The SDPA guard checks the device before the query shape
The Windows ROCm SDPA wrapper's
_wide_cuda_headreadquery.shapebefore checking the device. A strided NestedTensor raisesNestedTensorImpl doesn't support sizeson.shape, so a valid CPU nested SDPA call failed inside the wrapper. It now returns False for any non-CUDA query without touching the shape, judges a nested CUDA query bysize(-1), and sends the call to the stock dispatch if even that raises. Dense CUDA queries are judged as before.Tests
CPU only, Windows ROCm faked:
tests/test_diffusion_windows_rocm_wide_head.py:test_windows_rocm_keeps_decode_compile_unless_the_vae_has_a_wide_head, with tiny real diffusers AutoencoderKL VAEs: the head-64 and no-attention cases fail on main and pass here. The two head-512 cases (with and without the env forcing compile) are still refused, passing on both.test_windows_rocm_fp64_wide_head_keeps_fp64_precision[1073741824|16](unchunked and chunked): fail on main (NaN), pass here.test_vae_decode_compile_stays_eager_on_windows_rocm(an uninspectablevae=object()stays eager) passes on both.tests/test_rocm_windows_wide_head_sdpa.py:test_a_nested_cpu_query_reaches_the_stock_dispatchandtest_a_nested_cuda_query_is_judged_by_its_head[128-False|512-True]fail on main and pass here.Base vs head over both files: 7 tests fixed, 31 unchanged, 0 failing on this branch. Wider suite (
test_diffusion_vae_attn_chunked.py,test_diffusion_speed.py,test_diffusion_vae_fused.py,test_diffusion_vae_regional_compile.py): no failures on main or here apart from the new tests on main.Windows gfx1151 (AMD CI)
Real Windows ROCm (torch 2.11.0+rocm7.14.0, gfx1151), base = main, head = this branch, two tiny AutoencoderKL VAEs (head dim 64 and 512) on the real GPU:
CONFIRMED: main refuses decode compile for the narrow VAE, this branch allows it, the compiled decode matches eager, and the head-512 VAE is still refused.
Not proven here