Merged
docs(gmm): 补充 GMMFR、Swiglu 与 InplaceAdd 转置融合指南 #15168
zhoushaolongAdd on 7 days ago
docs(gmm): 补充 GMMFR、Swiglu 与 InplaceAdd 转置融合指南 #15168
Merged
Total: 17 files changed+195-0
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:4591e729fcfb2fff1802a14c43498d79fc4a355f92e5985a8ae9ffb375f3e557 | ||
| 3 | +size 52187 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:d5d717ec4de8408f9fe9b71351b937daec245e64e8e38f4beeb8b443e4de60da | ||
| 3 | +size 54183 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:8f5d51000f53a6e8dddb9686fd360bec7458be8b1336a15d07cdb856b26f5e4e | ||
| 3 | +size 5370 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:2e436373a904bfcf2f70f6c62d1b74d86257144320c3134e6a690dab74b7490e | ||
| 3 | +size 9237 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:bed926ffcffbcbabf63dca2127f2c425ae86493a27161fada7a42a6c152ee5b6 | ||
| 3 | +size 41708 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:3e470ff3e2ddaaf0bca2627ab7f199f56555bb8888206f4d4ba3bfc663597b44 | ||
| 3 | +size 52867 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:16a2f8b2b2e9f4b3f71feb461af89493664162e545e223c0460836094598166d | ||
| 3 | +size 42837 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:dca908e3ae11fe6e294dd8ea377ca4a0543e406b271371ce65ff004fdda83ee8 | ||
| 3 | +size 46211 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:8f5d51000f53a6e8dddb9686fd360bec7458be8b1336a15d07cdb856b26f5e4e | ||
| 3 | +size 5370 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:2e436373a904bfcf2f70f6c62d1b74d86257144320c3134e6a690dab74b7490e | ||
| 3 | +size 9237 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:6df851d2b6c85b15fd2ec8dd3c49d2460dc2531f915f3b1590e4991c66eec721 | ||
| 3 | +size 45037 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:a46b1aebfafa143e34a79bf8cbc3a739643d87b628abb8e1c79d42982e638c3b | ||
| 3 | +size 55444 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:8d66f5f29e11d4c469feefd4205cd7733b08d60db90cbc6631fb901700acdf9c | ||
| 3 | +size 33745 | ||
| @@ -0,0 +1,3 @@ | |||
| 1 | +version https://git-lfs.github.com/spec/v1 | ||
| 2 | +oid sha256:505844dd4bfaa6cba0c244d413e4be1028931073d5285034e1ef445eb0c73ec5 | ||
| 3 | +size 34501 | ||
| @@ -0,0 +1,67 @@ | |||
| 1 | +# GroupedMatmulFinalizeRoutingTransposeFusionPass | ||
| 2 | + | ||
| 3 | +## 融合模式 | ||
| 4 | + | ||
| 5 | +下图中的 `[Bitcast]` 表示可选节点,存在时保留,不由本 Pass 消除;不存在时直接连接对应源节点。图中的 Transpose 也可为 TransposeD。 | ||
| 6 | + | ||
| 7 | +所有模式均不改动 x、x_scale 等其他输入。融合成功后,将算子的 `transpose_w` 从 `false` 设置为 `true`,由算子承担 weight 的转置语义。 | ||
| 8 | + | ||
| 9 | +### 非 MX 量化 | ||
| 10 | + | ||
| 11 | +非 MX 场景要求 weight 和 weight_scale 两侧配套匹配,其中 weight_scale 仅支持 Reshape → Transpose → Reshape 结构。以下是支持的特殊图结构,不表示非 MX 量化调用必然生成这条 scale 链。 | ||
| 12 | + | ||
| 13 | +融合模式一:weight 经过单个 Transpose 或转置等价的 Reshape,weight_scale 经过 Reshape → Transpose → Reshape。配套消除两侧转置链,保留已有的 Bitcast。 | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +融合模式二:weight 和 weight_scale 均经过 Reshape → Transpose → Reshape。配套消除两侧的三节点转置链,保留已有的 Bitcast。 | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +### MX 量化 | ||
| 22 | + | ||
| 23 | +#### 可融合转置链 | ||
| 24 | + | ||
| 25 | +MX 场景要求 weight 和 weight_scale 两侧均匹配到可融合转置链,才配套融合。可融合转置链有以下两类。 | ||
| 26 | + | ||
| 27 | +第一类:单个 Transpose/TransposeD,或转置等价的单个 Reshape。 | ||
| 28 | + | ||
| 29 | +“转置等价的单个 Reshape”指待交换的两个维度中至少有一个为 1,仅改变 shape、不重排数据即可得到与转置相同的结果。例如,weight 从 `[2, 128, 1]` Reshape 为 `[2, 1, 128]`,等价于交换最后两个维度。 | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +第二类:Reshape → Transpose/TransposeD → Reshape。整条链须满足指定轴交换的 shape 和排列检查,不能将任意三节点链当作可融合结构。 | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +例如,weight 的 `[1, 128, 256] → [128, 256] → [256, 128] → [1, 256, 128]`,以及 MX scale 的 `[1, 128, 4, 2] → [128, 4, 2] → [4, 128, 2] → [1, 4, 128, 2]`,分别表示先去掉单位 group 轴、完成转置、再恢复 group 轴。 | ||
| 38 | + | ||
| 39 | +两侧可以分别选择不同结构:均为第一类、均为第二类,或一侧第一类、另一侧第二类。下文用“可融合转置链”统一表示这两类结构,不再逐一展开组合。 | ||
| 40 | + | ||
| 41 | +#### MXFP8 | ||
| 42 | + | ||
| 43 | +下图中,weight 侧没有 Bitcast,weight_scale 使用字节载体,通过 Bitcast 解释为 E8M0。 | ||
| 44 | + | ||
| 45 | +融合时,配套消除两侧的可融合转置链。融合后 weight 直接连接算子,weight_scale 仍经 Bitcast 连接算子。 | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +#### MXFP4 | ||
| 50 | + | ||
| 51 | +下图表示 weight 使用字节载体、经 Bitcast 和尾部 Reshape 恢复逻辑 FP4 shape,weight_scale 经 Bitcast 解释为 E8M0 的调用路径。 | ||
| 52 | + | ||
| 53 | +融合时,配套消除 weight、weight_scale 的可融合转置链;保留 weight 的 Bitcast、尾部打包 Reshape,以及 weight_scale 的 Bitcast,并更新打包链的 shape、输入描述及相关 Shape 依赖。 | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +weight 的尾部打包 Reshape 不属于“可融合转置链”,不能随转置链一起删除。 | ||
| 58 | + | ||
| 59 | +## 使用约束 | ||
| 60 | + | ||
| 61 | +- 算子的 `transpose_w` 属性须为 `false`,融合后设为 `true`;已为 `true` 时不再融合。 | ||
| 62 | + | ||
| 63 | +## 支持的型号 | ||
| 64 | + | ||
| 65 | +<!-- npu="950" id1 --> | ||
| 66 | +Ascend 950PR/Ascend 950DT | ||
| 67 | +<!-- end id1 --> | ||
| @@ -0,0 +1,67 @@ | |||
| 1 | +# GroupedMatmulSwigluQuantTransposeFusionPass | ||
| 2 | + | ||
| 3 | +## 融合模式 | ||
| 4 | + | ||
| 5 | +下图中的 `[Bitcast]` 表示可选节点,存在时保留,不由本 Pass 消除;不存在时直接连接对应源节点。图中的 Transpose 也可为 TransposeD。 | ||
| 6 | + | ||
| 7 | +所有模式均不改动 x、x_scale 等其他输入。融合成功后,将算子的 `transpose_weight` 从 `false` 设置为 `true`,由算子承担 weight 的转置语义。 | ||
| 8 | + | ||
| 9 | +### 非 MX 量化 | ||
| 10 | + | ||
| 11 | +非 MX 场景只融合 weight 侧的转置链,不改动 weight_scale 侧的连接和节点。 | ||
| 12 | + | ||
| 13 | +融合模式一:weight 经过单个 Transpose 或转置等价的 Reshape,消除该转置类节点,保留可选 Bitcast。 | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | +融合模式二:weight 经过 Reshape → Transpose → Reshape,整条链等价于 weight 的轴交换时,消除这三个节点,保留可选 Bitcast。 | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +### MX 量化 | ||
| 22 | + | ||
| 23 | +#### 可融合转置链 | ||
| 24 | + | ||
| 25 | +MX 场景要求 weight 和 weight_scale 两侧均匹配到可融合转置链,才配套融合。可融合转置链有以下两类。 | ||
| 26 | + | ||
| 27 | +第一类:单个 Transpose/TransposeD,或转置等价的单个 Reshape。 | ||
| 28 | + | ||
| 29 | +“转置等价的单个 Reshape”指待交换的两个维度中至少有一个为 1,仅改变 shape、不重排数据即可得到与转置相同的结果。例如,weight 从 `[2, 128, 1]` Reshape 为 `[2, 1, 128]`,等价于交换最后两个维度。 | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +第二类:Reshape → Transpose/TransposeD → Reshape。整条链须满足指定轴交换的 shape 和排列检查,不能将任意三节点链当作可融合结构。 | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + | ||
| 37 | +例如,weight 的 `[1, 128, 256] → [128, 256] → [256, 128] → [1, 256, 128]`,以及 MX scale 的 `[1, 128, 4, 2] → [128, 4, 2] → [4, 128, 2] → [1, 4, 128, 2]`,分别表示先去掉单位 group 轴、完成转置、再恢复 group 轴。 | ||
| 38 | + | ||
| 39 | +两侧可以分别选择不同结构:均为第一类、均为第二类,或一侧第一类、另一侧第二类。下文用“可融合转置链”统一表示这两类结构,不再逐一展开组合。 | ||
| 40 | + | ||
| 41 | +#### MXFP8 | ||
| 42 | + | ||
| 43 | +下图中,weight 侧没有 Bitcast,weight_scale 使用字节载体,通过 Bitcast 解释为 E8M0。 | ||
| 44 | + | ||
| 45 | +融合时,配套消除两侧的可融合转置链。融合后 weight 直接连接算子,weight_scale 仍经 Bitcast 连接算子。 | ||
| 46 | + | ||
| 47 | + | ||
| 48 | + | ||
| 49 | +#### MXFP4 | ||
| 50 | + | ||
| 51 | +下图表示 weight 使用字节载体、经 Bitcast 和尾部 Reshape 恢复逻辑 FP4 shape,weight_scale 经 Bitcast 解释为 E8M0 的调用路径。 | ||
| 52 | + | ||
| 53 | +融合时,配套消除 weight、weight_scale 的可融合转置链;保留 weight 的 Bitcast、尾部打包 Reshape,以及 weight_scale 的 Bitcast,并更新打包链的 shape、输入描述及相关 Shape 依赖。 | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + | ||
| 57 | +weight 的尾部打包 Reshape 不属于“可融合转置链”,不能随转置链一起删除。 | ||
| 58 | + | ||
| 59 | +## 使用约束 | ||
| 60 | + | ||
| 61 | +- 算子的 `transpose_weight` 属性须为 `false`,融合后设为 `true`;已为 `true` 时不再融合。 | ||
| 62 | + | ||
| 63 | +## 支持的型号 | ||
| 64 | + | ||
| 65 | +<!-- npu="950" id1 --> | ||
| 66 | +Ascend 950PR/Ascend 950DT | ||
| 67 | +<!-- end id1 --> | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +# QuantGroupedMatmulInplaceAddTransposeFusionPass | ||
| 2 | + | ||
| 3 | +## 融合模式 | ||
| 4 | + | ||
| 5 | +该融合 Pass 提供融合 Transpose、Reshape 节点的两种模式,参考下图。图中的 Transpose 也可为 TransposeD。 | ||
| 6 | + | ||
| 7 | +融合模式一:TT/TC量化场景下,消除 x1 前的转置类节点;若有 Bitcast 则保留,否则将源节点直接连接到算子输入。 | ||
| 8 | + | ||
| 9 | + | ||
| 10 | + | ||
| 11 | +融合模式二:MX 量化场景下,配套消除 x1 和 scale1 前的转置类节点;各侧若有 Bitcast 则保留,否则将源节点直接连接到对应算子输入。 | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +## 支持的型号 | ||
| 16 | + | ||
| 17 | +<!-- npu="950" id1 --> | ||
| 18 | +Ascend 950PR/Ascend 950DT | ||
| 19 | +<!-- end id1 --> | ||