Repository navigation
Description
Environment
Where are you using Unsloth?
- Unsloth desktop application
- Unsloth web UI (
unsloth studio) - Unsloth CLI
- Python package or notebook
- Colab or Kaggle
Operating system and version: Linux Mint 22.3 (Zena), Ubuntu 24.04 base, kernel 7.3.4-x64v3 xanmod
GPU model(s) and accelerator backend: AMD Navi 22 [Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT] (1002:73df), gfx103X, ROCm — torch 2.11.0+rocm7.13.0 wheel
Versions: Unsloth desktop v0.1.917-beta; issue persists in v0.1.918-beta (verified by diffing studio/backend/core/inference/diffusion_vae_attn_chunked.py between the two tags: only additions are Windows-gated); torch 2.11.0+rocm7.13.0
What happened?
Steps to reproduce:
- Load
unsloth/Z-Image-Turbo-GGUForunsloth/Z-Image-Turbo-unsloth-bnb-4bitin the desktop app's image generation - Generate at any resolution from 512–1024 px with any settings: fails identically for GGUF Q4/Q8 and bnv 4-bit, compiled (default speed) or eager (
speed_mode=off) - Denoising completes; the failure is in the final full-resolution VAE decode
Expected behavior: Image saves successfully. This worked on this machine through v0.1.916-beta until the Nov 11 auto-update to v0.1.917-beta.
Actual behavior: Generation fails at ~99% with:
RuntimeError: The decoded image contains NaN values and would be saved as a blank image.
File ".../diffusers/pipelines/z_image/pipeline_z_image.py", line 596, in __call__
image = self.image_processor.postprocess(image, output_type=output_type)
File "~/unsloth_studio/lib/python3.13/site-packages/studio/backend/core/inference/diffusion_postprocess.py", line 123, in postprocess
Model and operation involved: unsloth/Z-Image-Turbo-GGUF + unsloth/Z-Image-Turbo-unsloth-bnb-4bit, diffusion image generation. (Note: bnv int8 GEMMs are separately broken on this box by ROCm 7.2 bitsandbytes wheels under a 7.13 runtime — different path, see below.)
Diagnostics and logs
From ~/.unsloth/studio/logs:
- Progress reaches
"phase": "decode", "percent": 100immediately before each failure: denoising is clean; only the final decode NaNs. Intermediate live-preview decodes look fine — matches a full-resolution-only overflow. - This card has no fused SDPA kernels for VAE attention head dims (384/512): flash / efficient / cudnn all report "No available kernel", so math backend runs everywhere;
diffusion.attention.math_onlywarnings are logged on every load.
Root cause analysis: Since #17252/#17350 (Nov 9–10, shipped in v0.1.917-beta), studio/backend/core/inference/diffusion_vae_attn_chunked.py runs the VAE attention math SDPA on ROCm by default in the model's own fp16/bf16 dtype (half_math_sdpa) instead of an fp32 upcast. At head dims 384/512 over full-resolution spatial maps, that path overflows to NaN on gfx103X / torch 2.11+rocm7.13.
Workaround (verified): Launch Studio with UNSLOTH_VAE_ATTN_HALF_MATH=0 — restores the fp32-upcast math SDPA (pre-917 behaviour). GGUF and bnv at 512 / 768 / 1024 px all render cleanly.
Suggested fix: Extend the wide-head guard from #17976 (studio/backend/core/_rocm_windows_sdpa.py, currently win32-gated) to Linux ROCm when no fused kernel is available for head dim > 256 — route those calls through fp32_math_sdpa as the Windows path now does, or make half-math opt-in on hosts without a trusted kernel.
Unrelated observation (please split if preferred): bitsandbytes wheels in this venv are ROCm-7.2 builds running under a 7.13 runtime; int8 GEMMs fail with "No available kernel" while bnv 4-bit works through a different path. Flagging for the wheel-release process only.
Activity
ROCm VAE attention: half math for bf16 only, fp16 takes the fp32 upcast
danielhanchen commentedon Nov 17, 2026
Thanks for the detailed report and the workaround, it pointed straight at the cause.
Root cause: on ROCm cards without native bf16 (gfx103x and older), Studio runs the VAE in fp16. The Z-Image (FLUX.1) VAE's mid-block attention produces scores between about 1e6 and 5e7 on real images, far above fp16's maximum of 65504. The half-precision math path therefore turned every score into inf and every softmax row into NaN. bf16 has the same exponent range as fp32 and is unaffected, which is why gfx11 / gfx1151 never saw this.
The fix (in #18077) keeps the faster half-precision VAE attention only for bf16. fp16 VAEs go back to the fp32-upcast math, exactly what
UNSLOTH_VAE_ATTN_HALF_MATH=0does. On a gfx1151 forced to fp16, the Z-Image VAE decode went from all-NaN to finite at 512 and 1024 px, bitwise equal to the workaround, and the bf16 decode keeps its speed (814 ms, vs 1032 ms for the fp32 upcast). Once it ships you can drop the environment variable.The bitsandbytes ROCm 7.2 vs 7.13 wheel mismatch is a separate issue; feel free to open it on its own.
Studio ROCm: half-math VAE attention for bf16 only; fp16 takes the fp…