Skip to content

[Cherry-Pick][OP][RL]update attn_mask_q(#7371)#7373

Merged
ckl117 merged 1 commit into
PaddlePaddle:release/2.6from
ckl117:26_attn_mask_q2
Apr 13, 2026
Merged

[Cherry-Pick][OP][RL]update attn_mask_q(#7371)#7373
ckl117 merged 1 commit into
PaddlePaddle:release/2.6from
ckl117:26_attn_mask_q2

Conversation

@ckl117
Copy link
Copy Markdown
Collaborator

@ckl117 ckl117 commented Apr 13, 2026

Motivation

💡 If this PR is a Cherry Pick, the PR title needs to follow the format by adding the [Cherry-Pick] label at the very beginning and appending the original PR ID at the end. For example, [Cherry-Pick][CI] Add check trigger and logic(#5191)

💡 如若此PR是Cherry Pick,PR标题需遵循格式,在最开始加上[Cherry-Pick]标签,以及最后面加上原PR ID,例如[Cherry-Pick][CI] Add check trigger and logic(#5191)

Modifications

Usage or Command

Accuracy Tests

Checklist

  • 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.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented Apr 13, 2026

Thanks for your contribution!

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

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

🤖 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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 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];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 被注释的代码(第 52-53 行)可考虑移除,因为它们反映了之前的实现且已不再使用。

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (release/2.6@9823d63). Learn more about missing BASE report.

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           
Flag Coverage Δ
GPU 73.72% <ø> (?)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckl117 ckl117 merged commit 144dc17 into PaddlePaddle:release/2.6 Apr 13, 2026
34 of 37 checks passed
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.

4 participants