已合并
qbmm算子,x2 input, 外轴大于65536,weightnz场景,部分case有精度问题 #7301
liyuanqiang创建于 7月9日
qbmm算子,x2 input, 外轴大于65536,weightnz场景,部分case有精度问题 #7301
已合并
liyuanqiang创建于 7月9日
liyuanqiang成员
7月9日

描述

关联的Issue

#issue: #3847

测试

文档更新

类型标签

AI/Agent生成声明

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 liyuanqiang 的贡献)
Lliyuanqiang成员
7月9日 创建了 pull request,commit 824730cb
Lliyuanqiang成员
7月9日 关联了issue:[Bug-Report|缺陷反馈]: qbmm算子,x2 input, 外轴大于65536,weightnz场景,部分case有精度问题
atomgit-bot
atomgit-bot
7月9日 评论:

变更摘要

此 PR 修复了 quant_batch_matmul_v3 算子在 transA 且权重为 FRACTAL_NZ 格式时的精度问题。核心改动集中在三个方面:在 Tiling 阶段引入 CapBaseNForATransWeightNzbaseN 限制在 32 以内,以匹配 Cube 指令的 N 维度获取步长;在多个 Kernel 实现中修正了 NZ 格式下 B 矩阵的偏移量计算(移除不必要的 Align(nOffset, K0_INT8) 对齐),并新增 SetMatmulOrgShape 函数为不同格式组合正确设置矩阵乘法的原始形状参数。

主要改动

  • 新增 CapBaseNForATransWeightNz Tiling 约束:在 QuantBatchMatmulV3BasicTiling 中,当 transA && !transB 且权重为 FORMAT_FRACTAL_NZ 时,若 baseN > 32 则将其截断为 32(ONE_BLK_SIZE),并重新计算 usedCoreNumbaseK,防止 Cube 指令因 N 步长过大导致精度异常。

  • 修正 B 矩阵 NZ 格式偏移量计算:在 quant_batch_matmul_v3_bf16.hquant_batch_matmul_v3_bf16_opt.hquant_batch_matmul_v3_pertoken.hquant_batch_matmul_v3_pertoken_opt.h 中,将非转置 NZ 格式的列偏移从 Align(nOffset, K0_INT8) * Align(k_, BMM_BLOCK_NUM) 统一修正为 nOffset * Align(k_, BMM_BLOCK_NUM),因为 n1,k1,k0,n0 布局的列步幅应基于 k 对齐而非 n 对齐。

  • 新增 SetMatmulOrgShape 函数:在 quant_batch_matmul_v3_pertoken.hquant_batch_matmul_v3_pertoken_basic.hquant_batch_matmul_v3_pertoken_opt.h 中,根据特征图/权重是否均为 NZ 格式、仅一侧为 NZ 格式、或均为普通 ND 格式,为 mm.SetOrgShape 传入正确的对齐后维度参数,确保矩阵乘法指令准确理解数据布局。

  • 区分 NZ 格式的 alignedKbSize 计算:在 quant_batch_matmul_v3_update.hInit 中,为非转置且 x2Format 为 NZ 格式的情况显式添加分支,保持其 alignedKbSize 基于 BMM_BLOCK_NUM 对齐,与普通 ND 格式逻辑一致但代码结构更清晰。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月9日 评论:

代码审查

发现 6 个问题,均为中低优先级建议。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
不准确?
CANN-robotCANN-robot成员
7月9日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月9日 评论:

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
** gcw_kUomxQ2l, 陈琦, 刘波 (3/2) gcw_kUomxQ2l (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
liyuanqiang成员
7月9日 评论:

compile

likedislike
Lliyuanqiang成员
7月9日 update merge request[project id: 7665709, iid: 7301, commit_id: 39d46db07f7cf7cea6ac10b872bb2dfc2fca9075] virtual merging success
CANN-robotCANN-robot成员
7月9日 将crystalhu,yangyang016,fanqirui,chenqi317,liubo75,tangweiwei2,gitcode-chenjiao,gcw_kUomxQ2l,Andy-lb设为评审人
CANN-robotCANN-robot成员
7月9日 将gitcode-chenjiao,gcw_kUomxQ2l,Andy-lb设为审查人
CANN-robotCANN-robot成员
7月9日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月9日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer-chs-nn ✅ SUCCESS >>>>>
Compile_harmony-infer-chs-nn-1 ✅ SUCCESS >>>>>
UT_Test_ophost ❌ FAILED
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
likedislike
Lliyuanqiang成员
7月9日 修改标题为 “qbmm算子,x2 input, 外轴大于65536,weightnz场景,部分case有精度问题”,原标题为“qbmm accuracy issues”
CANN-robot
CANN-robot成员
7月9日 评论:

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

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

[2026-07-09 18:43:37]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月9日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月9日 添加了label:ci-pipeline-failed
唐超成员
7月9日 评论:

/lgtm
/approve

likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
唐超

likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

The following users do not have permission to comment /lgtm or /approve on any module in this PR:
唐超

likedislike
Lliyuanqiang成员
7月9日 update merge request[project id: 7665709, iid: 7301, commit_id: 55979e5f64325812e52f249903fa40d2f81d23ef] virtual merging success
Lliyuanqiang成员
7月9日 强制推送  1 个提交:71db4338-qbmm accuracy issues
Lliyuanqiang成员
7月9日 update merge request[project id: 7665709, iid: 7301, commit_id: 12058dbae7072736d50dbeec78485a2787ee0137] virtual merging success
liyuanqiang成员
7月9日 评论:

compile

likedislike
Lliyuanqiang成员
7月9日 update merge request[project id: 7665709, iid: 7301, commit_id: c4f152b9105b5e1b9d14a75b68aaf058ecaf50d0] virtual merging success
CANN-robotCANN-robot成员
7月9日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月9日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月9日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer-chs-nn ✅ SUCCESS >>>>>
Compile_harmony-infer-chs-nn-1 ✅ SUCCESS >>>>>
UT_Test_ophost ❌ FAILED
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>
likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

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

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

[2026-07-09 19:39:23]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月9日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月9日 添加了label:ci-pipeline-failed
liyuanqiang成员
7月9日 评论:

compile

likedislike
Lliyuanqiang成员
7月9日 update merge request[project id: 7665709, iid: 7301, commit_id: 37a9c857c0b09c1f038c3aff45896fd665b87163] virtual merging success
CANN-robotCANN-robot成员
7月9日 删除了label:ci-pipeline-failed
CANN-robotCANN-robot成员
7月9日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月9日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer-chs-nn ✅ SUCCESS >>>>>
Compile_harmony-infer-chs-nn-1 ✅ SUCCESS >>>>>

[2026-07-09 20:00:08]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

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

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

[2026-07-09 19:55:05]    CI执行结束

likedislike
liyuanqiang成员
7月9日 评论:

compile

likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

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

任务名称状态日志下载链接
Compile_Ascend_X86_mobile_station ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_single ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_experimental ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_X86_950 ✅ SUCCESS >>>>> >>>>>
Compile_Ascend_ARM_950 ✅ SUCCESS >>>>> >>>>>
Compile_Pre ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
Compile_Ascend_X86 ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910b ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_910c ✅ SUCCESS >>>>> >>>>>
Compile_X86_monitor_950 ✅ SUCCESS >>>>> >>>>>
Compile_harmony-infer-chs-nn ✅ SUCCESS >>>>>
Compile_harmony-infer-chs-nn-1 ✅ SUCCESS >>>>>
UT_Test_ophost ✅ SUCCESS
UT_Test_opapi ✅ SUCCESS
UT_Test_kernel ✅ SUCCESS
UT_Test_opgraph ✅ SUCCESS
PreSmoke_A900 ✅ SUCCESS >>>>>
PreSmoke_ATK_Test_A2 ✅ SUCCESS >>>>>

[2026-07-09 20:10:15]    CI执行结束

likedislike
CANN-robot
CANN-robot成员
7月9日 评论:

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

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

[2026-07-09 20:05:02]    CI执行结束

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

/lgtm
/approve

likedislike
liubo75成员
7月9日 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
7月9日 添加了label:lgtm
liulun0308成员
7月9日 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7月9日 添加了label:approved
CANN-robotCANN-robot成员
7月9日 关闭了关联的issue
CANN-robotCANN-robot成员
7月9日 合入了pull request