Merged
fix(gmm): 修复 A5 golden 权重解码与图输入布局 #17527
fix(gmm): 修复 A5 golden 权重解码与图输入布局 #17527
Merged
zhoushaolongAdd on 1 day ago
zhoushaolong
zhoushaolongCollaborators
1 day ago

描述

修复 Ascend 950(A5)GMM 系列 TTK 测试中的权重解码、eager/图模式输入布局衔接问题。

  • 共享 golden:按规范化后的轴号判断转置 stride,兼容 (-1, -2) 与 (-2, -1);ACLNN 逐专家二维权重使用 shape 末两轴,修复 FP4 解码及二维权重索引问题。
  • GMMIA:在 eager 预处理中提供 API 所需的转置视图,在图模块构造阶段恢复逻辑输入布局,再由原 forward 追踪 x1/MX scale 转置,避免图输入 K 维方向不一致。
  • GMMFR:为图源 FP8 E4M3FN × FP4 E2M1 / NZ 场景适配 eager 权重与 scale 视图;在图模块构造阶段绑定源布局,保留图内转置,避免 TorchAir 对非连续内部格式输入执行不支持的 clone。
  • 新增两项 CPU 回归,覆盖转置轴顺序、逻辑数值保持和 FP4 packed K 轴解码。未修改 TTK 源码或精度阈值。

关联的Issue

关联 Issue #8958:https://gitcode.com/cann/ops-transformer/issues/8958

测试

  • 已撤回 GMMFR kernel 修改,当前相对源码基点仅保留四个 golden/测试文件的差异;源码与实际测试文件哈希已核对一致。
  • 使用提交 3c870ffdb9 对应源码,重新构建同源五算子包并独立安装;测试进程加载的 libopapi_transformer.so、GE 编译入口和 kernel 头来自新安装目录。
  • 固定环境:Ascend 950,CANN Toolkit/950 ops 9.3.0~weekly.20261014.01,torch 2.14.0+cpu、torch_npu 2.14.0、原版 TTK 558c98a。
  • 本轮完整复跑 GMMFR 165 条:保留 159 条,筛除 6 条失败用例;拟保留的 FP4/NZ 图用例另以 seed 17/101、每例 run 3 复验。筛选要求所有已记录检查均 PASS。
  • 本批 opstest 从 910 条调整为 904 条,其他四个算子的 745 条保留此前验证结果和原始 CSV 行。本轮是 GMMFR 回归,不是重新全跑 904 条。
  • CPU 回归 2/2 PASS;四个变更文件完整本地 pre-commit 通过,格式修改前后 AST 一致。
  • 沿用 --compare=close 和原 CSV 阈值;Kernel 使用 -d=false -b=release,静态/动态图分别使用 -c/-d,未以 eager 回退代替图执行。
  • 筛选用例与环境说明。此前带 kernel 修改的 910 条通过记录仅为历史结果。

文档更新

本 PR 未修改文档;匹配源码、运行环境与排除项说明已同步更新至 opstest README。

类型标签

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for zhoushaolong's contribution.)
zhoushaolongzhoushaolongCollaborators
1 day ago Created pull request, commit 8736c9c6
atomgit-bot
atomgit-bot
1 day ago Comments:

变更摘要

本 PR 统一了 GMM 系列算子(grouped_matmul_finalize_routing、quant_grouped_matmul_inplace_add、grouped_matmul_swiglu_quant_v2)在图模式与 eager 模式下的权重/scale 布局处理口径,并修复 A8W4 finalize routing 输出初始化的正确性问题。核心改动包括:在测试框架 fused_spec.py 中让转置存储适配不再依赖轴参数顺序,并为 routing 图场景新增 FRACTAL_NZ_C0_32 + float8_e4m3fn/float4_e2m1 的专用预处理分支;在 kernel 侧新增输出清零初始化器,确保 atomic 累加不依赖分配器残留内容;同时调整两个 e2e golden 脚本的图侧输入准备方式。

主要改动

  • _with_transposed_storage 轴顺序无关化:先对 dim0/dim1 取模并排序再比较 stride,使 (-1, -2) 与 (-2, -1) 两种调用都能得到相同的转置存储结果,并保持张量逻辑值不变。
  • routing 图模式预处理分支:_hook_preprocess 新增 routing_graph 判定(f_family 为 routing、带 f_graph_source、f_trans、格式为 FRACTAL_NZ_C0_32 且 dtype 为 float8_e4m3fn 与 float4_e2m1),该分支下 scale 通过 scale.data = scale.transpose(-3, -2) 暴露 API 视图,权重不再做 transpose + contiguous 转换。
  • golden 形状取值改为尾维:_hook_golden 中解码参数由 f_shape[1]、f_shape[2] 改为 f_shape[-2]、f_shape[-1],适配更高维形状描述。
  • A8W4 输出初始化清零:新增 GmmFrA8W4OutputInit(继承 GmmWqgmmFrOutputInit,新增 outputBs 字段),在基类初始化前按 sharedInputOffset/sharedInputLen 划出的共享区间之外,用 FillZeros 与 Clear 分块清零 ptrY 的前缀与后缀,并替换 BlockOutputInit 类型、传入 tiling->outputBs。
  • e2e golden 图侧输入准备调整:gmmfr_e2e_golden.py 新增 PreparedRoutingGraph,在 __init__ 中把打包 NZ 权重与 scale 恢复为源布局、在 forward 中跟踪转置;gmmia_e2e_golden.py 新增 PreparedInplaceGraph 及 npu_preprocess,在 __init__ 绑定逻辑输入、在预处理中仅以视图方式暴露 API 布局且不拷贝低精度值。
  • 新增转置存储单元测试:test_weight_storage.py 覆盖 _with_transposed_storage 在两种轴顺序下值不变、stride 与幂等性,以及 _decode 对 float4_e2m1 打包载体按 K 轴解包的结果。
likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
1 day ago Added label: stat/needs-squash
CANN-robotCANN-robotCollaborators
1 day ago Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
1 day ago 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.
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
gmm ✅ wuyi_huawei, kknan (2/2) ✅ kknan (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Set yangziqi_007,cheng_zhiwei,chenkang30,juyangokok,monologue815,chaotang233,wuyi_huawei,chen-linxin4,jiang-lirui,Allan_Yu,liudan12,Wei_NaChuan,zhangshuoleiokok,shi-rui,cc-z,kdy18482276080,kknan,mabing1118,Julius47 as approver
CANN-robotCANN-robotCollaborators
1 day ago Set yangziqi_007,cheng_zhiwei,chenkang30,juyangokok,monologue815,chaotang233,wuyi_huawei,chen-linxin4,jiang-lirui,Allan_Yu,liudan12,Wei_NaChuan,zhangshuoleiokok,shi-rui,cc-z,kdy18482276080,kknan,mabing1118,Julius47 as approver
zhoushaolongzhoushaolongCollaborators
1 day ago Change title to "fix(gmm): 修复 A5 golden 图输入布局及 GMMFR 输出初始化", originally titled "fix/gmm-a5-unified-20261127".
zhoushaolongzhoushaolongCollaborators
1 day ago Modify description of pull request
zhoushaolongzhoushaolongCollaborators
1 day ago Modify description of pull request
zhoushaolong
zhoushaolongCollaborators
1 day ago Comments:

compile

likedislike
zhoushaolongzhoushaolongCollaborators
1 day ago Pre merge succeeded (commit_id: 62f56e8e60f95187cd370ac9e9bc11b7515a882f)
CANN-robot
CANN-robotCollaborators
1 day ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-failed
CANN-robot
CANN-robotCollaborators
1 day ago Comments:

流水线分析报告 — ops-transformer run#19705

流水线: https://gitcode.com/cann/ops-transformer/actions/runs/22320af494d24bbba222732242b2e3d7 | PR#17527 | 2026-11-28 10:15:28 ~ 10:20:12 | 失败 Job 1 个

定界结论: 代码问题 / 代码检查错误(pre-commit 两项不通过)
  • 失败 Job: CodeCheck_precommit
  • 失败类型: 代码问题(PR 变更导致,提交者修复)
  • 根因: pre-commit 两个 hook 失败
    1. ruff-format:4 个 Python 文件格式不符合 ruff 规范(hook 自动重排后判定失败)
    2. oat-check:新增文件 gmm/grouped_matmul_swiglu_quant_v2/tests/ut/ttk/test_weight_storage.py 缺少合规 License 头(NoLicenseHeader)
  • 处置建议: 通知 PR 提交者本地执行 pre-commit 修复后重新提交(两者均须修复,只修格式仍会因 License 头被拦截)
  • 本地修复参考: 本地执行 pre-commit 指导
  • 排除项: 本 run 共 47 个 Job,其余 46 个均 COMPLETED(含 22 个 Compile、Antipoison、SCA、CodeCheck_style 等);UT/UT_report/PreSmoke_A2/PreSmoke_A5/API_Check/Kirin_PreSmoke 共 9 个 Job 为 INIT,系上游失败未调度,无独立失败;JOB_experimental_950_compile_0 等 2 个为 IGNORED,非失败。

失败根因分析

根因 #1: 代码问题 / 代码检查错误 — ruff format 需重排 4 个 Python 文件
  • 判据: pre-commit hook ruff-format 返回 Failed,输出 4 files reformatted(ruff check 本身已 Passed,仅格式问题)
  • 定位步骤: 4_precommit.log(Job CodeCheck_precommit,第 145–150 行)
  • 影响 Job: CodeCheck_precommit
  • 根因证据(日志原文):
[2026-11-28 10:18:11.520+08:00] ruff check...............................................................Passed
[2026-11-28 10:18:11.520+08:00] ruff format..............................................................Failed
[2026-11-28 10:18:11.520+08:00] - hook id: ruff-format
[2026-11-28 10:18:11.520+08:00] - files were modified by this hook
[2026-11-28 10:18:11.520+08:00] 4 files reformatted
  • 涉及文件: 日志未逐条打印被重排文件名;本 PR 变更的 Python 文件恰为 4 个(与 4 files reformatted 数量一致):
    • gmm/common/tests/ttk/fused_spec.py
    • gmm/grouped_matmul_finalize_routing/tests/assets/gmmfr_e2e_golden.py
    • gmm/grouped_matmul_swiglu_quant_v2/tests/ut/ttk/test_weight_storage.py
    • gmm/quant_grouped_matmul_inplace_add/tests/assets/gmmia_e2e_golden.py
  • 修复: pre-commit run ruff-format --all-files,将重排结果一并提交
根因 #2: 代码问题 / 代码检查错误 — 新增 UT 文件缺少 License 头
  • 判据: OAT Compliance Check 报 License Header Invalid(NoLicenseHeader),hook 退出码 1,阻断提交
  • 定位步骤: 4_precommit.log(第 161–191 行)
  • 影响 Job: CodeCheck_precommit
  • 根因证据(日志原文):
[2026-11-28 10:18:11.520+08:00] OAT Compliance Check (Python Edition)....................................Failed
[2026-11-28 10:18:11.520+08:00] - hook id: oat-check
[2026-11-28 10:18:11.520+08:00] - exit code: 1
[2026-11-28 10:18:11.520+08:00]   OAT: Compliance issues found. Commit blocked.
[2026-11-28 10:18:11.520+08:00] License Header Invalid Total Count: 1
[2026-11-28 10:18:11.520+08:00] Name:	License Header Invalid	Content:	NoLicenseHeader	Line:	0	Project:	ops-transformer	File:	/runner/workers/***.version/worker_dir/cann/ops-transformer/gmm/grouped_matmul_swiglu_quant_v2/tests/ut/ttk/test_weight_storage.py
  • 涉及文件: gmm/grouped_matmul_swiglu_quant_v2/tests/ut/ttk/test_weight_storage.py(PR 新增文件,当前仅有 # Copyright (c) 2026 Huawei Technologies Co., Ltd. 一行,缺少仓库标准的 Mulan PSL v2 许可证头)
  • 修复: 在该文件头部补齐与仓库其他 .py 文件一致的完整 License 头(版权行 + Licensed under the Mulan PSL v2. 及后续声明)
结构化定界摘要
[
  {
    "repo": "ops-transformer",
    "run_number": 19705,
    "Failed_Type": "代码问题",
    "Failed_Sub_Type": "代码检查错误",
    "Failed_Reason": "pre-commit ruff-format 不通过:4 个 Python 文件需按 ruff 规范重排",
    "evidence": "[2026-11-28 10:18:11.520+08:00] ruff format..............................................................Failed / 4 files reformatted",
    "suggestion": "通知 PR 提交者执行 pre-commit run ruff-format --all-files 并提交重排结果",
    "jobs": "CodeCheck_precommit"
  },
  {
    "repo": "ops-transformer",
    "run_number": 19705,
    "Failed_Type": "代码问题",
    "Failed_Sub_Type": "代码检查错误",
    "Failed_Reason": "pre-commit oat-check 不通过:test_weight_storage.py 缺少 License 头(NoLicenseHeader)",
    "evidence": "License Header Invalid Total Count: 1 ... File: .../gmm/grouped_matmul_swiglu_quant_v2/tests/ut/ttk/test_weight_storage.py",
    "suggestion": "为该新增文件补齐仓库标准 Mulan PSL v2 许可证头后重新提交",
    "jobs": "CodeCheck_precommit"
  }
]

由门禁失败定界分析自动生成 | repo: ops-transformer | run: 22320af494d24bbba222732242b2e3d7 | PR#17527

likedislike
jayshu
jayshuCollaborators1 day agoStart code review2
gmm/grouped_matmul_finalize_routing/op_kernel/arch35/grouped_matmul_finalize_routing_a8w4_blaze.h
Outdated
@@ -32,0 +29,4 @@
29+// Atomic routing accumulation must not depend on allocator contents. The shared
30+// input initializer covers only its own rows; clear the disjoint prefix/suffix
31+// before the kernel's existing all-core barrier.
32+class GmmFrA8W4OutputInit : public Blaze::Gemm::Kernel::GmmWqgmmFrOutputInit {
jayshu
jayshu1 day agoComments:

清0这块不要再新增了,本来有自带的清0,你这块加上就是两倍清0,对性能会有影响

likedislike
System
System MessageSystem
1 day ago Comments:

changed this line on 040056d8 view diff detail

likedislike
zhoushaolongzhoushaolongCollaborators
1 day ago Pre merge succeeded (commit_id: f06163450bb852ed29bb50545b1f147080c1c8a9)
10 event messages are collapsed here。 See more
zhoushaolongzhoushaolongCollaborators
1 day ago Modify description of pull request
zhoushaolong
zhoushaolongCollaborators
1 day ago Comments:

compile

likedislike
zhoushaolongzhoushaolongCollaborators
1 day ago Pre merge succeeded (commit_id: 3839d9ec6252fa105bcb2631fab9429567a9a607)
CANN-robot
CANN-robotCollaborators
1 day ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
1 day ago Removed label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
1 day ago Added label: ci-pipeline-passed
zhoushaolongzhoushaolongCollaborators
1 day ago Modify description of pull request
zhoushaolongzhoushaolongCollaborators
1 day ago Resolved final issue
kknan
kknanCollaborators
1 day ago Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: approved
wuyi_51
wuyi_51Collaborators
1 day ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
1 day ago Added label: lgtm
CANN-robotCANN-robotCollaborators
1 day ago Closed associated issue
CANN-robotCANN-robotCollaborators
1 day ago Merged pull request