[Bugfix] Fix flash-attention func param mismatch and softmax_scale default value mistake on Ascend NPU#37575
Merged
MekkCyber merged 2 commits intohuggingface:mainfrom Apr 18, 2025
Merged
Conversation
Contributor
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
98b4473 to
8bc2bfb
Compare
Contributor
Author
|
@ArthurZucker please help me review and merge it, thanks~ |
8bc2bfb to
b99b85b
Compare
SunMarc
approved these changes
Apr 17, 2025
Comment on lines
+197
to
+198
| max_seqlen_q=None, | ||
| max_seqlen_k=None, |
Member
There was a problem hiding this comment.
maybe leave a msg on why we put those here
Contributor
Author
There was a problem hiding this comment.
@SunMarc Thanks for your suggestion, I have added code comments on both params.
…fault value mistake on Ascend NPU
b99b85b to
2d7c8e1
Compare
zucchini-nlp
pushed a commit
to zucchini-nlp/transformers
that referenced
this pull request
May 14, 2025
…fault value mistake on Ascend NPU (huggingface#37575) [Bugfix] fix flash-attention func param mismatch and softmax_scale default value mistake on Ascend NPU Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
After we support using Flash Attention on Ascend NPU(PR), we found 2 bugs in the implementation of Flash Attention on Ascend NPU. This PR is committed for solving both.
Bugfix1:
We found that there exists a kind of situation in the code of
mainbranch, where funcflash_attn_varlen_funcis used without key-value style params passing, like following code:transformers/src/transformers/models/qwen2_5_vl/modeling_qwen2_5_vl.py
Line 203 in 3bc44ea
In that case, params order between func
flash_attn_varlen_funcin packageflash-attnand funcnpu_flash_attn_varlen_funcin packagetransformersis not aligned, which may cause unexpected errors 😞Therefore, we solve this problem by aligning mismatch params
max_seqlen_qandmax_seqlen_k.At the same time, we have also checked the func
npu_flash_attn_func, and it does not have param order mismatch problem.Bugfix2:
For func
npu_flash_attn_funcandnpu_flash_attn_varlen_func, when paramsoftmax_scaleis set toNone, it should be set to1.0 / sqrt(q.shape(-1))as default value.Fixes # (issue)
Not related.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.