Merged
[fix] QBMMV3 batch consistency handling #7705
[fix] QBMMV3 batch consistency handling #7705
Merged
guiruoyuAdd on Jul 20
guiruoyu
guiruoyuCollaborators
Jul 20

描述

  • QBMMV3 StreamK 场景的 batch 一致性校验由 GetDeterministic() == 1 调整为 GetDeterministicLevel() > 1,仅在 batch 一致性等级下过滤 StreamK,保留普通确定性等级的行为。
  • QBMMV3 per-block 场景选中对应 tiling 模板且 GetDeterministicLevel() > 1 时输出 warning,提示该量化模式天然不支持 batch 一致性。

关联的Issue

无。

测试

  • git diff --check HEAD^ HEAD 通过。
  • 推送 GitCode 时仓库 pre-push hook 检查通过。
  • 当前本地 Windows 环境不具备 CANN/Linux 编译运行环境,编译与 UT 由 CI 验证。

文档更新

无。

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for guiruoyu's contribution.)
guiruoyuguiruoyuCollaborators
Jul 20 Created pull request, commit 9a90081d
atomgit-bot
atomgit-bot
Jul 20 Comments:

变更摘要

此 PR 修复了 QBMMV3 量化算子中 batch 一致性校验粒度过粗的问题。原逻辑使用 GetDeterministic() == 1 判断是否启用确定性模式,导致普通确定性场景与 batch 一致性场景被等同处理。现统一改为 GetDeterministicLevel() > 1,仅在 batch 一致性等级下触发限制行为,保留普通确定性等级的正常执行路径。同时为 per-block 量化模板新增了 batch 一致性不支持的警告提示。

主要改动

  • StreamK tiling 的 batch 一致性过滤条件收紧:在 QBMMV3StreamKTiling::IsCapable() 中,将确定性判断从 GetDeterministic() == 1 改为 GetDeterministicLevel() > 1,使得 StreamK 仅在 batch 一致性等级(level > 1)下被禁用,普通确定性模式下不再被错误过滤。
  • Per-block tiling 新增 batch 一致性警告:在 AdaptiveSlidingWindowPerblockBasicAPITiling::IsCapable() 中,当 tiling 模板被判定为可用且 GetDeterministicLevel() > 1 时,通过 OP_LOGW 输出警告,明确告知该量化模式天然不支持 batch 一致性。
  • 日志信息细化:StreamK 禁用时的日志消息从原来的 "deterministic mode is enabled" 更新为 "deterministic level is greater than 1 for batch consistency",更准确地描述了触发条件。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
Jul 20 Comments:

代码审查

Now I have a complete picture. Both batch_matmul_v3_basic_streamk_tiling.cpp (line 72) and matmul_v3_basic_streamk_tiling.cpp (line 142) use the identical context_->GetDeterministicLevel() > 1 pattern without INT32_MAX guard. The QBMM files in this diff adopt the same established convention, and additionally add context_ != nullptr guards which are more defensive than the sibling files.

Let me do the final targeted sweep.


Final sweep (silent):

  1. Boundary values for > 1: Level 0 (disabled) → false ✓. Level 1 (normal deterministic) → false ✓. Level 2+ (batch consistency) → true ✓. No off-by-one.

  2. Hot-path costs: IsCapable() is called once in DoTiling() (line 80 of tiling_base.h), not in any hot loop. The added GetDeterministicLevel() call is a single attribute access — negligible.

  3. Co-located secondary defects around the changed lines:

    • StreamK file line 889-892: The return false correctly exits IsCapable(). The new check is placed BEFORE the expensive EvaluateStreamKBenefitGate() call (line 898), which is an optimal placement since it short-circuits when batch consistency is detected. No issue.
    • Per-block file lines 57-64: The newly expanded IsCapable() returns isCapable (the local variable) on line 63 as it should; no risk of returning an uninitialized value since isCapable is initialized on line 59. The warning fires but does not block — this is by design per the PR description. No issue.

No issues found.


审查结论

此 diff 将 QBMMV3 的两个 tiling 模板中的确定性检查从 GetDeterministic() == 1 调整为 GetDeterministicLevel() > 1,与同仓库中 batch_matmul_v3_basic_streamk_tiling.cpp 和 matmul_v3_basic_streamk_tiling.cpp 的既有模式保持一致。变更语义正确、代码风格一致、无正确性/安全/可靠性问题。

变更文件审查结果:

  • adaptive_sliding_window_perblock_basic_api_tiling.cpp:无问题。新增的 warning 逻辑为纯增量行为,不影响模板选择结果;context_ 空指针检查到位。
  • qbmm_streamk_tiling.cpp:无问题。确定性检查语义变更正确(普通确定性等级保留 StreamK,仅 batch 一致性等级过滤),日志信息与变更语义一致。
严重度 数量
P0 0
P1 0
P2 0
P3 0

整体风险评估:低风险。 此变更仅调整确定性等级判断的粒度,与仓库中其他同类 tiling 模板的既有模式完全一致,且增加了额外的空指针防护。

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

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 20 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 20 Comments:

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
matmul ✅ 范其瑞, 王子韬, 刘波 (3/2) ✅ 范其瑞, 王子韬 (2/1)
tests ✅ 范其瑞, 刘波 (2/2) ✅ 范其瑞 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
72 messages are collapsed here。 See more
liuyang_806liuyang_806Collaborators
Oct 12 Deleted associated issue: [Requirement|需求建议]: 算子新增支持 Batch 一致性
CANN-robotCANN-robotCollaborators
Oct 12 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Oct 12 Comments:

The following label is not ready.

ci-pipeline-passed: The ci-pipeline-passed label is expired as added over 72 hours. Please use /compile to recompile.

likedislike
CANN-robot
CANN-robotCollaborators
Oct 12 Comments:

The following label is not ready.

ci-pipeline-passed: The ci-pipeline-passed label is expired as added over 72 hours. Please use /compile to recompile.

likedislike
liuyang_806liuyang_806Collaborators
Oct 12 Associated issue: [Requirement|需求建议]: 算子新增支持 Batch 一致性