[Cherry-Pick][OP][RL]update attn_mask_q(#7371)#7373
Conversation
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-13 21:32 CST
📋 Review 摘要
PR 概述:优化 get_attn_mask_q 算子,将输出张量维度从 4 减少到 2,节省内存占用
变更范围:custom_ops/gpu_ops/get_attn_mask_q.cu
影响面 Tag:[OP]
📝 PR 规范检查
PR 标题格式正确,但描述部分未填写完整,建议补充:
Motivation(示例):
优化内存使用:原实现中
startend_row_vec数组有 2 个元素未被实际使用,将数组大小从 4 减少到 2,可降低约 50% 的输出张量内存占用。
Modifications(示例):
- 将
startend_row_vec数组大小从 4 改为 2- 移除未使用的数组元素
[1]和[2]的赋值- 将输出张量 shape 从
{1, 1, kv_token_num, 4}改为{1, 1, kv_token_num, 2}- 将
int4*类型转换改为int2*以匹配新的数组大小
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | custom_ops/gpu_ops/get_attn_mask_q.cu:25 |
VecSize 常量定义但未使用 |
| 🟡 建议 | custom_ops/gpu_ops/get_attn_mask_q.cu:52 |
遗留被注释的代码 |
总体评价
变更逻辑正确,是一个合理的内存优化。测试覆盖充分(FA2/FA3/FA4 端到端测试)。代码中遗留了一些无用的常量和注释代码,建议一并清理。
| @@ -24,7 +24,7 @@ __global__ void get_attn_mask_q_kernel( | |||
| const int max_batch_size) { | |||
| constexpr int VecSize = 4; | |||
There was a problem hiding this comment.
🟡 建议 VecSize 常量在第 25 行定义但从未使用,建议移除以保持代码整洁。
| startend_row_vec[1] = cu_seqlens_q[max_batch_size]; | ||
| startend_row_vec[2] = 0; | ||
| startend_row_vec[3] = this_batch_q_end; | ||
| // startend_row_vec[1] = cu_seqlens_q[max_batch_size]; |
There was a problem hiding this comment.
🟡 建议 被注释的代码(第 52-53 行)可考虑移除,因为它们反映了之前的实现且已不再使用。
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/2.6 #7373 +/- ##
==============================================
Coverage ? 73.72%
==============================================
Files ? 376
Lines ? 52968
Branches ? 8271
==============================================
Hits ? 39052
Misses ? 11184
Partials ? 2732
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.