已合并
对 SwigluMxQuantWithDualAxis 算子 arch35 偶现精度问题修改 #6699
对 SwigluMxQuantWithDualAxis 算子 arch35 偶现精度问题修改 #6699
已合并
chenfeng创建于 6月29日
chenfeng
chenfeng成员
6月29日

描述

对 SwigluMxQuantWithDualAxis 算子 arch35 偶现精度问题修改:

  1. MicroAPI 交错存储:新增 ComputeInterleave 函数,使用 MicroAPI::DataCopy + DIST_INTLV_B8 替代原有 Interleave 函数,ascendc api不支持src和dst是同地址。
  2. 常量提取:抽出 ONCE_ROW_LEN = 256、DIGIT_THREE = 3 等魔数,初始化改用常量替代 tilingData 间接取值。
  3. Buffer 计算简化:mxScale2BufferSize 与 tmpScale2BufferSize 公式利用已知常量简化。

关联的Issue

测试

文档更新

类型标签

  • Bug修复
  • 新特性
  • 性能优化
  • 文档更新
  • 其他,请描述:

AI/Agent生成声明

  • AI辅助编写
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 chenfeng 的贡献)
chenfengchenfeng成员
6月29日 创建了 pull request,commit 7fcdfb02
CANN-robotCANN-robot成员
6月29日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月29日 评论:

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
quant 徐炳麟, 唐玮玮 (2/2) 唐玮玮, 徐炳麟 (2/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
chenfengchenfeng成员
6月29日 修改标题为 “对 SwigluMxQuantWithDualAxis 算子 arch35 偶现精度问题修改”,原标题为“test”
chenfengchenfeng成员
6月29日 修改了pull request 的描述
chenfeng
chenfeng成员
6月29日 评论:

compile

likedislike
chenfengchenfeng成员
6月29日 update merge request[project id: 7665709, iid: 6699, commit_id: 8748c577dc9bb6d719023c8892f85dccf789d910] virtual merging success
CANN-robotCANN-robot成员
6月29日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月29日 评论:

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

任务名称状态日志下载链接
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 >>>>> >>>>>
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-06-29 09:50:58]    CI执行结束

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

变更摘要

该 PR 对 SwiGLU MX 量化算子的 arch35 架构实现进行了多项优化和修复,主要涉及缓冲区大小计算修正、双缓冲降级为单缓冲、tiling 参数硬编码化,以及 scale2 数据交织操作的 API 替换。

主要改动

  • scale2Ub 计算常量修正: 在 swiglu_mx_quant_with_dual_axis_tiling_arch35.cpp 中,scale2Ub 的计算将乘数从 DIGIT_TWO(2) 改为 DIGIT_HTREE(3),匹配 scale2 实际需要的 3 行缓冲区大小。

  • Queue 双缓冲降级为单缓冲: inQueue_outQueue1_outQueue2_mxScaleQueue1_mxScaleQueue2_ 的模板参数从 DB_BUFFER(2) 改为 1,移除所有队列的双缓冲机制以节省 UB 空间。

  • ubRowLen_ubRowCount_ 硬编码: InitParams()ubRowLen_ 改用新增常量 ONCE_ROW_LEN(256) 替代 tilingData_->blockWubRowCount_ 改用 DOUBLE_BLOCK_SIZE(64) 替代 tilingData_->splitBlockH,不再依赖 tiling 数据。

  • mxScale2 缓冲区大小简化: mxScale2BufferSizeubRowLen_ * ((ubRowCount_ / DOUBLE_BLOCK_SIZE) * DIGIT_TWO) 简化为 ubRowLen_ * DIGIT_THREEtmpScale2BufferSizeubRowLen_ * ((ubRowCount_ / DOUBLE_BLOCK_SIZE) * DIGIT_TWO) * sizeof(xDtype) 简化为 ubRowLen_ * DIGIT_TWO * sizeof(xDtype)

  • 交织操作改用 ComputeInterleave: 新增 ComputeInterleave 方法,内部使用 MicroAPI::DataCopy 配合 DIST_INTLV_B8 交织存储模式完成 scale2 数据的字节级交织,替代原有的 Interleave 函数调用。

likedislike
chenfengchenfeng成员
6月29日 修改了pull request 的描述
CANN-robot
CANN-robot成员
6月29日 评论:

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

任务名称状态日志下载链接
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-06-29 09:49:36]    CI执行结束

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

代码审查

审查总结

优先级 数量 说明
P0 0
P1 0
P2 2 队列深度不匹配、DataCopy 越界加载风险
P3 1 tiling data 契约被硬编码绕过(可选建议)

各文件审查结果:

  • quant/swiglu_mx_quant_with_dual_axis/op_host/arch35/swiglu_mx_quant_with_dual_axis_tiling_arch35.cpp — 仅 1 行改动(DIGIT_TWODIGIT_HTREE),与 kernel 侧的 mxScale2 缓冲区增大一致,无独立问题

  • quant/swiglu_mx_quant_with_dual_axis/op_kernel/arch35/swiglu_mx_quant_with_dual_axis_regbase.h — 34 行新增/修改,发现 3 个问题(2 个 P2 + 1 个 P3)。

整体风险评估:中等。P2 的两个问题分别涉及 AscendC pipeline 框架的队列契约不一致和可能的 UB 越界读取,在特定条件下可能导致运行时错误或精度异常。建议优先修复队列深度与 InitBuffer 的匹配问题,并确认 ComputeInterleave 中的 DataCopy 加载 API 用法的正确性。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
atomgit-bot
atomgit-bot6月29日进行代码检视1
quant/swiglu_mx_quant_with_dual_axis/op_kernel/arch35/swiglu_mx_quant_with_dual_axis_regbase.h
@@ -154,0 +151,4 @@
151+ TQue<QuePosition::VECOUT, 1> outQueue1_;
152+ TQue<QuePosition::VECOUT, 1> outQueue2_;
153+ TQue<QuePosition::VECOUT, 1> mxScaleQueue1_;
154+ TQue<QuePosition::VECOUT, 1> mxScaleQueue2_;
atomgit-bot
atomgit-bot6月29日评论:

🟡 Medium Priority

diff 将 5 个队列的模板深度从 DB_BUFFER(2) 改为 1(第 149-154 行),但对应的 InitBuffer 调用(第 251、253-256 行)仍然传递 DB_BUFFER(2) 作为 buffer 数量。

在 AscendC 框架中,TQue<Pos, N> 的 N 表示队列 pipeline 深度,InitBuffer(queue, cnt, size) 的 cnt 表示物理 buffer 数量,二者应保持一致。当前的不匹配意味着:

  • 若框架以 TQue 深度为准,则只使用 1 个 buffer,另 1 个 buffer 被分配但从不使用(浪费 UB 内存);
  • 若框架以 InitBuffer 为准,则 pipeline 深度为 1 但物理 buffer 为 2,可能导致 EnQue/DeQue 时 buffer 管理出错。

受影响的队列:inQueue_, outQueue1_, outQueue2_, mxScaleQueue1_, mxScaleQueue2_

此变更的意图似乎是简化 pipeline(单缓冲),但遗漏了同步更新 InitBuffer 调用。

建议:方案一(推荐):若确实只需单缓冲,将 InitBuffer 的第二个参数从 DB_BUFFER 改为 1,并同步更新 host 侧的 UB 大小校验(减少 scale1Ub/scale2Ub/y1Ub 等的 DB 因子)。
方案二:若仍需双缓冲,将 TQue 模板参数恢复为 DB_BUFFER。

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

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
6月29日 添加了label:approved
tangweiwei2成员6月29日进行代码检视2
quant/swiglu_mx_quant_with_dual_axis/op_host/arch35/swiglu_mx_quant_with_dual_axis_tiling_arch35.cpp
已过期
@@ -369,3 +369,3 @@
369369 int64_t y2Ub = y1Ub;
370370 int64_t scale1Ub = tilingParams_.splitBlockH * BLOCK_SIZE * DB;
371- int64_t scale2Ub = tilingParams_.blockW * DIGIT_TWO * DB;
371+ int64_t scale2Ub = tilingParams_.blockW * DIGIT_HTREE * DB;
tangweiwei26月29日评论:

HTREE?拼错了THREE?

likedislike
System
系统消息系统
6月29日 评论:
likedislike
chenfengchenfeng成员
6月29日 virtual merging failed, update merge request[project_id: 7665709, iid: 6699, target_commit_sha: 7121998cf1849ab131a98b0d5102fac6a850f352], message: You are not allowed to merge to this ref
Ccheng-ziyang2成员
6月29日 推送  1 个提交:50f0194b-fix: DIGIT_HTREE -> DIGIT_THREE 拼写修正
chenfengchenfeng成员
6月29日 virtual merging failed, update merge request[project_id: 7665709, iid: 6699, target_commit_sha: 7121998cf1849ab131a98b0d5102fac6a850f352], message: You are not allowed to merge to this ref
CANN-robotCANN-robot成员
6月29日 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
6月29日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
6月29日 评论:

Notification

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

likedislike
CANN-robotCANN-robot成员
6月29日 删除了label:approved
CANN-robot
CANN-robot成员
6月29日 评论:

Notice

New code changes of the pull request are detected and remove these labels approved. 😳

likedislike
chenfeng
chenfeng成员
6月29日 评论:

compile

likedislike
chenfengchenfeng成员
6月29日 update merge request[project id: 7665709, iid: 6699, commit_id: 8851c8b1b49555030acba3b37073db77e2ab8828] virtual merging success
chenfengchenfeng成员
6月29日 解决了最后一个问题
CANN-robotCANN-robot成员
6月29日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
6月29日 评论:

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

任务名称状态日志下载链接
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 >>>>> >>>>>
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-06-29 10:39:08]    CI执行结束

likedislike
tangweiwei2成员
6月29日 评论:

/approve
/lgtm

likedislike
CANN-robotCANN-robot成员
6月29日 添加了label:approved
xubinglin成员
6月29日 评论:

/approve
/lgtm

likedislike
CANN-robotCANN-robot成员
6月29日 添加了label:lgtm
CANN-robot
CANN-robot成员
6月29日 评论:

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

任务名称状态日志下载链接
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-06-29 10:34:50]    CI执行结束

likedislike
CANN-robotCANN-robot成员
6月29日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
6月29日 添加了label:ci-pipeline-passed
CANN-robotCANN-robot成员
6月29日 合入了pull request
CANN-robot
CANN-robot成员
6月29日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike