feat: adapt flash attention to Ascend backend#1401
Open
Jingbo-gao wants to merge 3 commits into
Open
Conversation
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.
PR内容:添加昇腾flash attention特性适配
python/infinicore/ops/ascend_flash_attn.py:新增基于 torch_npu 的 Ascend paged FlashAttention prefill/decode Python 封装;
src/infinicore/ops/mha_kvcache/mha_kvcache_flashattn.cc:将 Ascend decode 请求隔离出通用 CUDA FlashAttention 路径并交由专用实现处理;
src/infinicore/ops/mha_kvcache/mha_kvcache_flashattn_ascend.cc:新增基于 aclnnFusedInferAttentionScoreV4 的 Ascend paged decode 实现,支持 BNSD Query 和 BnBsH KV cache;
src/infinicore/ops/multi_head_attention_varlen/mha_varlen_flashattn.cc:将 Ascend varlen 请求路由到专用实现,同时保留其他后端原有 ATen、FlashAttention 和 SDPA 行为;
src/infinicore/ops/multi_head_attention_varlen/mha_varlen_flashattn_ascend.cc:新增基于 FIA V4 的 Ascend TND varlen prefill 实现,支持 paged KV cache、累计序列长度和因果掩码;
src/infiniop/ops/flash_attention/operator.cc:新增 Ascend FlashAttention descriptor 的设备分发入口;
ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python examples/bench.py --device ascend --model=/workspace/models/FM9G_70B_SFT_MHA/ --tp=8 --input-len=32 --output-len=256 --batch-size=16 --enable-paged-attn --attn=flash-attn --enable-graph