Merged
图融合引用文档 #6701
yuwang-Add on 17 days ago
图融合引用文档 #6701
Merged
yuwang-Add on 17 days ago
Total: 8 files changed+153-0
@@ -0,0 +1,87 @@
1+# PermuteFusionPass
2+ 
3+<!-- md-trans-meta sourceCommit=unknown translatedAt=2026-10-12T17:03:49.766Z pushedAt=2026-10-13T01:47:29.754Z -->
4+ 
5+## Fusion Pattern
6+ 
7+This fusion replaces the Permute operator in the graph with the TransposeD or Transpose operator. The replacement method depends on the running platform:
8+ 
9+<!-- npu="A3,910b,910,310p,310b" id16 -->
10+**Use case 1**:
11+ 
12+<!-- npu="A3,910b,910,310p,310b" id14 -->
13+Permute is replaced with the TransposeD operator. The dimension permutation attribute of Permute is passed as the `perm` attribute of TransposeD.
14+The supported platforms are as follows:
15+<!-- end id14 -->
16+<!-- npu="A3" id7 -->
17+Atlas A3 products
18+<!-- end id7 -->
19+<!-- npu="910b" id8 -->
20+Atlas A2 products
21+<!-- end id8 -->
22+<!-- npu="310b" id9 -->
23+Atlas 200I/500 A2 inference products
24+<!-- end id9 -->
25+<!-- npu="310p" id10 -->
26+Atlas inference products
27+<!-- end id10 -->
28+<!-- npu="910" id11 -->
29+Atlas training products
30+<!-- end id11 -->
31+ 
32+The graph structures before and after fusion are as follows:
33+ 
34+![](../../../docs/en/figures/PermuteFusionPass_1.png)
35+<!-- end id16 -->
36+ 
37+<!-- npu="950" id15 -->
38+**Use case 2**:
39+ 
40+<!-- npu="950" id13 -->
41+Replace Permute with the Transpose operator. The dimension permutation attribute of Permute is passed as a Const node to the `perm` input of Transpose.
42+Supported products are as follows:
43+<!-- end id13 -->
44+ 
45+<!-- npu="950" id12 -->
46+Ascend 950PR&950DT products
47+<!-- end id12 -->
48+ 
49+The graph structures before and after fusion are as follows:
50+ 
51+![](../../../docs/en/figures/PermuteFusionPass_2.png)
52+<!-- end id15 -->
53+ 
54+The dimension permutation order of the Permute operator is preferentially read from the `perm` attribute. If the attribute does not exist, the `order` attribute is read. The shape and dtype of the output after replacement are the same as those of the original Permute output.
55+ 
56+## Constraints
57+ 
58+- Structural constraints:
59+ - The graph contains a Permute operator, with input x and output y.
60+ - The Permute operator must carry the `perm` or `order` attribute to specify the dimension permutation order. The attribute value must be a valid full permutation of the dimensions of x, without repetition or omission.
61+- Version constraint: The fusion takes effect when the GE compiler version is 9.1.0 or later.
62+ 
63+## Applicable Products
64+ 
65+<!-- npu="310b" id1 -->
66+Atlas 200I/500 A2 inference products
67+<!-- end id1 -->
68+ 
69+<!-- npu="310p" id2 -->
70+Atlas inference products
71+<!-- end id2 -->
72+ 
73+<!-- npu="910" id3 -->
74+Atlas training products
75+<!-- end id3 -->
76+ 
77+<!-- npu="910b" id4 -->
78+Atlas A2 products
79+<!-- end id4 -->
80+ 
81+<!-- npu="A3" id5 -->
82+Atlas A3 products
83+<!-- end id5 -->
84+ 
85+<!-- npu="950" id6 -->
86+Ascend 950PR&950DT products
87+<!-- end id6 -->
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:dd43e69a6b30987d5fe9c4fd0b97c56f6c285fba583d697d48f9de512fea08dc
3+size 18794
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:d739524c54e0d17c3573d3c45ab7a6825af904fcae5689893c04bd1863909941
3+size 17445
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:a0360e2060f9f8ca37d3389776e85cb60edc54403c23ef6a61fd7eb82f12ccfd
3+size 19963
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:a32bfe75be6af51d87f9ca29a1f8ee4ba354a697e168f4c2f64e071ac3e7aa24
3+size 22466
@@ -0,0 +1,3 @@
1+version https://git-lfs.github.com/spec/v1
2+oid sha256:451d1c0c02a0a02ca2fdc9b1e7f20d0ddf02436a318cb7029e492b2e5d6a75e8
3+size 26092
@@ -0,0 +1,21 @@
1+# Globalavgpoolpass
2+ 
3+<!-- md-trans-meta sourceCommit=unknown translatedAt=2026-10-12T16:56:50.046Z pushedAt=2026-10-13T01:47:29.733Z -->
4+ 
5+## Fusion Pattern
6+ 
7+This fusion replaces the `GlobalAveragePool` operator in the graph with the `ReduceMean` operator, which computes the mean along the spatial dimensions (all dimensions from the second one onward), as shown in the following figure.
atomgit-bot
atomgit-botatomgit-bot17 days ago

🟡 Medium Priority

变更行:math/reduce_mean/docs/GlobalavgpoolFusionPass_en.md:7 新增「computes the mean along the spatial dimensions (all dimensions from the second one onward)」。

问题链路:GlobalAveragePool 的语义是沿空间维度(NCHW 下的 H、W)求均值,输出仍保留 batch(N) 与 channel(C) 维,即归约轴为 {2,…,n-1};而该句把归约范围写成「从第 2 维起的所有维度」= {1,…,n-1},等于把 channel 维也一起平均掉,描述出的计算与 GlobalAveragePool 标准语义(输出 N×C×1×1)不一致。

失败模式:读者按此文档理解融合后 ReduceMean 的 axes,会认为 C 维被压平;若下游按此理解做 shape 推导、对齐适配层或编写校验用例,就会出现 shape/数值预期错误(例如期望输出为 N×1×1 而实际为 N×C×1×1)。触发条件:任何 4D NCHW 输入阅读该文档并据此推导输出形状。由于本环境无法读取 pass 实现核对实际 axes,置信度已下调,但即便是实现侧真的传 axes={1..n-1},该实现同样与 GlobalAveragePool 语义不符,仍需修正。

建议:核对 pass 实际传入的 axes 后修正该句:GlobalAveragePool 只沿空间维(NCHW 的 H、W,即从第三维起)求均值并保留 batch/channel 维;建议直接写出 axes 取值,避免「from the second one onward」这种会吞掉 channel 维的表述。

likedislike
Incorrect?
8+ 
9+![](../../../docs/en/figures/GlobalavgpoolFusionPass.png)
10+ 
11+After the replacement, the attributes of `ReduceMean` are set to `keep_dims=true` and `noop_with_empty_axes=true`.
12+ 
13+## Constraints
14+ 
15+- Version constraint: The fusion takes effect when the GE compiler version is not lower than 9.1.0.
16+- Input dimension constraint: The input `x` of `GlobalAveragePool` must be 3D, 4D, or 5D. Inputs of other dimensions are not fused.
17+- Data types and data formats follow the constraints of the underlying `GlobalAveragePool`/`ReduceMean` operators.
18+ 
19+## Applicable Products
20+ 
21+This fusion rule is platform-independent. For the specific supported models, see the Applicable Products of the underlying `GlobalAveragePool` and `ReduceMean` operators.
@@ -0,0 +1,30 @@
1+# ReduceMeanWithCastFusionPass
2+ 
3+<!-- md-trans-meta sourceCommit=unknown translatedAt=2026-10-12T17:09:24.202Z pushedAt=2026-10-13T01:47:29.768Z -->
4+ 
5+## Fusion Pattern
6+ 
7+This fusion decomposes the `ReduceMeanWithCast` operator in the graph into `Cast` + `ReduceMean`. When `ReduceMeanWithCast` carries a valid `dtype` attribute (not `DT_UNDEFINED`), a `Cast` node is inserted first to convert the input to the target data type, and then `ReduceMean` is connected. When `dtype` is `DT_UNDEFINED`, no `Cast` is inserted, and the operator is directly replaced with `ReduceMean`.
8+ 
9+**Use case 1: dtype is valid (Cast is inserted)**
10+ 
11+![](../../../docs/en/figures/ReduceMeanWithCastFusionPass_1.png)
12+ 
13+**Use case 2: dtype is DT_UNDEFINED (Cast is not inserted)**
14+ 
15+![](../../../docs/en/figures/ReduceMeanWithCastFusionPass_2.png)
16+ 
17+After the replacement, the `keep_dims` and `noop_with_empty_axes` attributes of `ReduceMean` are inherited from the original `ReduceMeanWithCast` node, and `dst_type` of `Cast` takes the value of the `dtype` attribute of the original node.
18+ 
19+## Constraints
20+ 
21+- Version constraint: The fusion takes effect when the GE compiler version is 9.1.0 or later.
22+- Attribute constraints:
23+ - `keep_dims`: Boolean. Default value: `false`. It is inherited as-is by `ReduceMean`.
24+ - `noop_with_empty_axes`: Boolean, defaults to `true`, inherited as-is by `ReduceMean`.
25+ - `dtype`: target data type, defaults to `DT_UNDEFINED`. If the value is `DT_UNDEFINED`, no `Cast` is inserted; otherwise, `Cast` is inserted and the value is used as `dst_type`.
26+- Input shape and data type are not validated. Relevant constraints follow those of the underlying `Cast` and `ReduceMean` operators.
27+ 
28+## Applicable Products
29+ 
30+This fusion rule is platform-independent. The supported models depend on the applicable products of the underlying `Cast` and `ReduceMean` operators.