已合并
QSFA oom bugfix #7676
QSFA oom bugfix #7676
已合并
郑文惠创建于 6月27日
郑文惠
郑文惠成员
6月27日

描述

QSFA oom bugfix

关联的Issue

测试

文档更新

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 郑文惠 的贡献)
郑文惠郑文惠成员
6月27日 创建了 pull request,commit 37c53cc4
CANN-robotCANN-robot成员
6月27日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月27日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
attention zzy__, wangzhe123456789 (2/2) wangzhe123456789, zzy__ (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

zhengwenhui0817, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
郑文惠
郑文惠成员
6月27日 评论:

/compile

likedislike
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: 5f1f3c8506d660f7fa9f2244a09bccb2e9709179] virtual merging success
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [dd6c94b7996b4728a8ba84982e9bce07][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>

[2026-06-27 11:08:35]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [20054282b4c345a9b2414dce20b1e8c0][流水线指导]

任务名称状态日志下载链接
codecheck ❌ FAILED >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ⚠️ WARNING >>>>> >>>>>
likedislike
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: 5659101291d8dec5db5fec33833efb17cb583d18] virtual merging success
郑文惠郑文惠成员
6月27日 强制推送  1 个提交:b8bdb0f4-QSFA oom bugfix
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: ce4459b90cbdb4b6ae93975d303670892a8139c0] virtual merging success
郑文惠
郑文惠成员
6月27日 评论:

/compile

likedislike
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: 41c350afd67294ab811de3461031afdbbd5570a7] virtual merging success
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-failed
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [d900a49d886f460887089f21379aaaca][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-27 11:26:31]    CI执行结束

likedislike
atomgit-bot
atomgit-bot
6月27日 评论:

变更摘要

此 PR 修复了 QSFA(KV 量化稀疏 Flash Attention)算子在特定场景下的 OOM(内存溢出)问题。核心变更涉及 CopyInSingleKv 函数的接口调整与 combineBytes 计算方式的修正:将原来硬编码的 combineBytes = 672 改为由调用方通过参数传入,并将调用方中 combineBytes 的取值从 constInfo.dSizeVInput 修正为 constInfo.dSizeVInput * sizeof(KV_T),确保字节数计算正确,避免因内存分配或数据搬运长度异常导致的 OOM。

主要改动

  • CopyInSingleKv 函数签名变更: 新增 uint32_t combineBytes 参数,替换原来函数内部硬编码的 uint32_t combineBytes = 672;,使数据搬运长度由调用方动态决定而非固定常量。
  • combineBytes 计算修正: 在调用 CopyInSingleKv 的上层函数中,将 combineBytes 的计算从 constInfo.dSizeVInput 改为 constInfo.dSizeVInput * sizeof(KV_T),把元素个数正确转换为字节数。
  • CopyInSingleKv 调用点适配: 两处回退分支的 CopyInSingleKv 调用均补充了 combineBytes 实参传入,确保异常场景下也使用正确的外部传入值。
likedislike
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [764d6ed8d2c046889a7ba39d265caf03][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-06-27 11:12:10]    CI执行结束

likedislike
atomgit-bot
atomgit-bot
6月27日 评论:

代码审查

总结

本次 diff 共审查 1 个文件,发现 2 个问题

优先级 数量 说明
P2 1 keySrcStride 计算缺少 * sizeof(KV_T) 乘法,单位不一致
P3 1 combineBytes 类型 uint32_t 可能导致未来维度增大时的截断风险(可选改进)

整体风险评估:中等风险。核心修复(移除硬编码 672、参数化 combineBytes)是正确的,解决了 CopyInSingleKvCopyInKvSparse 之间 combineBytes 不一致导致的 OOM 问题。但在 CopyInKvSparsekeySrcStride 计算中,combineBytes 改为字节单位后,keyOffset 差值未同步乘以 sizeof(KV_T) 转换为字节,导致在 sizeof(KV_T) > 1 且稀疏索引非相邻时可能使用错误的源地址进行数据拷贝。

已审查文件

  • attention/kv_quant_sparse_flash_attention/op_kernel/arch35/kv_quant_sparse_flash_attention_service_vector_mla.h:发现 2 个问题(见上述)
类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
atomgit-bot
atomgit-bot6月27日进行代码检视2
attention/kv_quant_sparse_flash_attention/op_kernel/arch35/kv_quant_sparse_flash_attention_service_vector_mla.h
@@ -244,3 +245,3 @@
244245 return 0;
245246 }
246- uint32_t combineBytes = constInfo.dSizeVInput;
247+ uint32_t combineBytes = constInfo.dSizeVInput * sizeof(KV_T);
atomgit-bot
atomgit-bot6月27日评论:

🟡 Medium Priority

变更行 245 将 combineBytes 从元素数改为字节数(constInfo.dSizeVInput * sizeof(KV_T)),但行 246-247 的 keySrcStride 计算公式未同步调整:

uint32_t combineBytes = constInfo.dSizeVInput * sizeof(KV_T); // 字节
int64_t keySrcStride = abs(keyOffset0 - keyOffset1) - combineBytes; // 元素 - 字节 = 单位混乱

keyOffset0/keyOffset1GetkeyOffset 返回,是元素偏移量(见行 205:(boIdx * s2Size + s2Idx) * dSizeVInput),而 combineBytes 已是字节。两者直接相减导致单位不一致。

对于 sizeof(KV_T) > 1(如 bf16/fp32):

对比 sparse_flash_mla/op_kernel/arch35/sparse_flash_mla_scfa_block_vector.h 第 305 行的平行代码,已正确使用 * sizeof(KV_T)
int64_t keySrcStride = (keyOffset0 > keyOffset1 ?
(keyOffset0 - keyOffset1) : (keyOffset1 - keyOffset0)) * sizeof(KV_T) - combineBytes;

触发条件:sizeof(KV_T) > 1 且稀疏索引中相邻两个 token 在 KV cache 中的偏移差 ≥ 3 倍 dSizeVInput

建议:在 keyOffset 差值上乘以 sizeof(KV_T) 使其单位转换为字节,与 combineBytes 保持一致。参照 sparse_flash_mla 中的平行实现修复。

likedislike
郑文惠
郑文惠成员
6月27日 评论:

已修改

CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-passed
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: 2264e9c72990ee1aaa1962fcafe42fbe572e151e] virtual merging success
郑文惠郑文惠成员
6月27日 强制推送  1 个提交:d9324f4f-QSFA oom bugfix
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: ea21a96fe833771ae23a81efa4a548ae18a8fe2f] virtual merging success
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
6月27日 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
郑文惠
郑文惠成员
6月27日 评论:

/compile

likedislike
郑文惠郑文惠成员
6月27日 update merge request[project id: 7673863, iid: 7676, commit_id: 9b8db93a35ee6ccf439fbbf71d1e3e7ad8676ddc] virtual merging success
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [9f584131242d49b9aa840b746bd0ad0a][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-27 11:47:00]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [831af2238e06435eb5adaf556eefd0e2][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-06-27 11:35:05]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-passed
郑文惠
郑文惠成员
6月27日 评论:

/compile

likedislike
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-passed
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [6601e2ce213d43f69ac4c5060fde655b][流水线指导]

任务名称状态日志下载链接
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_experimental_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_experimental_950 ✅ SUCCESS >>>>> >>>>>
UT_Test ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-06-27 14:14:30]    CI执行结束

likedislike
郑文惠郑文惠成员
6月27日 解决了最后一个问题
CANN-robot
CANN-robot成员
6月27日 评论:

流水线任务触发成功
任务链接 [4144307e036d4bf6b39a58f496277d4c][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
codecheck_style ✅ SUCCESS >>>>>
StaticCheck_codespell_check ✅ SUCCESS
StaticCheck_link_validity_check ✅ SUCCESS
StaticCheck_resource_existence_check ✅ SUCCESS
StaticCheck_tag_closed_check ✅ SUCCESS
StaticCheck_markdownlint ✅ SUCCESS
codecheck_checkpr ✅ SUCCESS
codecheck_precommit ⚠️ WARNING >>>>> >>>>>

[2026-06-27 13:59:47]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6月27日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月27日 添加了label:ci-pipeline-passed
wangzhe123456789成员
6月27日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月27日 添加了label:approved
赵志勇成员
6月27日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
6月27日 添加了label:lgtm
CANN-robotCANN-robot成员
6月27日 合入了pull request