[Cherry-Pick][Feature] support decode attention for mix(#7688)#7729
[Cherry-Pick][Feature] support decode attention for mix(#7688)#7729lizhenyun01 wants to merge 11 commits intoPaddlePaddle:release/2.6from
Conversation
|
Thanks for your contribution! |
CI报告基于以下代码生成(30分钟更新一次): 1 任务总览❌ 存在 1 个 Required 失败任务需优先处理(Approval 审批检查未通过),另有 8 个 Required 任务因上游依赖被跳过(不阻塞合并)。
2 任务状态汇总2.1 Required任务 : 1/10 通过
2.2 可选任务 — 4/14 通过
3 失败详情(仅 required)Approval — 审批检查(置信度: 高)Approval
根因详情:
关键日志: 修复建议:
修复建议摘要: 请联系所需 RD 对各受保护模块完成审批 链接: 查看日志 |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-07 15:07:05
📋 Review 摘要
PR 概述:Cherry-Pick #7688,为 mix 场景新增 decode attention 支持(C16 fp16/bf16 KV cache 与静态 C8 量化),通过环境变量 USE_DECODE_ATTENTION=1 开启,当前 CUDA kernel 仅在 sm90+(H100/Hopper)平台编译
变更范围:custom_ops/gpu_ops/append_attention/(CUDA kernel)、model_executor/layers/attention/ops/(Python wrapper)、worker/gpu_model_runner.py、spec_decode/mtp.py、tests/operators/attention/
影响面 Tag:[OP] [Feature] [Speculative Decoding] [Metax]
📝 PR 规范检查
标题格式 [Cherry-Pick][Feature] support decode attention for mix(#7688) 符合 Cherry-Pick 规范([Cherry-Pick][Tag] 标题(#原PR号) 格式正确)。但描述中 Modifications、Usage or Command、Accuracy Tests 三段落仅有占位注释,内容为空,需补充。
PR 描述建议(可直接复制):
## Motivation
Cherry-Pick from #7688。为 mix 场景(混合 Prefill+Decode 请求)新增 decode attention 支持,涵盖 C16(fp16/bf16 KV cache)和静态 C8 量化两种 KV cache 格式。在 flash_attn 开启情况下通过环境变量启用,当前仅支持 sm90+(H100/Hopper 及以上)平台。
## Modifications
- 新增 CUDA kernel:`custom_ops/gpu_ops/decode_append_attention.cu`、`decoder_write_cache_with_rope.cu`,以及 `custom_ops/gpu_ops/append_attention/` 下 C8/C16 实现(attention_func.cuh、decode_append_attention_c8_impl.cuh、decode_append_attention_c16_impl.cuh 等)
- 新增 Python wrapper:`fastdeploy/model_executor/layers/attention/ops/decode_append_attention.py`、`config_for_attention.py`、`decoder_write_cache_with_rope.py`
- 在 `fastdeploy/envs.py` 新增 `USE_DECODE_ATTENTION` 环境变量(默认 0,关闭)
- 在 `fastdeploy/worker/gpu_model_runner.py` 和 `metax_model_runner.py` 集成 decode attention buffer 分配与 forward_meta 传入
- 在 `fastdeploy/spec_decode/mtp.py` 增加 decode attention 相关输入透传
- 在 `custom_ops/setup_ops.py` 添加编译入口(仅限 cc>=90/Hopper 及以上)
- 新增测试:`tests/operators/attention/test_decode_append_attention.py`、`test_decode_append_attention_c16.py`、`benchmark_decode_attention.py`
## Usage or Command
在 flash_attn backend 开启情况下,设置如下环境变量启用 decode attention:`export USE_DECODE_ATTENTION=1`(注意:当前编译仅支持 sm90+ Hopper 及以上平台)
## Accuracy Tests
N/A
## 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.
- [x] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [x] 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.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | fastdeploy/spec_decode/mtp.py |
Cherry-Pick 合并后存在两段完全相同的 if 代码块(重复赋值),应清理其中一个 |
| ❓ 疑问 | fastdeploy/worker/metax_model_runner.py |
fix ci 提交删除了 decode buffer 到 forward_meta 的赋值,Metax 平台开启 USE_DECODE_ATTENTION=1 时是否能正确工作? |
| 📝 PR 规范 | PR 描述 | Modifications、Usage or Command、Accuracy Tests 段落内容为空 |
注意:新增 decode attention op 在
setup_ops.py中仅在cc >= 90(Hopper 及以上)条件下编译,A100(sm80)等平台即使设置USE_DECODE_ATTENTION=1也不会加载该 op,建议在文档或描述中注明硬件要求,避免用户困惑。
总体评价
整体实现结构清晰,CUDA kernel、Python wrapper、SM 门控和测试均已配套,Cherry-Pick 格式也正确。主要问题是 cherry-pick 合并后 mtp.py 存在重复代码块需要清理,以及 Metax 平台的 decode buffer 赋值路径需要作者确认。
Motivation
C16/静态C8 attention支持,使用方式:flash_attn开启情况下export USE_DECODE_ATTENTION=1
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.