swa#8054
Conversation
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-06-16 14:07:55
📋 Review 摘要
PR 概述:调整 MLA attention baseline 的 causal / sliding-window mask 构造。
变更范围:fastdeploy/model_executor/layers/attention/mla_attention_backend.py
影响面 Tag:[OP]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | fastdeploy/model_executor/layers/attention/mla_attention_backend.py:878 |
SM10 MLA mixed prefill 固定传 window_size=-1,SWA 层仍执行 full attention |
📝 PR 规范检查
PR 标题缺少官方 Tag,描述仍保留模板占位内容且未填写核心章节。建议替换为以下内容。
标题建议(可直接复制):
[OP] Fix MLA baseline SWA mask propagation
PR 描述建议(点击展开,可直接复制)
## Motivation
完善 MLA attention baseline 在 mixed prefill / prefix cache 场景下的 causal/SWA mask 构造,避免 cached KV 与当前 query 长度不一致时 mask 语义错误。
## Modifications
- 在 `MLAAttentionBackend.mha_baseline` 中新增 `window_size` 参数。
- 按 `kv_len - q_len + i + 1` 计算当前 query 可见的 KV 边界,并在 `window_size > 0` 时限制可见窗口。
- SM10 mixed prefill 分支调用 `mha_baseline` 时补充 `window_size` 形参。
## Usage or Command
N/A
## Accuracy Tests
N/A(当前 PR 未提供精度结果)
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.总体评价
代码变更方向是修正 MLA baseline mask,但调用点没有传递已有 SWA 层窗口,会让新增逻辑在目标场景失效。请先修复该语义传递;规范问题也需补齐。
| forward_meta.cu_seqlens_q, | ||
| forward_meta.cu_seqlens_k, | ||
| causal=self.causal, | ||
| window_size=-1, |
There was a problem hiding this comment.
🔴 Bug 这里把 window_size 固定为 -1,导致新增的 SWA mask 分支不会在唯一调用点生效。
Attention 层已经在 layer_types == "sliding_attention" 时保存了 layer.sliding_window,append_attn_backend 也会把正的 sliding_window 传给 attention kernel;但 SM10 的 MLA mixed prefill 会走这个 mha_baseline 分支,当前固定 -1 后即使该层是 sliding attention,也会执行 full causal attention,输出语义和 SWA 配置不一致。
建议修复方式:在调用前按现有 attention 约定计算当前层窗口,例如 sliding 层传 layer.sliding_window(或与 append backend 一致地优先使用 backend/model 级 self.sliding_window),非 sliding 层传 -1/0 表示 full attention,并补充 kv_len > q_len 的 mixed prefill + SWA 对齐测试。
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8054 +/- ##
==========================================
Coverage ? 67.50%
==========================================
Files ? 475
Lines ? 66660
Branches ? 10284
==========================================
Hits ? 45000
Misses ? 18789
Partials ? 2871
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
CI报告基于以下代码生成(30分钟更新一次): 1 Required任务 : 9/10 通过
2 失败详情🔴 Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — 环境问题(置信度: 高)分析器: 通用分析(fallback) 失败用例:
关键日志:
主测试任务中 420 个 pytest 文件成功 419 个,唯一失败文件是 本 PR 只修改 修复建议:
关联变更: |
Motivation
Modifications
Usage or Command
Accuracy Tests
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.