Adapt to the SDPA interface to enable the NPU to call FlashAttentionScore
Author: frozenleaves
Pull request: yes


# What does this PR do?

Enable the torhc native SDPA interface  to invoke the FlashAttentionScore operator of NPU.


----

### Restrictions on the use of torch native interface calling FA operator: 
1. When is_causal calculation is enabled, attn_mask must be None; when is_causal is not enabled, if attn_mask enters valid data, the input data type must be Bool type.
2. When entering the data types of query, key, value, and enables requirements_grad, executes the FA operator.

Comments:
> Thanks for iterating
> 
> * Can you look at [#41143 (review)](https://github.com/huggingface/transformers/pull/41143#pullrequestreview-3267237606) --> just want to make sure that `use_gqa` is also supported on npu and if there are any restrictions
> * And a last comment on the questions from @FightingZhen --> I think one question has been handled, but the other should be addressed imo

@vasqu I've received question 1. It's currently under internal review with the team, and I will provide an update in the PR once we have a conclusion.

**compare the loss between original sdpa and this pr:**
internlmVL3-1B-hf:
<img width="1366" height="946" alt="image" src="https://github.com/user-attachments/assets/2ee542ac-4132-4836-bb06-815a79f1db86" />

qwen3-1.7B:
<img width="1358" height="940" alt="image" src="https://github.com/user-attachments/assets/9aa0e3cc-60c8-4505-ac37-cf425a7e0dca" />


**compare the loss between original eager and this pr:**
internlmVL3-1B-hf:
<img width="1362" height="945" alt="image" src="https://github.com/user-attachments/assets/2c258bc9-ca51-44e2-a68f-ad8059726abe" />

qwen3-1.7B:
<img width="1357" height="948" alt="image" src="https://github.com/user-attachments/assets/be0231a6-d6b3-4287-9d8e-d92c182dd046" />


This is part of the test data, showing the comparison of loss curves before and after adaptation， include eager and sdpa mode.


> > Thanks for iterating
> > 
> > * Can you look at [#41143 (review)](https://github.com/huggingface/transformers/pull/41143#pullrequestreview-3267237606) --> just want to make sure that `use_gqa` is also supported on npu and if there are any restrictions
> > * And a last comment on the questions from @FightingZhen --> I think one question has been handled, but the other should be addressed imo
> 
> @vasqu I've received question 1. It's currently under internal review with the team, and I will provide an update in the PR once we have a conclusion.

@vasqu `enable_gqa` is not available for Ascend NPU for now, I will try my best to push inner team make it available. Maybe we need to add some code to make func `use_gqa_in_sdpa` return `False` for Ascend NPU @frozenleaves 

> > > Thanks for iterating
> > > 
> > > * Can you look at [#41143 (review)](https://github.com/huggingface/transformers/pull/41143#pullrequestreview-3267237606) --> just want to make sure that `use_gqa` is also supported on npu and if there are any restrictions
> > > * And a last comment on the questions from @FightingZhen --> I think one question has been handled, but the other should be addressed imo
> > 
> > 
> > @vasqu I've received question 1. It's currently under internal review with the team, and I will provide an update in the PR once we have a conclusion.
> 
> @vasqu `enable_gqa` is not available for Ascend NPU for now, I will try my best to push inner team make it available. Maybe we need to add some code to make func `use_gqa_in_sdpa` return `False` for Ascend NPU @frozenleaves

No problem, I've updated the code to make sure that in npu environment `use_gqa_in_sdpa` returns False. Please review this PR again, thanks. @vasqu @FightingZhen 

Looks good, would wait for @FightingZhen if he has any additional comments then merge :hugs: 

> Looks good, would wait for @FightingZhen if he has any additional comments then merge 🤗

@vasqu Codes and comments all LGTM :)

Thanks a lot both of you, merging now (docs building)

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_41143). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.