Pull Request已成功合入, 合并人@CANN-robot
(感谢 caorenlei 的贡献)变更摘要
该 PR 针对 swiglu_mx_quant 算子修复检视意见并补充测试资产:在 arch35 的 swiglu_mx_quant_tiling_arch35.cpp 中统一 ParseAttrs() 的非法入参报错方式并调整 axis 校验位置,同时新增 TTK 测试标杆脚本 golden.py 作为算子融合逻辑(SwiGLU + DynamicMxQuant)的参考实现,另外按标题所述还补充了对应的 aclnn 文档。
主要改动
- 入参校验报错方式统一: 在
ParseAttrs()中引入error_util.h,将swigluMode、clampLimit的非法值检查由OP_LOGE改为OP_LOGE_FOR_INVALID_VALUE_WITH_REASON,报错信息带上属性名和具体取值,便于定位非法入参。 axis校验逻辑调整: 将"swiglu_mode为 2/3 时axis必须为 -1"的检查从读取axis属性处移除,改放到axis必须为 -1 或 -2 的通用校验之后执行,并同步更新错误提示文案。- 新增 TTK 标杆实现
golden.py: 新增__golden_swiglu_mx_quant及辅助函数_swiglu、_mx_quantize,实现 mode 0~3 的 SwiGLU 激活语义(含 clamp、sigmoid、bias)与基于block_size=32的 Dynamic MX 量化(支持 FP4/FP8 各dst_type,以及可选的group_index分组量化),作为算子输出的参考基准。


代码审查
我已完成对两个变更文件的审查。
关闭总结
变更文件审查结果:
-
quant/swiglu_mx_quant/op_host/arch35/swiglu_mx_quant_tiling_arch35.cpp — 无问题。
#include "error_util.h"及OP_LOGE_FOR_INVALID_VALUE_WITH_REASON的 4 参用法与同仓库dynamic_mx_quant_tiling_arch35.cpp中已验证过的用法一致,无编译/宏签名风险;- 将 mode 2/3 的 axis 校验从轴归一化之前移到之后,属于有意修复:正索引表示末轴(如 3D 输入 axis=2)现在能正确归一化为 -1 并通过校验,而 axis=-2/非末轴仍被拒绝,与旧行为不冲突、无回归。
-
quant/swiglu_mx_quant/tests/assets/golden.py — 4 个问题:
- P1(置信 0.8):
_mx_quantize的 mxscale 组装(206-211 行)对 2D 输入抛 IndexError、对 3D 末轴输入(UT 形状 (4,256,4096))抛 ValueError,golden 在文档默认配置(axis=-1)下必然崩溃; - P2(置信 0.55):量化值未饱和到目标 dtype 最大有限值,默认 FP4 E2M1(max 6.0 < clamp_limit 7.0)场景 astype 溢出为 inf,
nan_to_num不清除,参考输出失效; - P3(置信 0.4):负 shared_exp 被钳位为 0,禁用 MX 规范的小幅度 block 放大,可能与 kernel 不一致;
- P3(置信 0.7):
output_dtypes空pass分支为死代码,建议删除。
- P1(置信 0.8):
总体风险评估: C++ 侧改动安全且方向正确;风险集中在新增的 Python 标杆文件,其中 P1 问题使该 golden 在算子最常用配置下无法运行,属于交付功能缺陷,需修复后再启用 TTK 对比;P2 问题会在大幅值场景产生错误的参考值,建议一并修复。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 1 |
| 🟡 建议 | 1 |
⛔ 需要修改


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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| */*/docs/acl*.md | ✅ 陈娇, 汤平川 (2/2) | ✅ 陈娇 (1/1) |
| quant | ✅ 陈风, 汤平川 (2/2) | ✅ 陈风, 汤平川 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
caorenlei, thanks for your pull request. All authors of the commits have signed the CLA. 👍


🟠 High Priority
changed line: golden.py 新增的 _mx_quantize 中 scale_out 组装逻辑(206-211 行)。
受影响行为/契约:scale_flat 始终是扁平的三维 (pre_q, n_blocks, post_q),而 scale_out 的形状是 shape 把 axis_pos 维替换为 n_blocks 后再 append(2),即 ndim+1 维;两者维数/形状根本没有对齐,赋值语句却按固定维数写死。
失败模式:
即该 golden 在算子最常用配置(axis=-1,rank 2/3,以及 group_index 分组路径 280-295 行同样调用本函数)下必然崩溃,无法生成参考输出,新增标杆完全不可用。
建议:将 scale_flat 先 reshape 回原始维度(axis_pos 处为 n_blocks)再写入 scale_out 的最后一个维度(两个槽位写同一份 scale),替换整个 if/else 分支。


🟡 Medium Priority
变更行:golden.py 第 200-211 行(新增的 _mx_quantize 的 scale 输出构造部分)。
影响行为:scale_out 是按「未展开的完整 shape」构造的(第 201-204 行:scale_shape = list(shape)、把 axis 维替换为 n_blocks、再 append(2)),但写入时却按「已展开的 (pre_q, n_blocks, post_q, 2)」形状进行索引(第 207-211 行)。
失败模式(对默认/主路径 axis=-1 必然触发):
- 即便不崩溃,第 207-208 行把同一份 scale 写入 block 下标 0 和 1 位置、并把 trailing 维下标 1 留为 0,语义上也与「每个 block 一个 scale」不符。
由于 axis=-1 是默认属性、且 mode 2/3 仅允许 axis=-1,该 golden 在主要测试路径上直接崩溃,无法产出参考输出。
建议:将 scale_flat 先 reshape 到 scale_shape[:-1] 再写入 scale_out 的两个 trailing 切片,统一处理 post_q==1 与 post_q>1 两种情况,避免按展开形状索引未展开数组。


流水线任务触发成功
任务链接 [9e62de3ef0404e068a4c0ec24c3ea0bc][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| 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_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_single_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_950_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test_ophost | ✅ SUCCESS | ||
| UT_Test_opapi | ✅ SUCCESS | ||
| UT_Test_kernel | ✅ SUCCESS | ||
| UT_Test_opgraph | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_report_lcov | ✅ SUCCESS | >>>>> |
[2026-08-27 20:12:37] CI执行结束


/lgtm
/approve


/lgtm
/approve


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
本次改动针对 swiglu_mx_quant 算子(arch35 平台)修复检视意见,并新增标杆实现与 aclnn 接口文档。
改动原因
OP_LOGE打印错误日志,未使用结构化的OP_LOGE_FOR_INVALID_VALUE_WITH_REASON,无法准确标识出错的参数名和校验原因。swigluMode 2/3的 axis 校验位于通用 axis 校验之前,逻辑顺序不合理。swigluMode 2和3的计算公式、参数约束及错误码说明。改动方法
tiling 代码修复(
swiglu_mx_quant_tiling_arch35.cpp):#include "error_util.h"swigluMode、clamp_limit、axis三处参数校验的错误日志从OP_LOGE改为OP_LOGE_FOR_INVALID_VALUE_WITH_REASON,明确标识参数名和校验原因swigluMode 2/3的 axis 校验从通用 axis 校验之前移到之后,先执行通用校验(axis 必须为 -1 或 -2),再执行模式特定校验(mode 2/3 要求 axis=-1)aclnn 文档补充(
aclnnSwigluMxQuant.md):标杆新增(
tests/assets/golden.py):关联的Issue
#5268
测试
文档更新
quant/swiglu_mx_quant/docs/aclnnSwigluMxQuant.md:新增 swigluMode 2/3 计算公式、参数约束、错误码类型标签
AI/Agent生成声明