Repository navigation
[Bugfix][XPU] Honor full_attn_spans in the XPU FlashAttention path - #9123
Conversation
Signed-off-by: Iryna Boiko <iboiko@habana.ai>
Codex Review SummaryThis 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. |
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
This PR appears to belong to: docs/design/module/diffusion/index.md. Module owners: @Isotr0py @david6666666 @princepride Routing: @Isotr0py via module of the changed files, module named in the PR description, semantic router, CODEOWNERS; @david6666666 via module of the changed files, module named in the PR description, semantic router; @princepride via module of the changed files, module named in the PR description, semantic router @iboiko-habana, please review your own changes and leave a short self-review comment describing what you checked. PRs without author self-review may not be assigned a reviewer. Please take a look when you have a chance. If you would like an automated review, mention @vllm-omni-review-bot in a comment. |
Omni ReviewBot triage noteAutomated triage of commit
These are automated triage suggestions only — the final decision belongs to the maintainers. |
Omni ReviewBot: three questions on the performance claim@iboiko-habana this PR reads as a performance or value claim:
Before the full evidence checklist, three short questions:
When you answer, the evidence that settles it is: base and head SHA, hardware, model, workload, warm-up and repeat count, mean or percentiles with their spread, and a correctness/quality-equivalence signal; an end-to-end claim also needs stage attribution. |
#8798 (#9251) Signed-off-by: aayc123 <2803023760@qq.com> Signed-off-by: aayc123 <115020989+aayc123@users.noreply.github.com> Signed-off-by: 曾妮 <2803023760@qq.com> Signed-off-by: haic0 <149741444+haic0@users.noreply.github.com> Signed-off-by: andyluo7 <andy.luo@amd.com> Signed-off-by: caoshijie <shijiecao4@gmail.com> Signed-off-by: wuli666 <421774554@qq.com> Signed-off-by: Iryna Boiko <iboiko@habana.ai> Signed-off-by: NumberWan <wantszkin2003@gmail.com> Co-authored-by: aayc123 <115020989+aayc123@users.noreply.github.com> Co-authored-by: haic0 <149741444+haic0@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: andyluo7 <andy.luo@amd.com> Co-authored-by: Shijie_cao <shijiecao4@gmail.com> Co-authored-by: dengyunyang <584797741@qq.com> Co-authored-by: wuli666 <421774554@qq.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: NATURE <wzliu@connect.hku.hk> Co-authored-by: Iryna Boiko <iryna.boiko@intel.com> Co-authored-by: Chendi.Xue <chendi.xue@intel.com> Co-authored-by: NumberWan <wantszkin2003@gmail.com> Co-authored-by: wangyu <53896905+yenuo26@users.noreply.github.com>
…ask check Regression from vllm-project#9248: its dense 4D mask check in Attention._run_local_attention diverts a 4D attn_mask to SDPA, or rejects it for an explicitly selected backend, when the backend cannot consume 4D masks. HunyuanImage3 sends the 4D mask together with full_attn_spans, and piecewise backends (FlashAttention on CUDA and XPU after vllm-project#9123, FlashAttention Hub) honor the spans and never read the mask. As a result HunyuanImage3 with FLASH_ATTN fails on XPU again, undoing vllm-project#9123, and silently falls back to SDPA under automatic backend selection. Skip the check when full_attn_spans is set and the backend supports piecewise spans. Span-less dense masks keep the vllm-project#9248 behavior. Signed-off-by: Iryna Boiko <iboiko@habana.ai> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor intent (required human answers)
1. What outcome do you want to achieve?
HunyuanImage-3.0 runs correctly on Intel XPU with
DIFFUSION_ATTENTION_BACKEND=FLASH_ATTNinstead of failing every request with HTTP 500.2. What is the highest-leverage variable for that outcome?
The XPU FlashAttention backend honoring
full_attn_spans, the mixed causal/full attention contract the backend already advertises.3. How will this work move that variable?
forward_xpunow dispatches spans throughpiecewise_attnwith the varlen wrapper, exactly asforward_cudadoes, so models that pass spans get correct mixed attention on XPU.4. Whose customer or user needs does this address, and what are those needs?
Users serving HunyuanImage-3.0 (and other span-based models such as Qwen-Image 2.1 and HiDream-O1) on Intel GPUs. They need the default fast attention backend to work and produce correct images, without falling back to TORCH_SDPA.
Purpose
Before:
FlashAttentionImpl.forward_xpuignoresAttentionMetadata.full_attn_spans, althoughFlashAttentionBackendadvertisessupports_piecewise_spans = Trueon every platform.DIFFUSION_ATTENTION_BACKEND=FLASH_ATTNfails on XPU. On the dense prompt-KV path (_forward_dense_legacy), the model passes a 4Dattn_masktogether withfull_attn_spans.forward_xpusends the 4D mask to_forward_varlen_masked, which assertsattention_mask must be 2D, so every request returns HTTP 500. XPU uses this path because it has no Scheduler-paged KV.supports_piecewise_spans. On XPU they fall through to_forward_varlen_dense, which runs plain full attention, so the causal segments are not applied. This is from code inspection; I did not run these models on XPU.After: when
full_attn_spansis present,forward_xpudispatches throughpiecewise_attnwith the existing_flash_varlen_wrapper, likeforward_cuda(XPU only providesflash_attn_varlen_func). Spans take precedence overattn_mask, as on CUDA. Other XPU paths are unchanged.Contracts and docs: this brings XPU in line with the existing piecewise-span contract of the Flash backend (see Attention execution contract and the span inputs in Diffusion paged KV cache). The user guides (Diffusion Attention Backends, Dense backends) need no update: they don't say XPU lacks span support, and the user-facing configuration is unchanged.
Alternatives considered
_forward_pagedraisesNotImplementedError). It would still depend on this span dispatch.Known limitations (same as CUDA): spans must be identical across batch rows, otherwise
piecewise_attnraisesValueError.attn_maskis ignored when spans are present.AI assistance was used to prepare this change. The author reviewed every changed line and ran the tests below.
Test Plan
vLLM Version: v0.31.0 (XPU image)
vLLM-Omni Commit:
da572cddb(v0.32.0rc1) + this patch9bbfb61d5+ the identical patch. The rebased tree requires vLLM v0.32 serving APIs (e.g.vllm.renderers.chat_utils), which the v0.31.0 XPU image lacks. The patched code path is identical on both bases; the only upstream change in it ([Bugfix][Diffusion] Pass the resolved FA version into dense varlen attention #9100,fa_versionkwargs) applies only to vLLM's CUDA varlen dispatcher.Hardware: 4x Intel Arc Pro B70 (Battlemage)
DIFFUSION_ATTENTION_BACKEND=FLASH_ATTNvsTORCH_SDPA.full_attn_spans(bottom-right causal + full spans) with the model's real 4D mask, andF.scaled_dot_product_attentionon the same Q/K/V with the real 4D mask.Test Result
Regression test:
test_xpu_piecewise_spans_ignore_4d_maskv0.32.0rc1): 1 failed,AssertionError: attention_mask must be 2D, (batch_size, seq_len)v0.32.0rc1):test_flash_attn.py+test_piecewise_attn.py: 80 passed, 7 deselectedEnd-to-end (HunyuanImage-3.0 on XPU, previous base + identical patch):
FLASH_ATTNattention_mask must be 2D)TORCH_SDPAFLASH_ATTNvsTORCH_SDPAimage PSNR: 19.4 dB. For reference, twoTORCH_SDPAserver starts differ by 23.8 dB. The remaining gap is numeric drift over the denoising steps; the operator-level check below shows the attention semantics are identical.FLASH_ATTNis about 4% faster end-to-end thanTORCH_SDPAin this configuration.Operator-level equivalence (real HunyuanImage-3.0 shapes):
[(94, 1118)][(94, 1118)]Not run:
v0.32.0rc1(needs a vLLM v0.32 XPU image).