Repository navigation
Conversation
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
| import pytest | ||
| from fastapi import FastAPI | ||
| from fastapi import HTTPException | ||
| from fastapi import FastAPI, HTTPException |
Signed-off-by: gcanlin <canlinguosdu@gmail.com>
There was a problem hiding this comment.
can you report the performance measurements in the description? e.g. run benchmarks comparing the original Attention layer with this SDPAImpl workaround on realistic workloads and report the generation latency and peak VRAM usage before and after. also verify that quality is preserved without accuracy degradation.
| # Unified attention layer | ||
| self.attn = Attention( | ||
| # Force SDPA backend for cross-attention (workaround) | ||
| self.sdpa_impl = SDPAImpl( |
There was a problem hiding this comment.
Bypassing the unified Attention layer skips the pre_attention and post_attention hooks used for parallel strategies. This breaks the abstraction and may cause issues with distributed execution. Consider adding a backend_override parameter to the Attention class instead of hardcoding SDPAImpl here.
There was a problem hiding this comment.
We expect to only change Wan2.2 modeling file. If add backend_override in attention, we have to change the attention layer. As a workaround, I prefer to hardcode here. We have confirmed the performance didn't happen degradation offline.
|
BLOCKER scan:
OVERALL: NO BLOCKERS VERDICT: COMMENT Question: This is marked as a [Workaround]. Is there a plan to add SDPA as a configurable option with proper fallback to other backends for different hardware? The current forced SDPA approach may not work on all GPUs. |
|
have updated to only be applied on NPU. |
lishunyang12
left a comment
There was a problem hiding this comment.
Review of [v0.18.0.post1][Perf] handle cross attention with different Q/KV seqlen on NPU
Overall the approach is sound: bypass LA (which does not support mismatched Q/KV seqlen) and call torch_npu.npu_fusion_attention directly for cross attention. A few items worth addressing:
1. Layout detection heuristic is fragile (main concern)
if query.shape[2] == self.num_heads:
layout = "BSND"
else:
layout = "BNSD"This assumes S != num_heads. If a model happens to use S == num_heads (e.g., 24 heads with a 24-token sequence), the layout will be misidentified. Consider one of:
- Accept
layoutas a constructor / method parameter so callers declare it explicitly. - Add a secondary check, e.g., also verify
query.shape[1] != self.num_headsand raise anAssertionErrorif both dimensions match, making the ambiguity visible. - At minimum, add a comment documenting this assumption and the known limitation.
2. pre_tokens / next_tokens magic numbers
pre_tokens=2147483647,
next_tokens=2147483647,These are INT32_MAX. They effectively disable causal masking, which is correct for cross attention, but they should be named constants (e.g., _NPU_NO_CAUSAL = 2147483647) with a one-line comment explaining why, so future readers do not wonder if this is an overflow bug.
3. import torch_npu inside the hot path
The import torch_npu is inside the if q_seqlen != k_seqlen branch, which runs on every cross-attention forward call. Python caches module imports after the first load so the runtime cost is small, but it is conventional to do the import once at module level (guarded by a try/except) or at __init__ time, similar to how mindiesd is imported in the self-attention path. This also lets you fail fast at startup if torch_npu is missing.
4. PR description vs. diff mismatch
The description states "Reverts WanCrossAttention to use unified Attention layer", but no changes to wan2_2_transformer.py (or any Wan model file) are included in this diff. Was that change dropped or is it in a separate PR?
5. Test coverage
The test file change is just an import style fix (combining two from fastapi import ... lines). There are no new tests exercising the cross-attention path. Given this is a correctness-sensitive code path, at least a unit test verifying that:
- BSND and BNSD layouts are detected correctly,
- the
torch_npupath is taken whenq_seqlen != k_seqlen, - the
mindiesdpath is taken whenq_seqlen == k_seqlen,
would be valuable, even if they need to be mocked for CI environments without NPU hardware.
Minor
- The
attention_forwardcall in the self-attention path now uses the dynamically detectedlayoutinstead of the hardcoded"BNSD". This is a good improvement, but please confirm thatattention_forwardfrom mindiesd supports"BSND"layout -- the old code always passed"BNSD".
Not blocking, but items 1 and 4 should be addressed before merge.
|
@SamitHuang @david6666666 PTAL. A new workaround. Will integrate it into #2681 using an elegant way. |
PLEASE FILL IN THE PR DESCRIPTION HERE ENSURING ALL CHECKLIST ITEMS (AT THE BOTTOM) HAVE BEEN CONSIDERED.
Purpose
ascend_laser_attention (LA) doesn't support different Q/KV sequence lengths, which causes errors for cross attention where Q comes from decoder (long seq) and KV comes from encoder (short seq, e.g. 512 text tokens).
This change:
Test Plan
Test Result
Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model. Please runmkdocs serveto sync the documentation editions to./docs.BEFORE SUBMITTING, PLEASE READ https://github.com/vllm-project/vllm-omni/blob/main/CONTRIBUTING.md (anything written below this line will be removed by GitHub Actions)