Merged
fix(swiglu_mx_quant): 修正资料与实现不一致,对齐golden参考实现及binary.json属性顺序 #10341
fix(swiglu_mx_quant): 修正资料与实现不一致,对齐golden参考实现及binary.json属性顺序 #10341
Merged
chenfengAdd on Sep 12
chenfeng
chenfengCollaborators
Sep 12

描述

本 PR 修正 swiglu_mx_quant 算子资料与实际实现不一致的问题,并对齐 golden 参考实现与 binary.json 属性顺序。

改动一:修正算子描述与实现不一致(README.md / docs/aclnnSwigluMxQuant.md / op_graph/swiglu_mx_quant_proto.h)

属性描述由"预留参数"修正为真实语义:

  • activate_left:表示对输入的前半部分或后半部分做 SwiGLU 激活,false 时激活后半部分;swiglu_mode=1 时该参数不生效
  • swiglu_mode:计算模式 0=传统 SwiGLU、1=奇偶交错变体、2=前后分半 clamp 变体、3=前后分半 sigmoid-clamp 变体,取值范围 [0, 3]
  • clamp_limit:变体 SwiGLU(swiglu_mode=1/2/3)的 clamp 门限,需大于 0
  • glu_alpha / glu_bias:变体 SwiGLU(swiglu_mode=1/2)的 sigmoid 缩放系数 / 线性部分偏置
  • group_mode:0=count 模式、1=cumsum 模式,当前仅支持 0
  • scale_alg:0=OCP、1=cuBLAS、2=RNE(预留),当前仅支持 0 和 1
  • max_dtype_value:预留参数,当前版本未生效

输入/输出描述修正:

  • x:在 activate_dim 指定维度上的尺寸必须是 2 的倍数(原文误写为 dim 维度)
  • group_index:shape[0] 大于 0 且小于等于 256;aclnn 文档数据类型由仅 INT64 修正为 INT32、INT64;补充 data 取值约束——每个值必须为大于等于 0 的整数,且所有值的和必须小于等于需要量化的 x 的总行数
  • y:形状与 x 相同,activate_dim 维度为 x 的一半
  • mxscale:每个量化块(32 个元素一组)的缩放因子;scale 成对存放——axis 轴为 y 对应轴除以 32 向上取整后按偶数对齐,最后一维固定为 2 存放相邻两个量化块的 scale;当 axis=-2 且 group_index 存在时,axis 轴 shape 为 y 对应轴值整除 64 再加 group_num

约束修正与补充:

  • 修正:activate_dim 为非尾轴时,swiglu_mode 必须为 0(aclnn 文档原文误写为 0 或 1)
  • 新增:swiglu_mode 为 2 或 3 时,axis 必须为 -1
  • proto.h 中 mxscale shape 推导公式同步修正(块数按偶数对齐成对打包;group_index 且非尾轴时为 act_shape[axis]/64 + group_num)
  • 新增:group_index 输入 data 约束——每个值必须为大于等于 0 的整数,且所有值的和必须小于等于需要量化的 x 的总行数(README.md 输入表与约束说明、aclnn 文档参数表与约束说明、proto.h 输入描述与 Constraints 三处同步补充;aclnn 文档原文"每个元素需要大于0"同步修正为"大于等于0的整数")

改动二:golden 参考实现修正(tests/assets/golden.py)

  • mxscale 布局修正为成对打包:axis 维为 ceil(n_blocks/2),末维 2 存放相邻两个 32 元素块的 scale,padding 槽位补 0
  • E8M0 scale 编码修正:scale_byte = clip(floor(log2(amax)) - emax + 127, 0, 255),全零块输出 scale 字节 0(2^-127)
  • group_index 场景修正:axis=-2 时每组拥有 ceil(rows_g/64) 个 scale pair 按组紧凑排布(分配 axis 维 = M//64 + groupNum);axis=-1 时 group_index 对 SwiGLU 输出展平后的行做分段
  • 头部新增 mxscale layout 说明注释(与 kernel/infershape 对齐)

改动三:binary.json 属性顺序对齐(op_host/config/ascend950/swiglu_mx_quant_binary.json)

  • 16 个 binary 配置项的 attrs 顺序统一调整为与 proto.h 属性声明顺序一致:activate_dim 移至 activate_left 之前,group_mode 移至 glu_bias 之后
  • 属性集合与取值不变,纯顺序调整(+144/-144 对称改动)

关联的Issue

测试

  • golden.py 为精度比对参考实现,本次将其与 kernel 实际输出布局(mxscale 成对打包、E8M0 编码、group_index 打包逻辑)对齐,保障 ST 精度比对基准正确

文档更新

  • quant/swiglu_mx_quant/README.md:属性语义、输入输出描述及约束修正
  • quant/swiglu_mx_quant/docs/aclnnSwigluMxQuant.md:group_index 数据类型、mxscaleOut shape 规则、约束修正
  • quant/swiglu_mx_quant/op_graph/swiglu_mx_quant_proto.h:属性语义与 mxscale 推导公式注释同步

类型标签

AI/Agent生成声明

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for chenfeng's contribution.)
chenfengchenfengCollaborators
Sep 12 Created pull request, commit 120cc611
CANN-robotCANN-robotCollaborators
Sep 12 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Sep 12 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
*/*/README.md ✅ 陈娇, 钱泽洪, 杨阳, 王星 (4/2) ✅ 陈娇 (1/1)
*/*/docs/acl*.md ✅ 陈娇, 钱泽洪, 杨阳, 王星 (4/2) ✅ 陈娇 (1/1)
*/*/op_graph/*_proto.h ✅ 汤磊, 钱泽洪, 杨阳, 王星 (4/2) ✅ 汤磊 (1/1)
quant ✅ 王星, 钱泽洪, 杨阳 (3/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
CANN-robotCANN-robotCollaborators
Sep 12 Set zengjuan,u010470851,sxb154714,chaotang233,crystalhu,yangyang016,fanqirui,gitee-duhuiping,su-yueming,zhajianqing123,tang-lei01,yourealize,chenqi317,LinPX,wang-xing001,liubo75,tangweiwei2,wangzitao_leo,xubinglin,gitcode-chenjiao,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang,fengying555682,liuyang_806,caiwenwen,yanglu-1 as approver
CANN-robotCANN-robotCollaborators
Sep 12 Set u010470851,sxb154714,gitee-duhuiping,su-yueming,zhajianqing123,tang-lei01,yourealize,LinPX,wang-xing001,wangzitao_leo,xubinglin,gitcode-chenjiao,liujie12345678,pingchuantang,Chen_HaoWen,qianzehong,wangyongguang,fengying555682,liuyang_806,caiwenwen,yanglu-1 as approver
chenfengchenfengCollaborators
Sep 12 Change title to "fix(swiglu_mx_quant): 修正资料与实现不一致,对齐golden参考实现及binary.json属性顺序", originally titled "fix(swiglu_mx_quant): 修正资料与实现不一致及binary.json属性顺序".
chenfengchenfengCollaborators
Sep 12 Modify description of pull request
chenfeng
chenfengCollaborators
Sep 12 Comments:

compile

likedislike
chenfengchenfengCollaborators
Sep 12 Pre merge succeeded (commit_id: f4c3864540dc16aaa52ff5517f822fb5eccdf57e)
CANN-robot
CANN-robotCollaborators
Sep 12 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 12 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 12 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 12 Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
Sep 12 Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
chenfengchenfengCollaborators
Sep 14 Pre merge succeeded (commit_id: c19b2fc310625c62345bca842c448b83065be616)
5 event messages are collapsed here。 See more
CANN-robotCANN-robotCollaborators
Sep 14 Removed label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:

Notification

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

likedislike
chenfengchenfengCollaborators
Sep 14 Modify description of pull request
chenfeng
chenfengCollaborators
Sep 14 Comments:

compile

likedislike
chenfengchenfengCollaborators
Sep 14 Pre merge succeeded (commit_id: e2ef56556a8b2dd3dc9b85204dda31d2fc6c82ef)
CANN-robot
CANN-robotCollaborators
Sep 14 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 14 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Sep 14 Added label: ci-pipeline-passed
yuning_chen
yuning_chenCollaborators
Sep 14 Comments:

您好,pr合入已准备就绪,请尽快联系committer进行检视,谢谢!

likedislike
qianzehongCollaborators
Sep 15 Comments:

/lgtm
/approve

likedislike
chenjiaoCollaborators
Sep 15 Comments:

/approve

likedislike
yangyang016Collaborators
Sep 15 Comments:

/lgtm
/approve

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: lgtm
wang-xing001Collaborators
Sep 15 Comments:

/lgtm
/approve

likedislike
tang-lei01Collaborators
Sep 15 Comments:

/approve

likedislike
CANN-robot
CANN-robotCollaborators
Sep 15 Comments:

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

likedislike
CANN-robotCANN-robotCollaborators
Sep 15 Added label: approved
CANN-robotCANN-robotCollaborators
Sep 15 Closed associated issue
CANN-robotCANN-robotCollaborators
Sep 15 Merged pull request