Pull Request已成功合入, 合并人@CANN-robot
(感谢 郑文惠 的贡献)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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


/compile


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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 | >>>>> | >>>>> |


/compile


流水线任务触发成功
任务链接 [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执行结束


变更摘要
此 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实参传入,确保异常场景下也使用正确的外部传入值。


流水线任务触发成功
任务链接 [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执行结束


代码审查
总结
本次 diff 共审查 1 个文件,发现 2 个问题:
| 优先级 | 数量 | 说明 |
|---|---|---|
| P2 | 1 | keySrcStride 计算缺少 * sizeof(KV_T) 乘法,单位不一致 |
| P3 | 1 | combineBytes 类型 uint32_t 可能导致未来维度增大时的截断风险(可选改进) |
整体风险评估:中等风险。核心修复(移除硬编码 672、参数化 combineBytes)是正确的,解决了 CopyInSingleKv 与 CopyInKvSparse 之间 combineBytes 不一致导致的 OOM 问题。但在 CopyInKvSparse 的 keySrcStride 计算中,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 |
💬 仅评论


🟡 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/keyOffset1 由 GetkeyOffset 返回,是元素偏移量(见行 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 中的平行实现修复。


/compile


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


/compile


流水线任务触发成功
任务链接 [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执行结束


流水线任务触发成功
任务链接 [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执行结束


/lgtm
/approve


描述
QSFA oom bugfix
关联的Issue
测试
文档更新
类型标签