Skip to content

Studio: chunk large Qwen-Image-2.1 attention queries on ROCm - #318

Closed
oobabooga wants to merge 1 commit into
mainfrom
fix/amd-qwen-attention-chunks
Closed

oobabooga wants to merge 1 commit into
mainfrom
fix/amd-qwen-attention-chunks

Conversation

@oobabooga

Copy link
Copy Markdown
Owner

Qwen-Image-2.1's native BF16 attention becomes a bottleneck at large image sizes on Radeon 8060S. With Q4_K_M and Auto memory at 1536x1536, the measured slowdown remains even when the transformer is resident. Splitting independent query rows reduces the attention runtime while retaining every key and value.

Fix

Install a pipeline-local Qwen-Image-2.1 processor that dispatches eligible queries in 512-row chunks. Enable it automatically only on the measured gfx1151 architecture, for native unmasked BF16 inference with at least 8192 query tokens and the model's 32-head/4096-wide attention layout.

Keep the stock processor for prefill, masks, smaller requests, other attention backends, parallel execution, gradients and compilation. Reuse Diffusers' QKV/cache preparation and output projections. Speed Off disables installation; UNSLOTH_QWEN_IMAGE_ROCM_QUERY_CHUNKING=0 opts out, and =1 allows explicit testing on other ROCm GPUs.

Tests

Live A/B against main at 4700dbc on Radeon 8060S (gfx1151), PyTorch 2.11 / ROCm 7.13, Qwen-Image-2.1 Q4_K_M, Auto memory, seed 42 and guidance 1.0. The planner sees 20 GiB total and 19 GiB free, with a 19 GiB PyTorch allocation cap. Both attention variants were tested without the encoder fix.

1536x1536 generation Main This PR
Linux, warm 4 steps 74.39 s 56.10 s
Windows, warm 4 steps 174.38 s 104.97 s
Linux, 40 steps 687.80 s 440.38 s
Windows, 40 steps 1948.72 s 537.50 s
Linux, warm image-conditioned 4 steps 117.09 s 72.40 s
Windows, warm image-conditioned 4 steps 274.01 s 145.17 s

Both OS jobs pass. All 16 attention comparisons are pixel-identical, including the 40-step images and image-conditioned outputs. At 1024x1024, both operating systems make zero chunking calls and preserve all three images and warm runtime. Peak GPU allocation is unchanged. The 40-step median decode step falls from 48.99 to 12.38 seconds on Windows and from 16.95 to 10.59 seconds on Linux; the unmodified first step stays around 45 and 20 seconds respectively.

The original 292 related tests passed; after the log clarification, all 174 processor/speed tests pass again. Coverage includes full-key/value chunk boundaries, cached-prefix and projection parity, backend selection, device/runtime guards and local installation. Formatting and diff checks pass. Post-A/B changes are limited to the load-log wording; attention computation is unchanged.

Live A/B run, both OS jobs passed

Scope

The automatic path is limited to gfx1151. RX 7900 XT and other ROCm architectures remain untested. The hardware probes in the run artifacts report shared-memory GPUs and 124.95 GiB of host RAM on Linux / 127.15 GiB on Windows, so the allocation cap does not emulate a discrete GPU's transfer costs. This does not change Auto placement, the Windows encoder fallback or cold MIOpen/VAE initialization. The processor uses helpers from Studio's pinned Diffusers version.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T05:38:14.815002Z cf68dab Manual request
🔒 Security Review ✅ Completed 2026-09-30T05:43:45.422600Z cf68dab Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@oobabooga

Copy link
Copy Markdown
Owner Author

@codex review

@oobabooga

Copy link
Copy Markdown
Owner Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: cf68daba2e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: cf68daba2e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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.

1 participant