feat: Flash Attention - #193
Open
Chamberlain0w0 wants to merge 4 commits into
Open
Conversation
Chamberlain0w0
force-pushed
the
feat/flash_attn
branch
from
July 31, 2026 01:29
a359785 to
cf12475
Compare
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.
背景
当前 unfused causal attention 会显式生成完整的
T x Tattention score。该 PR 为 InfiniTrain 接入 FlashAttention 2 native CUDA backend,并适配最新的统一 MHA/GQA Forward 路径。实现直接调用 FlashAttention CUDA kernels,在 CMakeLists 中不依赖 PyTorch extension,不链接 Torch、ATen、c10 或 Python runtime。主要改动
FlashAttention native backend
v2.7.4.post1。flash_attn_native静态库和USE_FLASH_ATTENTIONCMake 开关。src/kernels/cuda/flash_attention_compat,满足上游 kernel headers 中残留的 Philox 和 CUDA 检查接口,无需链接 Torch。Framework 与 autograd
nn::function::ScaledDotProductAttention(q, k, v, scale),以及对应 autograd Function 和 CUDA dispatcher kernels。Dispatcher::HasKernel检查 flash attn 的 backend availability。Hq == Hkv:MHAHq % Hkv == 0:GQA/MQATransformer 接入
--attention_backend=unfused|flash。CausalSelfAttention::Forward;unfused GQA 继续通过RepeatKV展开 K/V;Flash 保留原始 KV heads,交由 kernel 来处理。Splitautograd node;不等宽 GQA 使用Slice。TransformerConfig::flash。测试与文档
test_flash_attention_cuda。scripts/test_config.json中增加flash测试组,覆盖 GPT-2/LLaMA3 的多组 batch/sequence shapes。docs/flash_attn_integration_design.md,记录架构、构建方式、支持矩阵和已知技术债。TODO
暂不支持:
start_pos当前 Transformer Flash 路径会忽略已解析的 mask/start_pos,并固定使用 kernel 内建 causal mask。