Skip to content

Support attn sink in fa3#1415

Open
starcrown001 wants to merge 4 commits into
PaddlePaddle:developfrom
starcrown001:xhy/sink_attn
Open

Support attn sink in fa3#1415
starcrown001 wants to merge 4 commits into
PaddlePaddle:developfrom
starcrown001:xhy/sink_attn

Conversation

@starcrown001

Copy link
Copy Markdown

PR Category

Operator Mechanism

PR Types

New features

Description

新增 FA3 attention sink 实现,并在 DotProductAttention 的 SDPA/FlashMask 路径中按条件分发到 FA3 sink 分支

是否引起精度变化

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已完成初轮审查,发现需要先修复的阻塞问题。具体问题已放在行级评论中,主要涉及新增 FA3 sink 模块的导入可靠性、训练时 attention dropout 语义,以及 FA3 FlashMask 反向的 Paddle 版本兼容性。

CI 当前通过,但这些路径依赖特定设备/配置,建议修复后补充对应覆盖。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread src/paddlefleet/transformer/sink_impl.py Outdated
Comment thread src/paddlefleet/transformer/sink_impl.py Outdated
Comment thread src/paddlefleet/transformer/sink_impl.py
PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮我指出的导入保护、FA3 dense dropout 显式拒绝、以及 FlashMask v2 grad 签名兼容性在当前代码里看起来已经修复;不过当前账号没有权限关闭已有 review 线程。

这轮发现 FA3 FlashMask/startend 分支的非零 dropout 仍会进入自定义 PyLayer,但 backward 没有对应 dropout 状态,详细说明已放在新的行级评论中。该问题建议合入前修复。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread src/paddlefleet/transformer/sink_impl.py
PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮我指出的 FA3 FlashMask/startend 训练期非零 attention_dropout 问题已通过显式 guard 修复,本轮没有新增 Nyanpasu 行级评论。

当前仍有独立的 KV-cache decode 风险由已有行级讨论覆盖,我没有重复开新线程;请以该现有讨论继续处理。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。Nyanpasu 之前提出的导入保护、FA3 grad 签名兼容和两处 dropout 静默语义问题在当前代码中已处理;但这轮发现两个仍需要修复后再合入的问题,细节已放在行级评论中。

请针对 P1 评论提交新的修复 commit;CI 当前通过,但这些路径需要对应回归测试覆盖。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread src/paddlefleet/transformer/sink_impl.py
Comment thread src/paddlefleet/transformer/sink_impl.py

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮 Nyanpasu 提出的 KV-cache decode fallback 和 additive dense mask 解析两个 P1 问题,在当前代码中均已通过新 commit 修复,并补充了对应回归覆盖。

本轮未发现新的需要阻塞合入的问题;CI 当前通过。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。本次变更只移除了 FA3 sink 实现中的调试注释,不改变已检查过的 fallback、mask 解析或 backward 逻辑。

上轮 Nyanpasu 已确认修复的 P1 问题在当前 head 仍保持修复状态;本轮未发现新的需要阻塞合入的问题,CI 当前通过。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。此前 Nyanpasu 提出的 additive mask 解析问题仍保持修复状态,但当前 KV-cache decode fallback 会在启用 attention sink 时静默退回到不带 sink 的 SDPA,导致 prefill/decode 语义不一致;我已在行级评论中给出需要修复的位置和建议方向。

请针对 P1 评论提交新的修复 commit 后再继续复查。CI 当前通过,但该路径还需要对应的 decode 语义覆盖。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread src/paddlefleet/transformer/sink_impl.py Outdated
PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮指出的 KV-cache decode 静默丢 sink 已改为显式拒绝,方向是对的;但当前测试仍断言旧的 fallback 行为,且 FA3 sink 的 value head_dim padding 还缺少 v_head_dim > q_head_dim 边界处理。

新的 P1 问题已放在行级评论中,请提交修复 commit 后再复查。CI 当前通过,但这些路径需要对应覆盖保持一致。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread tests/single_card_tests/transformer/test_flash_mask_sink.py Outdated
Comment thread src/paddlefleet/transformer/sink_impl.py

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮 Nyanpasu 提出的测试旧 fallback 断言和 v_head_dim > q_head_dim 边界问题,当前都已通过新 commit 修复,并补充了对应覆盖。

本轮未发现新的需要阻塞合入的问题;CI 当前通过。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@Paddle-CI-Bot

Paddle-CI-Bot commented Jul 14, 2026

Copy link
Copy Markdown

PaddleFleet Log Analysis

Run #29322564074 · Attempt 1

日志分析报告

流水线名称 问题标签 修复建议 日志片段
Unit test (single card) 单测断言失败 — 错误类型/消息不符预期 sink_impl.py 的 FA3 learnable sink 路径中,当 v_channels != qk_channels 时提前抛出 ValueError("requires value head_dim to match query/key head_dim"),不要让 Paddle 底层先触发 padding 越界 报错代码
Coverage Upload And Check 增量覆盖率不达标 (exit 9) src/paddlefleet/transformer/sink_impl.py 的 137 条未覆盖行补充单测 报错代码

失败的测试case:

tests/single_card_tests/transformer/test_flash_mask_sink.py::TestDotProductAttentionFA3SinkForward::test_forward_learnable_sink_value_head_dim_larger_raises

根本原因分析:

PR #1415 新增了 FA3 attention sink 实现(sink_impl.py +961 行)。测试用例 test_forward_learnable_sink_value_head_dim_larger_raises 期望当 v_dim > qk_dim(192 vs 128)时,DotProductAttention 抛出包含 "requires value head_dim to match query/key head_dim"ValueError。然而实际执行路径未在参数校验阶段提前拦截该情况,导致 Paddle 底层 pad 算子先崩溃并抛出 InvalidArgument: paddings[i]:-64 < 0,错误消息不匹配,断言失败。同时,sink_impl.py 新增的 961 行中有大量分支(137 行,占比 44%)未被现有测试覆盖,导致增量覆盖率仅 55%,远低于 90% 阈值,触发 exit 9。

修复建议:

  1. 单测修复:在 sink_impl.py(或 dot_product_attention.py)的 FA3 learnable sink 入口,v_channels != head_dim 时主动 raise:

    if v_channels is not None and v_channels != head_dim:
        raise ValueError(
            "FA3 learnable sink requires value head_dim to match query/key head_dim, "
            f"but got v_channels={v_channels} vs head_dim={head_dim}"
        )

    确保该校验在调用任何 paddle 算子之前执行。

  2. 覆盖率修复sink_impl.py 缺失覆盖的行集中在 FA3 sink 各分支逻辑(如不同 softmax_type、不同序列长度、边界条件等)。在 test_flash_mask_sink.py 中补充针对这些分支的用例,使增量覆盖率 ≥ 90%。可优先覆盖已有 skipped 的用例所对应的代码路径(当前 37 个收集用例中有 23 个被 skip)。


🔍 准确性记录:请点击评论底部 😊 图标,选择 👍(准确)或 👎(有误),将自动记录到 CI 监控系统

🔄 每次 Re-run 后自动更新

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。此前 KV-cache decode 测试旧断言仍保持修复;但 v_head_dim > q_head_dim 的 P1 边界在当前 DotProductAttention padding 条件里重新出现,我已在原有 head_dim 线程补充了当前证据和建议修复形态。

请针对该 P1 推送修复 commit 后再复查。CI 当前通过,但这个路径依赖 FA3/特定 head_dim 配置,现有结果不能覆盖该回归。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。此前 KV-cache decode 测试旧断言仍保持修复,但 v_head_dim > q_head_dim 的 P1 边界还没有被修复;这次提交只调整了相关代码格式,当前两个 padding 分支仍可能在显式 head_dim 拒绝之前进入 q_head_dim - v_head_dim 的错误 padding。

我已在原有 head_dim 讨论中补充当前证据。请针对该 P1 推送修复 commit 后再复查。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

PaddlePaddle-bot

This comment was marked as outdated.

@liuhao2638 liuhao2638 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。此前 KV-cache decode 测试旧断言仍保持修复,但 head_dim padding 的 P1 仍未完成;另外这次提交在标准 SDPA 路径引入了新的未赋值 attn_output 回归,详细位置和建议修复已放在新的行级评论中。

请针对这些 P1 问题推送修复 commit 后再复查。CI 当前通过,但这些路径没有被现有检查覆盖到。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread src/paddlefleet/transformer/dot_product_attention.py
Co-authored-by: liuhao2638 <2284903223@qq.com>

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Paddle-CI-Agent | pr_review | 2026-07-14 16:34:21

📋 Review 摘要

PR 概述:新增 FA3 attention sink 的 1F1B correction 实现,并在 DotProductAttention 中接入 FA3 sink 分支。
变更范围transformer/dot_product_attention.py、新增 transformer/sink_impl.py、FA3/FA4 sink 单卡测试。
影响面 TagTransformer Attention

问题

级别 文件 概述
🟡 建议 src/paddlefleet/transformer/dot_product_attention.py:734 dense/SDPA 场景仍绕过新增 FA3 sink 分发,新增 dense 用例没有覆盖新路径

历史 Findings 修复情况

Finding 问题 状态
F1 runtime 输入校验依赖 assert ⚠️ 仍存在
F2 FA3 sink 分支永远不会被触发 ✅ 已修复
F3 use_startend=False 用例不会覆盖新增 FA3 sink 分支 ⚠️ 仍存在

📝 PR 规范检查

标题缺少规范 Tag;描述已包含 checklist §D2 要求的 PR CategoryPR TypesDescription 且均有内容。

标题建议(可直接复制):

[New features] Support FA3 attention sink

总体评价

FA3 sink 的 FlashMask/startend 路径已经有实际分发和数值测试覆盖;但 dense/SDPA 场景仍停留在旧实现,与 PR 描述和新增测试类名不一致,建议补齐真实分发或收窄声明与测试。

else:
flashmask_attention_func = flashmask_attention

use_fa3_sink, attn_mask_startend_row_indices = (

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 这里的 FA3 sink 分发只在 attn_mask_startend_row_indices is not None 的 FlashMask 分支里执行;当 attn_mask_startend_row_indices=None 时,上面的 SDPA 分支已经直接返回,新增的 sink_attention_forward 不会被调用。

这会导致 PR 描述里的 SDPA/dense 场景仍然走旧的 scaled_dot_product_attention_with_softmax_offsetprepare_fa3_sink_attention 里的 dense mask 转换也没有入口;新增的 dense causal 用例只能验证旧路径能跑,不能覆盖 FA3 sink 分支。

建议修复方式:把 FA3 sink 判定前移到 SDPA 分支内(传入 attention_mask/attn_mask_kv 并在 prepare_fa3_sink_attention 中转换 dense causal/full mask),或抽成两个分支共用的分发逻辑;同时让 dense 用例断言实际调用了 sink_attention_forward

@liuhao2638 liuhao2638 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已复查最新提交。上轮指出的标准 SDPA 路径 attn_output 未赋值问题已经通过新 commit 修复;KV-cache decode 测试旧断言也仍保持修复。

当前仍剩一个 P1:FA3 sink 的 v_head_dim > q_head_dim padding 边界还没有修完,我已在原有 head_dim 讨论中补充当前 head 的证据和建议修复形态。请针对该 P1 推送修复 commit 后再复查。

Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.27832% with 166 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@3cbba1f). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/paddlefleet/transformer/sink_impl.py 45.03% 137 Missing and 29 partials ⚠️

❌ Your patch status has failed because the patch coverage (46.27%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #1415   +/-   ##
==========================================
  Coverage           ?   46.27%           
==========================================
  Files              ?        2           
  Lines              ?      309           
  Branches           ?       74           
==========================================
  Hits               ?      143           
  Misses             ?      137           
  Partials           ?       29           
Flag Coverage Δ
coverage_combine 46.27% <46.27%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...c/paddlefleet/transformer/dot_product_attention.py 100.00% <100.00%> (ø)
src/paddlefleet/transformer/sink_impl.py 45.03% <45.03%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

6 participants