[OP] Support MLA sliding-window attention#8060
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #8060 +/- ##
==========================================
Coverage ? 67.24%
==========================================
Files ? 475
Lines ? 66867
Branches ? 10312
==========================================
Hits ? 44968
Misses ? 19024
Partials ? 2875
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 — PR问题(置信度: 高)错误类型: PR问题 | 置信度: 高
关键日志:
本次失败不是单测断言失败或 CI 环境异常: 未覆盖代码集中在本 PR 的核心变更: 修复建议:
关联变更: |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-06-17 14:42:51
📋 Review 摘要
PR 概述:为 DeepSeek V3 MLA attention 增加 SWA static attention 路径,并调整 MLA/SWA KV cache 形状与 dtype。
变更范围:deepseek_v3.py、layers/attention/*、gpu_model_runner.py、相关 KV cache 单测。
影响面 Tag:[Models] [OP] [KVCache]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | fastdeploy/model_executor/models/deepseek_v3.py:143 |
SWA indexer 硬编码 64 作为 page size,非默认 --block-size 下会读错 KV cache 位置 |
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | SWA prefill 路径没有读取 prefix/chunked prefill 的历史 KV。 | |
| F2 | layer_id 和 SWA uint8 cache dtype 只在非 V1 cache 初始化路径生效。 |
📝 PR 规范检查
已修复:标题已包含官方 [OP] Tag,PR 描述也已补齐 Motivation / Modifications / Usage or Command / Accuracy Tests / Checklist 结构。
总体评价
当前实现仍有一个会导致非默认 block size 下 SWA decode 访问错误 KV cache 的阻塞问题,需要在合入前修复。另有两条历史 finding 在当前 diff 中仍未解决,本轮未重复发 inline comment。
| batch_id_per_token, | ||
| max_page_per_seq=block_tables.shape[1], | ||
| window_size=indexer_top_k.shape[2], | ||
| page_size=64, |
There was a problem hiding this comment.
🔴 Bug 这里把 SWA indexer 的 page_size 固定为 64,但 KV block size 是可配置的 cache_config.block_size。
当前 block_tables 的页号按实际 block size 分配,其他 cache 读写路径也使用 self.block_size。当用户通过 --block-size 配置为非 64 时,这里的 idx // 64 和 idx % 64 会生成错误的物理 token id,decode SWA 会从错误 cache 位置取 KV,直接导致 attention 结果错误。
建议把 block_size 作为参数从 DeepseekV3MLAAttention.forward_swa_static() 传入 get_swa_indexer_top_k(),并在 kernel launch 中使用该值作为 page_size,不要硬编码 64。
EmmonsCurse
left a comment
There was a problem hiding this comment.
LGTM~ Skip coverage check as it mainly relies on end-to-end tests.
Motivation
为 DeepSeek V3 MLA attention 增加 sliding-window attention (SWA) 支持,并复用 DSA/FlashMLA static attention 路径以降低 SWA 层 KV cache 开销。
Modifications
forward_swa_static路径。DSAAttentionBackend的 mixed attention 逻辑拆出forward_static,供 MLA SWA 路径复用。window_attn_skip_freq为 MLA SWA 层使用 packed fp8 key cache shape,并在 GPU cache 初始化中为 SWA 层创建uint8cache。test_dsa_attention_backend.py并保留 MLA KV cache 单测。Usage or Command
N/A
Accuracy Tests
N/A
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.