Skip to content

[BugFix] Check optional params before .get() call in gqa_rope_write_cache#7311

Merged
Jiang-Jia-Jun merged 2 commits intoPaddlePaddle:release/2.5from
K11OntheBoat:R25_Bzz3_GQAWrite
Apr 13, 2026
Merged

[BugFix] Check optional params before .get() call in gqa_rope_write_cache#7311
Jiang-Jia-Jun merged 2 commits intoPaddlePaddle:release/2.5from
K11OntheBoat:R25_Bzz3_GQAWrite

Conversation

@K11OntheBoat
Copy link
Copy Markdown
Collaborator

@K11OntheBoat K11OntheBoat commented Apr 10, 2026

Motivation

在gqa_rope_write_cache中, 存在针对 为空的optional tensor 使用.get()方法的情况;导致Paddle框架Assert错误:
python: paddle/include/paddle/utils/optional.h:563: paddle::optional::reference_const_type paddle::optional::get() const [with T = paddle::Tensor; reference_const_type = const paddle::Tensor&]: Assertion `this->is_initialized()' failed.”

Modifications

此PR采用更标准的C++写法,用指针表示可选参数, 不存在的Optional不使用 .get()方法,参数用nullptr向下传入的方法,可以修复此Assertion报错.

Note:

K11OntheBoat@2eea6fa 此PR給dev和2.6提了,规避了本PR处理的bug,但是那个PR并没提给2.5; 所以本PR专給2.5修复Bug使用

@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 10, 2026

Thanks for your contribution!

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 10, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Jiang-Jia-Jun
❌ K11OntheBoat


K11OntheBoat seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@paddle-bot paddle-bot bot added the contributor External developers label Apr 10, 2026
PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 10, 2026

Codecov Report

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

Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.5    #7311   +/-   ##
==============================================
  Coverage               ?   69.62%           
==============================================
  Files                  ?      390           
  Lines                  ?    54376           
  Branches               ?     8577           
==============================================
  Hits                   ?    37859           
  Misses                 ?    13805           
  Partials               ?     2712           
Flag Coverage Δ
GPU 69.62% <ø> (?)

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.

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

📋 Review 摘要

PR 概述:修复 gqa_rope_write_cache 中 optional tensor 为空时调用 .get() 导致的断言错误,将参数从引用改为指针方式处理。

变更范围:custom_ops/gpu_ops/append_attn/

影响面 Tag[BugFix] [OP]

📝 PR 规范检查

✅ PR 标题包含有效的 [BugFix] 标签
✅ PR 描述完整,包含 Motivation 和 Modifications

问题

级别 文件 概述
🔴 Bug custom_ops/gpu_ops/append_attn/gqa_rope_write_cache.cu:1240 cache_int8/fp8 分支缺少空指针检查
🔴 Bug custom_ops/gpu_ops/append_attn/gqa_rope_write_cache.cu:1276 cache_int4_zp 分支缺少空指针检查

总体评价

PR 的修复方向正确,将参数类型改为指针允许传递 nullptr。但 AppendCacheKV 函数内部在解引用指针前缺少防御性检查,如果 cache_quant_type 需要某参数但传入的是 nullptr,会导致空指针解引用崩溃而非清晰的错误提示。建议添加断言或参数有效性检查。

Comment thread custom_ops/gpu_ops/append_attn/gqa_rope_write_cache.cu
Comment thread custom_ops/gpu_ops/append_attn/gqa_rope_write_cache.cu
Copy link
Copy Markdown
Collaborator

@zoooo0820 zoooo0820 left a comment

Choose a reason for hiding this comment

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

LGTM

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit 10a5e1c into PaddlePaddle:release/2.5 Apr 13, 2026
6 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants