[Optim] FlashMask-4 Overlap support part 1 (NVSHMEM backend) by Enigmatisms · Pull Request #166 · PaddlePaddle/flash-attention · GitHub
Skip to content

[Optim] FlashMask-4 Overlap support part 1 (NVSHMEM backend) - #166

Merged
GuoxiaWang merged 1 commit into
PaddlePaddle:mainfrom
Enigmatisms:overlap_fmv4
Jul 24, 2026
Merged

GuoxiaWang merged 1 commit into
PaddlePaddle:mainfrom
Enigmatisms:overlap_fmv4

Conversation

@Enigmatisms

Copy link
Copy Markdown

FM-4 Overlap 支持第一阶段,将 FM-3 已经大量测试的 overlap 组件通过轻量的 bridge 方式引入 FM-4。
FM-4 端的主要改动在 interface.py,尤其是 bwd,需要适配 multi-stage AG & RS overlap 的 orchestration。

part 1 只支持 NVSHMEM 作为 backend,故在后续封装 Fleet 端 PyLayer 时会限制 EP group 不跨机下才能使用 Overlap。EP 跨机会导致 NVSHMEM 通信单例冲突,出现 hang 或者 core dump。此前已经论证了 NVSHMEM 共用没有简单而不 hacky 的解法。

本 PR 支持并实现了:

  • RS & AG multi-stage bwd overlap
  • AG fwd overlap
  • FM-3 overlap bridge
  • Overlap 分层通信
  • Overlap BHSD layout 通信

只有在 FM-4 安装时带 ovl(或者 all)情况下,overlap 组件才会被编译。由于 overlap 组件强依赖手写的 CUDA kernel,编译肯定是没办法避免的,overlap 组件编译时间并不短(通常2~3min)。但相比 FM-3 还是好很多。

另外,interface.py 做了这样的一个接口小改动:将所有的 non keyword arguments 转为了 keyword args 的写法。考虑到 FM-4 的 API 形参列表可能会发生变动,一旦在列表非尾部位置增加了一个参数,原始写法如果不注意将很容易导致大量参数错位。

- RS & AG multi-stage bwd overlap
- AG fwd overlap
- FM-3 overlap bridge

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

为啥叫block_seqlen_k

block_bos is None,
) + (
# SRBuffer K/V require a distinct artifact only when overlap is active.
(overlap_bhsd_layout, overlap_kv_chunk_size) if enable_overlap else ()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

overlap_view.shape 不需要加到compile key里吗

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

这些raw_参数是什么意思?为什么要加一个raw_前缀?

@GuoxiaWang
GuoxiaWang merged commit 1599ddc into PaddlePaddle:main Jul 24, 2026
1 check passed
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.

4 participants