Skip to content

Commit 170b270

Browse files
committed
Fixes #40262
1 parent 7dbc054 commit 170b270

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/transformers/modeling_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,11 @@ def _flash_attn_2_can_dispatch(self, is_init_check: bool = False) -> bool:
24832483
if not is_flash_attn_2_available():
24842484
preface = "FlashAttention2 has been toggled on, but it cannot be used due to the following error:"
24852485
install_message = "Please refer to the documentation of https://huggingface.co/docs/transformers/perf_infer_gpu_one#flashattention-2 to install Flash Attention 2."
2486+
2487+
# package `flash-attn` can not be installed on Ascend NPU, following validation logics can be ignored.
2488+
if is_torch_npu_available():
2489+
logger.info("Detect using FlashAttention2 on Ascend NPU.")
2490+
return True
24862491

24872492
# package `flash-attn` can not be installed on Ascend NPU, ignore related validation logi
24882493
if importlib.util.find_spec("flash_attn") is None and not is_torch_npu_available():

0 commit comments

Comments
 (0)