Skip to content

Conversation

FightingZhen
Copy link
Contributor

@FightingZhen FightingZhen commented Aug 1, 2025

What does this PR do?

After PR #39474 merged, flash_attention_2 is unavailable on Ascend NPU, because package flash-attn can not be installed on Ascend NPU :(

This PR is committed for solving this problem.

Detail modification:

  1. Follow newest flash attention preparation logics in src/transformers/modeling_flash_attention_utils.py module, use get_npu_flash_attn_funcs return flash attention related functions for Ascend NPU.
  2. Ignore logics related with package flash-attn in func _flash_attn_2_can_dispatch from src/transformers/modeling_utils.py module, it is not required for Ascend NPU.

Fixes # (issue)
Not related.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

@FightingZhen FightingZhen marked this pull request as ready for review August 2, 2025 07:29
@FightingZhen FightingZhen changed the title [WIP][bugfix] fix flash_attention_2 unavailable error on Ascend NPU [bugfix] fix flash_attention_2 unavailable error on Ascend NPU Aug 2, 2025
@FightingZhen
Copy link
Contributor Author

Please help me review this, thanks a lot! @ArthurZucker

@FightingZhen
Copy link
Contributor Author

@ArthurZucker please help me review and merge, thanks ~

@Rocketknight1
Copy link
Member

cc @ivarflakstad @SunMarc

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ! Sorry for the breaking change

@SunMarc SunMarc enabled auto-merge (squash) August 6, 2025 17:35
@SunMarc SunMarc merged commit ac0b468 into huggingface:main Aug 6, 2025
26 checks passed
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Yulv-git
Copy link
Contributor

Yulv-git commented Aug 7, 2025

Very good work. Can Flash Attention 3 also be used on the Ascend NPU?

@FightingZhen
Copy link
Contributor Author

Very good work. Can Flash Attention 3 also be used on the Ascend NPU?

Hi, as far as i know, flash-attention-3 is not supported yet on Ascend NPU, see doc

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.

5 participants