Skip to content

Studio: keep Qwen-Image-2.1 image conditioning finite on ROCm - #12360

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:fix/amd-qwen21-vision-attention
Oct 1, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
oobabooga:fix/amd-qwen21-vision-attention

Conversation

@oobabooga

Copy link
Copy Markdown
Member

Qwen-Image-2.1 reference-image generation produces NaN conditioning and blank images on Radeon 8060S with native vision SDPA, on both Windows and Linux.

Fix

Use eager attention in 512-query-row chunks for the encoder's Qwen3-VL vision tower, retaining all keys and values. This avoids native SDPA's NaNs without the memory cost of unbounded eager attention. The language model, denoiser and global SDPA settings stay unchanged, and the fix applies with Speed Off too.

Default to ROCm gfx1151 only. UNSLOTH_QWEN_IMAGE_ROCM_VISION_EAGER=0 opts out; =1 enables testing on other ROCm GPUs. Preserve explicitly selected non-SDPA backends and report installation failures instead of silently skipping the fix.

Tests

Windows/Linux A/B on Radeon 8060S, PyTorch 2.11 / ROCm 7.13:

  • Native SDPA produced NaNs; the patch produced finite, nonblank 40-step images. Dense encoders with Speed Off, 512/2048 reference sizes and two repeated reference inputs also passed. Opt-out reproduced the failure.
  • The 2048-reference case peaked at 24.36 GiB under a 48 GiB cap; unbounded eager and math attention had run out of memory at that cap. Four-step detail cases validate finiteness and memory, not image quality.
  • Text-only decoder inputs remained bit-identical on both OSes.

148 focused and related tests pass after rebasing onto b1c522a4ea; Ruff and formatting checks pass. Hardware A/B used 4e8503e437 and was not repeated after the rebase and override/error-handling changes. The attention calculation is unchanged.

RX 7900 XT and other ROCm architectures remain untested.

@oobabooga

Copy link
Copy Markdown
Member Author

Reached Codex review convergence at oobabooga#320.

@danielhanchen

Copy link
Copy Markdown
Member

Review record for #12360, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#267.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 8e4ce5bcb6 (this PR's 8d1643378)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 8e4ce5bcb6

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 8e4ce5bcb6 (this PR's 8d1643378).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

@danielhanchen
danielhanchen merged commit 0e2df89 into unslothai:main Oct 1, 2026
33 of 36 checks passed
@LeoBorcherding

LeoBorcherding commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Tested on a discrete RDNA4 card with UNSLOTH_QWEN_IMAGE_ROCM_VISION_EAGER=0 vs =1. Native SDPA in the vision tower doesn't produce NaNs there, so the gfx1151 restriction looks correct as it stands.

1024² reference edit, 4 steps Native SDPA Chunked eager
Finite checks (encoder, vision tower, transformer) All pass All pass
Prompt encode 26.1 s 26.0 s
Peak allocation 25.79 GiB 25.79 GiB

Both images are normal (max pixel difference 14/255, mean 0.37). The eager path is harmless on this card but fixes nothing here. Only the 1024 reference size was run; 2048 references and multiple references weren't.

Setup: Radeon AI PRO R9700 (gfx1201), Windows 11, PyTorch 2.11 / ROCm 7.13, main at 364a42f0, Q4_K_M, Auto memory, seed 42, using full_probe.py from the amd-qwen21-memory-probe workflow with no allocator cap. One run per side.

Recommend keeping it gfx1151-only. A gfx1100 (RX 7900-class) run is still the open question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants