From 205b3d7a74451af873c727133f554f1d6d5677f6 Mon Sep 17 00:00:00 2001 From: shaoshengqi Date: Fri, 1 Aug 2025 17:33:52 +0800 Subject: [PATCH] change 'GRAPH_MODE' to '@jit' in mindir.md --- .../source_en/debug/error_analysis/mindir.md | 851 ++++++++++-------- .../debug/error_analysis/mindir.md | 851 ++++++++++-------- 2 files changed, 904 insertions(+), 798 deletions(-) diff --git a/tutorials/source_en/debug/error_analysis/mindir.md b/tutorials/source_en/debug/error_analysis/mindir.md index 8e4698e6fe..f964394d1d 100644 --- a/tutorials/source_en/debug/error_analysis/mindir.md +++ b/tutorials/source_en/debug/error_analysis/mindir.md @@ -4,7 +4,7 @@ ## Overview -When a model compiled using MindSpore runs in the graph mode `set_context(mode=GRAPH_MODE)` and setting the environment variable `MS_DEV_SAVE_GRAPHS` to 2, some intermediate files will be generated during graph compilation. These intermediate files are called IR files. Currently, there are two IR files: +When a model compiled using MindSpore runs in the Just-In-Time Compilation (JIT) mode and setting the environment variable `MS_DEV_SAVE_GRAPHS` to 2, some intermediate files will be generated during graph compilation. These intermediate files are called IR files. Currently, there are two IR files: - .ir file: An IR file that describes the model structure in text format and can be directly viewed using any text editors. - .dot file: When setting the environment variable `MS_DEV_SAVE_GRAPHS` to 3, an IR file that describes the topology relationships between different nodes. You can use this file by [graphviz](http://graphviz.org/) as the input to generate images for users to view the model structure. @@ -59,11 +59,9 @@ The following is an example to describe the contents of the IR file. Run the scr ```python import os -import mindspore as ms -import mindspore.nn as nn -from mindspore import ops +import mindspore +from mindspore import nn, ops -ms.set_context(mode=ms.GRAPH_MODE) os.environ['MS_DEV_SAVE_GRAPHS'] = '2' os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' @@ -74,6 +72,7 @@ class Net(nn.Cell): def func(x, y): return ops.div(x, y) + @mindspore.jit def construct(self, x, y): a = ops.sub(x, 1) b = ops.add(a, y) @@ -81,8 +80,8 @@ class Net(nn.Cell): b = ops.mul(b, self.func(a, b)) return b -input1 = ms.Tensor(3, ms.float32) -input2 = ms.Tensor(2, ms.float32) +input1 = mindspore.tensor(3, mindspore.float32) +input2 = mindspore.tensor(2, mindspore.float32) net = Net() out = net(input1, input2) print(out) @@ -90,7 +89,7 @@ print(out) ### ir Introduction -Use a text editing software (for example, `vi`) to open the `18_execute_0161.ir` file output after execution. The file contents are as follows (Here is MindSpore 2.3, and the content may have some imperceptible changes with the version upgrade): +Use a text editing software (for example, `vi`) to open the `18_execute_0161.ir` file output after execution. The file contents are as follows: ```text 1 # IR entry: @19_1___main___Net_construct_304 @@ -277,440 +276,494 @@ In the graph compilation process, MindSpore often reports a graph derivation fai ### Example 1: parameters number mismatch ```python - 1 import os - 2 import mindspore as ms - 3 import mindspore.nn as nn - 4 from mindspore import ops - 5 - 6 ms.set_context(mode=ms.GRAPH_MODE) - 7 os.environ['MS_DEV_SAVE_GRAPHS'] = '2' - 8 os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' - 9 - 10 class Net(nn.Cell): - 11 def __init__(self): - 12 super().__init__() - 13 - 14 def func(x, y): - 15 return ops.div(x, y) - 16 - 17 def construct(self, x, y): - 18 a = ops.sub(x, 1) - 19 b = ops.add(a, y) - 20 c = ops.mul(b, self.func(a, a, b)) - 21 - 22 input1 = ms.Tensor(3, ms.float32) - 23 input2 = ms.Tensor(2, ms.float32) - 24 net = Net() - 25 out = net(input1, input2) - 26 print(out) +import os +import mindspore +from mindspore import nn, ops + +os.environ['MS_DEV_SAVE_GRAPHS'] = '2' +os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' + +class Net(nn.Cell): + def __init__(self): + super().__init__() + + def func(x, y): + return ops.div(x, y) + + @mindspore.jit + def construct(self, x, y): + a = ops.sub(x, 1) + b = ops.add(a, y) + c = ops.mul(b, self.func(a, a, b)) + +input1 = mindspore.tensor(3, mindspore.float32) +input2 = mindspore.tensor(2, mindspore.float32) +net = Net() +out = net(input1, input2) +print(out) ``` An error happens. ```text 1 Traceback (most recent call last): - 2 File "t2.py", line 23, in + 2 File "/workspace/mindspore/test2.py", line 24, in 3 out = net(input1, input2) - 4 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 701, in __call__ - 5 out = self.compile_and_run(*args, **kwargs) - 6 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1051, in compile_and_run - 7 self.compile(*args, **kwargs) - 8 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1034, in compile - 9 _cell_graph_executor.compile(self, *self._compile_args, phase=self.phase, - 10 File "/workspace/mindspore/build/package/mindspore/common/api.py", line 1815, in compile - 11 result = self._graph_executor.compile(obj, args, kwargs, phase, self._use_vm_mode()) - 12 TypeError: The parameters number of the function is 2, but the number of provided arguments is 3. - 13 FunctionGraph ID : func_40 - 14 NodeInfo: In file t2.py:12~13, 4~28 - 15 def func(x, y): - 16 - 17 ---------------------------------------------------- - 18 - C++ Call Stack: (For framework developers) - 19 ---------------------------------------------------- - 20 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:104 DoJump - 21 - 22 ---------------------------------------------------- - 23 - The Traceback of Net Construct Code: - 24 ---------------------------------------------------- - 25 # 0 In file t2.py:18, 23~41 - 26 c = ops.mul(b, self.func(a, a, b)) - 27 ^~~~~~~~~~~~~~~~~~ - 28 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) + 4 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/nn/cell.py", line 1338, in __call__ + 5 return self.construct(*args, **kwargs) + 6 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 1090, in staging_specialize + 7 out = jit_executor(*args, **kwargs) + 8 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 180, in wrapper + 9 results = fn(*arg, **kwargs) + 10 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 667, in __call__ + 11 raise err + 12 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 663, in __call__ + 13 phase = self.compile(self.fn.__name__, *args_list, **kwargs) + 14 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 781, in compile + 15 is_compile = self._graph_executor.compile( + 16 TypeError: The parameters number of the function is 2, but the number of provided arguments is 3. + 17 FunctionGraph ID : func_7 + 18 NodeInfo: In file /workspace/mindspore/test2.py:12~13, 4~28 + 19 def func(x, y): + 20 + 21 ---------------------------------------------------- + 22 - C++ Call Stack: (For framework developers) + 23 ---------------------------------------------------- + 24 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:98 DoJump + 25 + 26 ---------------------------------------------------- + 27 - The Traceback of Net Construct Code: + 28 ---------------------------------------------------- + 29 # 0 In file /workspace/mindspore/test2.py:19, 23~41 + 30 c = ops.mul(b, self.func(a, a, b)) + 31 ^~~~~~~~~~~~~~~~~~ + 32 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) ``` Above exception is "TypeError: The parameters number of the function is 2, but the number of provided arguments is 3...". -And it tells us `FunctionGraph ID : func_40` only needs two parameters, but actually gives 3. From "The function call stack ...", we know that the error code is: "In file t2.py:18 ... self.func(a, a, b)", because the function call too many parameters. +And it tells us `FunctionGraph ID : func_7` only needs two parameters, but actually gives 3. From "The Traceback of Net Construct Code ...", we know that the error code is: "In file /workspace/mindspore/test2.py:19 ... self.func(a, a, b)", because the function call too many parameters. -Sometimes when the exception information is not enough easy to understand, or we want to see the part of graph information that have evaluated, we use text editing software (e.g., vi) to open the file (in parentheses on line 28) that prompts in the error message: `/workspace/mindspore/rank_0/om/analyze_fail.ir` with the following additional content (Here is MindSpore 2.3, and the content may have some imperceptible changes with the version upgrade): +Sometimes when the exception information is not enough easy to understand, or we want to see the part of graph information that have evaluated, we use text editing software (e.g., vi) to open the file (in parentheses on line 32) that prompts in the error message: `/workspace/mindspore/rank_0/om/analyze_fail.ir` with the following additional content: ```text 1 # =============================================================================================== - 2 # The following shows the IR when the function graphs evaluation fails to help locate the problem. - 3 # You can search the last ------------------------> to the node which is evaluated failure. - 4 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. - 5 # =============================================================================================== - 6 - 7 # IR entry: @__main___Net_construct_11 - 8 # Total subgraphs: 0 - 9 - 10 # Total params: 2 - 11 # Params: - 12 %para1_x: - 13 %para2_y: - 14 - 15 subgraph attr: - 16 subgraph instance: __main___Net_construct_11 : 0x12fb85c18 - 17 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 18 subgraph @__main___Net_construct_11() { - 19 %0(CNode_3) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) - 20 : (, ) -> () - 21 #scope: (Default) - 22 - 23 #------------------------> 0 - 24 %1(CNode_2) = %0(%para1_x, %para2_y) - 25 : (, ) -> () - 26 #scope: (Default) - 27 Return(%1) - 28 : () - 29 #scope: (Default) - 30 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 31 } - 32 # Order: - 33 # 1: @__main___Net_construct_11:CNode_3{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} - 34 # 2: @__main___Net_construct_11:CNode_2{[0]: CNode_3, [1]: param_x, [2]: param_y} - 35 # 3: @__main___Net_construct_11:CNode_44{[0]: ValueNode Return, [1]: CNode_2} - 36 - 37 - 38 subgraph attr: - 39 subgraph instance: __main___Net_construct_11 : 0x12fac0218 - 40 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 41 subgraph @__main___Net_construct_11(%para0_x, %para0_y) { - 42 %0(CNode_12) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) - 43 : (, ) -> () - 44 #scope: (Default) - 45 # In file t2.py:16, 12~15/ a = ops.sub(x, 1)/ - 46 %1(CNode_17) = getattr(%0, "mul") - 47 : (, ) -> () - 48 #scope: (Default) - 49 # In file t2.py:18, 12~19/ c = ops.mul(b, self.func(a, a, b))/ - 50 %2(CNode_15) = getattr(%0, "add") - 51 : (, ) -> () - 52 #scope: (Default) - 53 # In file t2.py:17, 12~19/ b = ops.add(a, y)/ - 54 %3(CNode_13) = getattr(%0, "sub") - 55 : (, ) -> () - 56 #scope: (Default) - 57 # In file t2.py:16, 12~19/ a = ops.sub(x, 1)/ - 58 %4(a) = %3(%para0_x, I64(1)) - 59 : (, ) -> () - 60 #scope: (Default) - 61 # In file t2.py:16, 12~25/ a = ops.sub(x, 1)/ - 62 %5(b) = %2(%4, %para0_y) - 63 : (, ) -> () - 64 #scope: (Default) - 65 # In file t2.py:17, 12~25/ b = ops.add(a, y)/ - 66 %6(CNode_18) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], func) - 67 : (, ) -> () + 2 # The following shows the last analyze fail log message. + 3 # =============================================================================================== + 4 + 5 ---------------------------------------------------- + 6 - Caught exception: + 7 ---------------------------------------------------- + 8 The parameters number of the function is 2, but the number of provided arguments is 3. + 9 FunctionGraph ID : func_7 + 10 NodeInfo: In file /workspace/mindspore/test2.py:12~13, 4~28 + 11 def func(x, y): + 12 + 13 ---------------------------------------------------- + 14 - C++ Call Stack: (For framework developers) + 15 ---------------------------------------------------- + 16 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:98 DoJump + 17 + 18 ---------------------------------------------------- + 19 - The Traceback of Net Construct Code: + 20 ---------------------------------------------------- + 21 # 0 In file /workspace/mindspore/test2.py:19, 23~41 + 22 c = ops.mul(b, self.func(a, a, b)) + 23 ^~~~~~~~~~~~~~~~~~ + 24 + 25 # =============================================================================================== + 26 # The following shows the IR when the function graphs evaluation fails to help locate the problem. + 27 # You can search the last ------------------------> to the node which is evaluated failure. + 28 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. + 29 # =============================================================================================== + 30 + 31 # IR entry: @__main___Net_construct_8 + 32 # Total subgraphs: 0 + 33 + 34 # Total params: 2 + 35 # Params: + 36 %para1_x: + 37 %para2_y: + 38 + 39 subgraph attr: + 40 subgraph instance: __main___Net_construct_8 : 0xf1667a0 + 41 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 42 subgraph @__main___Net_construct_8() { + 43 %0(CNode_1) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) + 44 : (, ) -> () + 45 #scope: (Default) + 46 + 47 #------------------------> 0 + 48 %1(CNode_2) = %0(%para1_x, %para2_y) + 49 : (, ) -> () + 50 #scope: (Default) + 51 Return(%1) + 52 : () + 53 #scope: (Default) + 54 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 55 } + 56 # Order: + 57 # 1: @__main___Net_construct_8:CNode_1{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} + 58 # 2: @__main___Net_construct_8:CNode_2{[0]: CNode_1, [1]: param_x, [2]: param_y} + 59 # 3: @__main___Net_construct_8:CNode_9{[0]: ValueNode Return, [1]: CNode_2} + 60 + 61 + 62 subgraph attr: + 63 subgraph instance: __main___Net_construct_8 : 0xf4c9fb0 + 64 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 65 subgraph @__main___Net_construct_8(%para0_x, %para0_y) { + 66 %0(CNode_10) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) + 67 : (, ) -> () 68 #scope: (Default) - 69 # In file t2.py:18, 23~32/ c = ops.mul(b, self.func(a, a, b))/ - 70 - 71 #------------------------> 1 - 72 %7(CNode_19) = %6(%4, %4, %5) - 73 : (, , ) -> () - 74 #scope: (Default) - 75 # In file t2.py:18, 23~41/ c = ops.mul(b, self.func(a, a, b))/ - 76 %8(c) = %1(%5, %7) - 77 : (, ) -> () - 78 #scope: (Default) - 79 # In file t2.py:18, 12~42/ c = ops.mul(b, self.func(a, a, b))/ - 80 %9(CNode_22) = StopGradient(%8) - 81 : () -> () - 82 #scope: (Default) - 83 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 84 %10(CNode_21) = Depend(None, %9) primitive_attrs: {side_effect_propagate: I64(1)} cnode_attrs: {topo_sort_rhs_first: Bool(1)} - 85 : (, ) -> () - 86 #scope: (Default) - 87 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 88 Return(%10) - 89 : () - 90 #scope: (Default) - 91 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 92 } - 93 # Order: - 94 # 1: @__main___Net_construct_11:CNode_12{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} - 95 # 2: @__main___Net_construct_11:CNode_13{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode sub} - 96 # 3: @__main___Net_construct_11:CNode_45{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 97 # 5: @__main___Net_construct_11:a{[0]: CNode_13, [1]: param_x, [2]: ValueNode 1} - 98 # 6: @__main___Net_construct_11:CNode_15{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode add} - 99 # 7: @__main___Net_construct_11:CNode_46{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -100 # 9: @__main___Net_construct_11:b{[0]: CNode_15, [1]: a, [2]: param_y} -101 # 10: @__main___Net_construct_11:CNode_17{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode mul} -102 # 11: @__main___Net_construct_11:CNode_18{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode func} -103 # 12: @__main___Net_construct_11:CNode_47{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -104 # 14: @__main___Net_construct_11:CNode_19{[0]: CNode_18, [1]: a, [2]: a, [3]: b} -105 # 15: @__main___Net_construct_11:CNode_48{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -106 # 17: @__main___Net_construct_11:c{[0]: CNode_17, [1]: b, [2]: CNode_19} -107 # 19: @__main___Net_construct_11:CNode_44{[0]: ValueNode Return, [1]: CNode_21} -108 -109 -110 # =============================================================================================== -111 # The total of function graphs in evaluation stack: 2 -112 # =============================================================================================== -113 -114 -115 # =============================================================================================== -116 # The rest function graphs are the following: -117 # =============================================================================================== -118 No more function graphs. + 69 # In file /workspace/mindspore/test2.py:17, 12~15/ a = ops.sub(x, 1)/ + 70 %1(CNode_11) = getattr(%0, "mul") + 71 : (, ) -> () + 72 #scope: (Default) + 73 # In file /workspace/mindspore/test2.py:19, 12~19/ c = ops.mul(b, self.func(a, a, b))/ + 74 %2(CNode_12) = getattr(%0, "add") + 75 : (, ) -> () + 76 #scope: (Default) + 77 # In file /workspace/mindspore/test2.py:18, 12~19/ b = ops.add(a, y)/ + 78 %3(CNode_13) = getattr(%0, "sub") + 79 : (, ) -> () + 80 #scope: (Default) + 81 # In file /workspace/mindspore/test2.py:17, 12~19/ a = ops.sub(x, 1)/ + 82 %4(a) = %3(%para0_x, I64(1)) + 83 : (, ) -> () + 84 #scope: (Default) + 85 # In file /workspace/mindspore/test2.py:17, 12~25/ a = ops.sub(x, 1)/ + 86 %5(b) = %2(%4, %para0_y) + 87 : (, ) -> () + 88 #scope: (Default) + 89 # In file /workspace/mindspore/test2.py:18, 12~25/ b = ops.add(a, y)/ + 90 %6(CNode_14) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], func) + 91 : (, ) -> () + 92 #scope: (Default) + 93 # In file /workspace/mindspore/test2.py:19, 23~32/ c = ops.mul(b, self.func(a, a, b))/ + 94 + 95 #------------------------> 1 + 96 %7(CNode_15) = %6(%4, %4, %5) + 97 : (, , ) -> () + 98 #scope: (Default) + 99 # In file /workspace/mindspore/test2.py:19, 23~41/ c = ops.mul(b, self.func(a, a, b))/ +100 %8(c) = %1(%5, %7) +101 : (, ) -> () +102 #scope: (Default) +103 # In file /workspace/mindspore/test2.py:19, 12~42/ c = ops.mul(b, self.func(a, a, b))/ +104 %9(CNode_16) = StopGradient(%8) +105 : () -> () +106 #scope: (Default) +107 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +108 %10(CNode_17) = Depend(None, %9) primitive_attrs: {side_effect_propagate: I64(1)} cnode_attrs: {topo_sort_rhs_first: Bool(1)} +109 : (, ) -> () +110 #scope: (Default) +111 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +112 Return(%10) +113 : () +114 #scope: (Default) +115 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +116 } +117 # Order: +118 # 1: @__main___Net_construct_8:CNode_10{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} +119 # 2: @__main___Net_construct_8:CNode_13{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode sub} +120 # 3: @__main___Net_construct_8:CNode_18{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +121 # 5: @__main___Net_construct_8:a{[0]: CNode_13, [1]: param_x, [2]: ValueNode 1} +122 # 6: @__main___Net_construct_8:CNode_12{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode add} +123 # 7: @__main___Net_construct_8:CNode_19{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +124 # 9: @__main___Net_construct_8:b{[0]: CNode_12, [1]: a, [2]: param_y} +125 # 10: @__main___Net_construct_8:CNode_11{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode mul} +126 # 11: @__main___Net_construct_8:CNode_14{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode func} +127 # 12: @__main___Net_construct_8:CNode_20{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +128 # 14: @__main___Net_construct_8:CNode_15{[0]: CNode_14, [1]: a, [2]: a, [3]: b} +129 # 15: @__main___Net_construct_8:CNode_21{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +130 # 17: @__main___Net_construct_8:c{[0]: CNode_11, [1]: b, [2]: CNode_15} +131 # 19: @__main___Net_construct_8:CNode_9{[0]: ValueNode Return, [1]: CNode_17} +132 +133 +134 # =============================================================================================== +135 # The total of function graphs in evaluation stack: 2 +136 # =============================================================================================== +137 +138 +139 # =============================================================================================== +140 # The rest function graphs are the following: +141 # =============================================================================================== +142 No more function graphs. ``` The file `analyze_fail.ir` has the same information format with ir file. The only difference is `analyze_fail.ir` will locate the node which inferring failed. -Searching the point by the text of `------------------------>`, we reach `------------------------> 1` at line 71. This points to the node that derives the error, which is `%7(CNode_19) = %6(%4, %4, %5) ....`. We can know the node have 3 parameters from `(%4, %4, %5)`. From the source parsing call stack, it can be known that the function is actually `self.func`, which is defined in the script as `def func(x, y):...`. In the function definition, only two parameters are needed, so there will be a deduction failure error, and we need to modify the number of parameters passed in the script to solve the problem. +Searching the point by the text of `------------------------>`, we reach `------------------------> 1` at line 95. This points to the node that derives the error, which is `%7(CNode_19) = %6(%4, %4, %5) ....`. We can know the node have 3 parameters from `(%4, %4, %5)`. From the source parsing call stack, it can be known that the function is actually `self.func`, which is defined in the script as `def func(x, y):...`. In the function definition, only two parameters are needed, so there will be a deduction failure error, and we need to modify the number of parameters passed in the script to solve the problem. ### Example 2: BiasAdd inputs shape mismatch ```python - 1 import numpy as np - 2 import mindspore as ms - 3 from mindspore import nn, ops, set_context, Tensor, Parameter - 4 from mindspore.common.initializer import initializer - 5 - 6 ms.set_context(mode=ms.GRAPH_MODE) - 7 - 8 class Net(nn.Cell): - 9 def __init__(self): - 10 super(Net, self).__init__() - 11 self.weight = Parameter(initializer('normal', [32, 8]), name="weight") - 12 self.bias = Parameter(initializer('zeros', [4]), name="bias") - 13 - 14 def construct(self, x1): - 15 x = ops.matmul(x1, self.weight) - 16 x = ops.bias_add(x, self.bias) - 17 return x - 18 - 19 net = Net() - 20 x = Tensor(np.arange(3*32).reshape(3, 32), ms.float32) - 21 out = net(x) - 22 print('out', out.shape) +import numpy as np +import mindspore +from mindspore import nn, ops, Tensor, Parameter +from mindspore.common.initializer import initializer + +class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.weight = Parameter(initializer('normal', [32, 8]), name="weight") + self.bias = Parameter(initializer('zeros', [4]), name="bias") + + @mindspore.jit + def construct(self, x1): + x = ops.matmul(x1, self.weight) + x = ops.bias_add(x, self.bias) + return x + +net = Net() +x = mindspore.tensor(np.arange(3*32).reshape(3, 32), mindspore.float32) +out = net(x) +print('out', out.shape) ``` An error happens. ```text 1 Traceback (most recent call last): - 2 File "t2.py", line 21, in + 2 File "/workspace/mindspore/test2.py", line 20, in 3 out = net(x) - 4 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 701, in __call__ - 5 out = self.compile_and_run(*args, **kwargs) - 6 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1051, in compile_and_run - 7 self.compile(*args, **kwargs) - 8 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1034, in compile - 9 _cell_graph_executor.compile(self, *self._compile_args, phase=self.phase, - 10 File "/workspace/mindspore/build/package/mindspore/common/api.py", line 1815, in compile - 11 result = self._graph_executor.compile(obj, args, kwargs, phase, self._use_vm_mode()) - 12 ValueError: For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector]{3, 8}. - 13 - 14 ---------------------------------------------------- - 15 - C++ Call Stack: (For framework developers) - 16 ---------------------------------------------------- - 17 mindspore/core/ops/ops_func_impl/bias_add.cc:71 CheckShapeValid - 18 - 19 ---------------------------------------------------- - 20 - The Traceback of Net Construct Code: - 21 ---------------------------------------------------- - 22 # 0 In file t2.py:16, 11~37 - 23 x = ops.bias_add(x, self.bias) - 24 ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 25 # 1 In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 11~37 - 26 return bias_add_op(input_x, bias) - 27 ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 28 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) + 4 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/nn/cell.py", line 1338, in __call__ + 5 return self.construct(*args, **kwargs) + 6 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 1090, in staging_specialize + 7 out = jit_executor(*args, **kwargs) + 8 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 180, in wrapper + 9 results = fn(*arg, **kwargs) + 10 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 667, in __call__ + 11 raise err + 12 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 663, in __call__ + 13 phase = self.compile(self.fn.__name__, *args_list, **kwargs) + 14 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 781, in compile + 15 is_compile = self._graph_executor.compile( + 16 ValueError: For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector] {3, 8}. + 17 + 18 ---------------------------------------------------- + 19 - C++ Call Stack: (For framework developers) + 20 ---------------------------------------------------- + 21 mindspore/ops/infer/ops_func_impl//bias_add.cc:71 CheckShapeValid + 22 + 23 ---------------------------------------------------- + 24 - The Traceback of Net Construct Code: + 25 ---------------------------------------------------- + 26 # 0 In file /workspace/mindspore/test2.py:15, 12~38 + 27 x = ops.bias_add(x, self.bias) + 28 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 29 # 1 In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37 + 30 return bias_add_op(input_x, bias) + 31 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 32 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) ``` -The above reports that the errors is caused by the mismatching of the shape of the first input and the second input of the operator `BiasAdd`. To further understand what changes have taken place in the shape of the operator, we use text editing software (e.g., vi) to open the file that prompts in the error message: `/workspace/mindspore/rank_0/om/analyze_fail.ir` with the following additional content (Here is MindSpore 2.3, and the content may have some imperceptible changes with the version upgrade): +The above reports that the errors is caused by the mismatching of the shape of the first input and the second input of the operator `BiasAdd`. To further understand what changes have taken place in the shape of the operator, we use text editing software (e.g., vi) to open the file that prompts in the error message: `/workspace/mindspore/rank_0/om/analyze_fail.ir` with the following additional content: ```text 1 # =============================================================================================== - 2 # The following shows the IR when the function graphs evaluation fails to help locate the problem. - 3 # You can search the last ------------------------> to the node which is evaluated failure. - 4 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. - 5 # =============================================================================================== - 6 - 7 # IR entry: @__main___Net_construct_6 - 8 # Total subgraphs: 0 + 2 # The following shows the last analyze fail log message. + 3 # =============================================================================================== + 4 + 5 ---------------------------------------------------- + 6 - Caught exception: + 7 ---------------------------------------------------- + 8 For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector]{3, 8}. 9 - 10 # Total params: 3 - 11 # Params: - 12 %para1_x1: - 13 %para2_weight: : has_default - 14 %para3_bias: : has_default - 15 - 16 subgraph attr: - 17 subgraph instance: __main___Net_construct_6 : 0x128910818 - 18 # In file t2.py:14~17, 4~15/ def construct(self, x1):/ - 19 subgraph @__main___Net_construct_6() { - 20 %0(CNode_3) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) - 21 : (, ) -> () - 22 #scope: (Default) - 23 - 24 #------------------------> 0 - 25 %1(CNode_2) = %0(%para1_x1) - 26 : () -> () - 27 #scope: (Default) - 28 Return(%1) - 29 : () - 30 #scope: (Default) - 31 # In file t2.py:17, 7~15/ return x/ - 32 } - 33 # Order: - 34 # 1: @__main___Net_construct_6:CNode_3{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} - 35 # 2: @__main___Net_construct_6:CNode_2{[0]: CNode_3, [1]: param_x1} - 36 # 3: @__main___Net_construct_6:CNode_162{[0]: ValueNode Return, [1]: CNode_2} - 37 - 38 - 39 subgraph attr: - 40 subgraph instance: __main___Net_construct_6 : 0x14bb64c18 - 41 # In file t2.py:14~17, 4~15/ def construct(self, x1):/ - 42 subgraph @__main___Net_construct_6(%para0_x1) { - 43 %0(CNode_7) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) - 44 : (, ) -> () - 45 #scope: (Default) - 46 # In file t2.py:15, 11~14/ x = ops.matmul(x1, self.weight)/ - 47 %1(CNode_11) = getattr(%0, "bias_add") - 48 : (, ) -> () - 49 #scope: (Default) - 50 # In file t2.py:16, 11~23/ x = ops.bias_add(x, self.bias)/ - 51 %2(CNode_8) = getattr(%0, "matmul") - 52 : (, ) -> () - 53 #scope: (Default) - 54 # In file t2.py:15, 11~21/ x = ops.matmul(x1, self.weight)/ - 55 %3(CNode_9) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], weight) - 56 : (, ) -> () - 57 #scope: (Default) - 58 # In file t2.py:15, 26~37/ x = ops.matmul(x1, self.weight)/ - 59 %4(x) = %2(%para0_x1, %3) - 60 : (, ) -> () - 61 #scope: (Default) - 62 # In file t2.py:15, 11~38/ x = ops.matmul(x1, self.weight)/ - 63 %5(CNode_12) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], bias) - 64 : (, ) -> () - 65 #scope: (Default) - 66 # In file t2.py:16, 27~36/ x = ops.bias_add(x, self.bias)/ - 67 - 68 #------------------------> 1 - 69 %6(x) = %1(%4, %5) - 70 : (, ) -> () - 71 #scope: (Default) - 72 # In file t2.py:16, 11~37/ x = ops.bias_add(x, self.bias)/ - 73 Return(%6) - 74 : () - 75 #scope: (Default) - 76 # In file t2.py:17, 7~15/ return x/ - 77 } - 78 # Order: - 79 # 1: @__main___Net_construct_6:CNode_7{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} - 80 # 2: @__main___Net_construct_6:CNode_8{[0]: ValueNode getattr, [1]: CNode_7, [2]: ValueNode matmul} - 81 # 3: @__main___Net_construct_6:CNode_9{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode weight} - 82 # 4: @__main___Net_construct_6:CNode_163{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 83 # 6: @__main___Net_construct_6:x{[0]: CNode_8, [1]: param_x1, [2]: CNode_9} - 84 # 7: @__main___Net_construct_6:CNode_11{[0]: ValueNode getattr, [1]: CNode_7, [2]: ValueNode bias_add} - 85 # 8: @__main___Net_construct_6:CNode_12{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode bias} - 86 # 9: @__main___Net_construct_6:CNode_164{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 87 # 11: @__main___Net_construct_6:x{[0]: CNode_11, [1]: x, [2]: CNode_12} - 88 # 12: @__main___Net_construct_6:CNode_162{[0]: ValueNode Return, [1]: x} - 89 - 90 - 91 subgraph attr: - 92 subgraph instance: bias_add_14 : 0x128910e18 - 93 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6244~6280, 0~37/def bias_add(input_x, bias):/ - 94 subgraph @bias_add_14(%para0_input_x, %para0_bias) { - 95 %0(CNode_15) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], _get_cache_prim) - 96 : (, ) -> () - 97 #scope: (Default) - 98 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~33/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ - 99 %1(CNode_16) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], P) -100 : (, ) -> () -101 #scope: (Default) -102 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 34~35/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -103 %2(CNode_17) = getattr(%1, "BiasAdd") -104 : (, ) -> () -105 #scope: (Default) -106 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 34~43/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -107 %3(CNode_18) = %0(%2) -108 : () -> () -109 #scope: (Default) -110 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~44/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -111 %4(CNode_131) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], make_dict) -112 : (, ) -> () -113 #scope: (Default) -114 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -115 %5(CNode_132) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) -116 : (, ) -> () -117 #scope: (Default) -118 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -119 %6(CNode_133) = %5("data_format") -120 : () -> () + 10 ---------------------------------------------------- + 11 - C++ Call Stack: (For framework developers) + 12 ---------------------------------------------------- + 13 mindspore/ops/infer/ops_func_impl//bias_add.cc:71 CheckShapeValid + 14 + 15 ---------------------------------------------------- + 16 - The Traceback of Net Construct Code: + 17 ---------------------------------------------------- + 18 # 0 In file /workspace/mindspore/test2.py:15, 12~38 + 19 x = ops.bias_add(x, self.bias) + 20 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 21 # 1 In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37 + 22 return bias_add_op(input_x, bias) + 23 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 24 + 25 # =============================================================================================== + 26 # The following shows the IR when the function graphs evaluation fails to help locate the problem. + 27 # You can search the last ------------------------> to the node which is evaluated failure. + 28 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. + 29 # =============================================================================================== + 30 + 31 # IR entry: @__main___Net_construct_3 + 32 # Total subgraphs: 0 + 33 + 34 # Total params: 3 + 35 # Params: + 36 %para1_x1: + 37 %para2_weight: : has_default + 38 %para3_bias: : has_default + 39 + 40 subgraph attr: + 41 subgraph instance: __main___Net_construct_3 : 0x13bfdd40 + 42 # In file /workspace/mindspore/test2.py:12~16, 4~16/ @mindspore.jit/ + 43 subgraph @__main___Net_construct_3() { + 44 %0(CNode_5) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) + 45 : (, ) -> () + 46 #scope: (Default) + 47 + 48 #------------------------> 0 + 49 %1(CNode_6) = %0(%para1_x1) + 50 : () -> () + 51 #scope: (Default) + 52 Return(%1) + 53 : () + 54 #scope: (Default) + 55 # In file /workspace/mindspore/test2.py:16, 8~16/ return x/ + 56 } + 57 # Order: + 58 # 1: @__main___Net_construct_3:CNode_5{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} + 59 # 2: @__main___Net_construct_3:CNode_6{[0]: CNode_5, [1]: param_x1} + 60 # 3: @__main___Net_construct_3:CNode_7{[0]: ValueNode Return, [1]: CNode_6} + 61 + 62 + 63 subgraph attr: + 64 subgraph instance: __main___Net_construct_3 : 0x13f5fc20 + 65 # In file /workspace/mindspore/test2.py:12~16, 4~16/ @mindspore.jit/ + 66 subgraph @__main___Net_construct_3(%para0_x1) { + 67 %0(CNode_8) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) + 68 : (, ) -> () + 69 #scope: (Default) + 70 # In file /workspace/mindspore/test2.py:14, 12~15/ x = ops.matmul(x1, self.weight)/ + 71 %1(CNode_9) = getattr(%0, "bias_add") + 72 : (, ) -> () + 73 #scope: (Default) + 74 # In file /workspace/mindspore/test2.py:15, 12~24/ x = ops.bias_add(x, self.bias)/ + 75 %2(CNode_10) = getattr(%0, "matmul") + 76 : (, ) -> () + 77 #scope: (Default) + 78 # In file /workspace/mindspore/test2.py:14, 12~22/ x = ops.matmul(x1, self.weight)/ + 79 %3(CNode_11) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], weight) + 80 : (, ) -> () + 81 #scope: (Default) + 82 # In file /workspace/mindspore/test2.py:14, 27~38/ x = ops.matmul(x1, self.weight)/ + 83 %4(x) = %2(%para0_x1, %3) + 84 : (, ) -> () + 85 #scope: (Default) + 86 # In file /workspace/mindspore/test2.py:14, 12~39/ x = ops.matmul(x1, self.weight)/ + 87 %5(CNode_12) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], bias) + 88 : (, ) -> () + 89 #scope: (Default) + 90 # In file /workspace/mindspore/test2.py:15, 28~37/ x = ops.bias_add(x, self.bias)/ + 91 + 92 #------------------------> 1 + 93 %6(x) = %1(%4, %5) + 94 : (, ) -> () + 95 #scope: (Default) + 96 # In file /workspace/mindspore/test2.py:15, 12~38/ x = ops.bias_add(x, self.bias)/ + 97 Return(%6) + 98 : () + 99 #scope: (Default) +100 # In file /workspace/mindspore/test2.py:16, 8~16/ return x/ +101 } +102 # Order: +103 # 1: @__main___Net_construct_3:CNode_8{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} +104 # 2: @__main___Net_construct_3:CNode_10{[0]: ValueNode getattr, [1]: CNode_8, [2]: ValueNode matmul} +105 # 3: @__main___Net_construct_3:CNode_11{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode weight} +106 # 4: @__main___Net_construct_3:CNode_13{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +107 # 6: @__main___Net_construct_3:x{[0]: CNode_10, [1]: param_x1, [2]: CNode_11} +108 # 7: @__main___Net_construct_3:CNode_9{[0]: ValueNode getattr, [1]: CNode_8, [2]: ValueNode bias_add} +109 # 8: @__main___Net_construct_3:CNode_12{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode bias} +110 # 9: @__main___Net_construct_3:CNode_14{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +111 # 11: @__main___Net_construct_3:x{[0]: CNode_9, [1]: x, [2]: CNode_12} +112 # 12: @__main___Net_construct_3:CNode_7{[0]: ValueNode Return, [1]: x} +113 +114 +115 subgraph attr: +116 subgraph instance: bias_add_4 : 0x13f65d00 +117 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7057~7093/def bias_add(input_x, bias):/ +118 subgraph @bias_add_4(%para0_input_x, %para0_bias) { +119 %0(CNode_15) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], _get_cache_prim) +120 : (, ) -> () 121 #scope: (Default) -122 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -123 %7(CNode_135) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) -124 : (, ) -> () +122 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~33/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +123 %1(CNode_16) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], P) +124 : (, ) -> () 125 #scope: (Default) -126 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -127 %8(CNode_136) = %7("NCHW") -128 : () -> () +126 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 34~35/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +127 %2(CNode_17) = getattr(%1, "BiasAdd") +128 : (, ) -> () 129 #scope: (Default) -130 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -131 %9(CNode_21) = %4(%6, %8) -132 : (, ) -> () +130 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 34~43/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +131 %3(CNode_18) = %0(%2) +132 : () -> () 133 #scope: (Default) -134 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -135 %10(bias_add_op) = UnpackCall_unpack_call(%3, %9) -136 : (, ) -> () +134 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~44/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +135 %4(CNode_19) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], make_dict) +136 : (, ) -> () 137 #scope: (Default) -138 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -139 -140 #------------------------> 2 -141 %11(CNode_22) = %10(%para0_input_x, %para0_bias) -142 : (, ) -> () -143 #scope: (Default) -144 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 11~37/ return bias_add_op(input_x, bias)/ -145 Return(%11) -146 : () -147 #scope: (Default) -148 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 4~37/ return bias_add_op(input_x, bias)/ -149 } -150 # Order: -151 # 1: @bias_add_14:CNode_15{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode _get_cache_prim} -152 # 2: @bias_add_14:CNode_16{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode P} -153 # 3: @bias_add_14:CNode_17{[0]: ValueNode getattr, [1]: CNode_16, [2]: ValueNode BiasAdd} -154 # 4: @bias_add_14:CNode_166{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -155 # 6: @bias_add_14:CNode_18{[0]: CNode_15, [1]: CNode_17} -156 # 7: @bias_add_14:CNode_132{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -157 # 8: @bias_add_14:CNode_133{[0]: CNode_132, [1]: ValueNode data_format} -158 # 9: @bias_add_14:CNode_135{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -159 # 10: @bias_add_14:CNode_136{[0]: CNode_135, [1]: ValueNode NCHW} -160 # 11: @bias_add_14:CNode_131{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode make_dict} -161 # 12: @bias_add_14:CNode_21{[0]: CNode_131, [1]: CNode_133, [2]: CNode_136} -162 # 13: @bias_add_14:bias_add_op{[0]: ValueNode MetaFuncGraph-unpack_call.20, [1]: CNode_18, [2]: CNode_21} -163 # 14: @bias_add_14:CNode_167{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -164 # 16: @bias_add_14:CNode_22{[0]: bias_add_op, [1]: param_input_x, [2]: param_bias} -165 # 17: @bias_add_14:CNode_165{[0]: ValueNode Return, [1]: CNode_22} -166 -167 -168 # =============================================================================================== -169 # The total of function graphs in evaluation stack: 3/5 (Ignored 2 internal frames). -170 # =============================================================================================== -171 -172 -173 # =============================================================================================== -174 # The rest function graphs are the following: -175 # =============================================================================================== -176 No more function graphs. +138 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +139 %5(CNode_20) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) +140 : (, ) -> () +141 #scope: (Default) +142 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +143 %6(CNode_21) = %5("data_format") +144 : () -> () +145 #scope: (Default) +146 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +147 %7(CNode_22) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) +148 : (, ) -> () +149 #scope: (Default) +150 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +151 %8(CNode_23) = %7("NCHW") +152 : () -> () +153 #scope: (Default) +154 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +155 %9(CNode_24) = %4(%6, %8) +156 : (, ) -> () +157 #scope: (Default) +158 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +159 %10(bias_add_op) = DoUnpackCall(%3, %9) +160 : (, ) -> () +161 #scope: (Default) +162 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +163 +164 #------------------------> 2 +165 %11(CNode_25) = %10(%para0_input_x, %para0_bias) +166 : (, ) -> () +167 #scope: (Default) +168 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37/ return bias_add_op(input_x, bias)/ +169 Return(%11) +170 : () +171 #scope: (Default) +172 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 4~37/ return bias_add_op(input_x, bias)/ +173 } +174 # Order: +175 # 1: @bias_add_4:CNode_15{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode _get_cache_prim} +176 # 2: @bias_add_4:CNode_16{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode P} +177 # 3: @bias_add_4:CNode_17{[0]: ValueNode getattr, [1]: CNode_16, [2]: ValueNode BiasAdd} +178 # 4: @bias_add_4:CNode_26{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +179 # 6: @bias_add_4:CNode_18{[0]: CNode_15, [1]: CNode_17} +180 # 7: @bias_add_4:CNode_20{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +181 # 8: @bias_add_4:CNode_21{[0]: CNode_20, [1]: ValueNode data_format} +182 # 9: @bias_add_4:CNode_22{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +183 # 10: @bias_add_4:CNode_23{[0]: CNode_22, [1]: ValueNode NCHW} +184 # 11: @bias_add_4:CNode_19{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode make_dict} +185 # 12: @bias_add_4:CNode_24{[0]: CNode_19, [1]: CNode_21, [2]: CNode_23} +186 # 13: @bias_add_4:bias_add_op{[0]: ValueNode DoUnpackCall, [1]: CNode_18, [2]: CNode_24} +187 # 14: @bias_add_4:CNode_27{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +188 # 16: @bias_add_4:CNode_25{[0]: bias_add_op, [1]: param_input_x, [2]: param_bias} +189 # 17: @bias_add_4:CNode_28{[0]: ValueNode Return, [1]: CNode_25} +190 +191 +192 # =============================================================================================== +193 # The total of function graphs in evaluation stack: 3/5 (Ignored 2 internal frames). +194 # =============================================================================================== +195 +196 +197 # =============================================================================================== +198 # The rest function graphs are the following: +199 # =============================================================================================== +200 No more function graphs. ``` -Search `------------------------>` to the position where inferring failed at line 68. According to `...(%4, %5) : (, ) -> (``)`, `BiasAdd`'s inputs are `%4` and `%5`. `%4`' with shape `[3, 8]` and `%5` with shape `[4]` doesn't meet the requirement about `bias (Tensor) - The bias tensor, with shape (C). C must be the same as channel dimension C of input_x...` for `BiasAdd` API. Thus, an error happens. +Search `------------------------>` to the position where inferring failed at line 92. According to `...(%4, %5) : (, ) -> (``)`, `BiasAdd`'s inputs are `%4` and `%5`. `%4`' with shape `[3, 8]` and `%5` with shape `[4]` doesn't meet the requirement about `bias (Tensor) - The bias tensor, with shape (C). C must be the same as channel dimension C of input_x...` for `BiasAdd` API. Thus, an error happens. To solve this problem, we need modify the shape of `%4` or `%5` (namely `self.bias`). - For `%5` (namely `self.bias`), we modify the shape of `self.bias` by `self.bias = Parameter(initializer('zeros', [8]), name="bias")`. -- For `%4`, we need know what `%4` is. According to line 59, `%4` is a `MatMul` with output shape `[3, 8]`. Its inputs are `(%para0_x1, %3)`. The shape of the first input (namely given arg `x`) is `[3, 32]` and the shape of the second input (namely `self.weight`) is `[32, 8]`. To meet the requirement of `BiasAdd` with the data shape `[4]`, the shape of `%4` output needs to be `[3, 4]`. Therefore, we modify `self.weight` by `self.weight = Parameter(initializer('normal', [32, 4]), name="weight")`. +- For `%4`, we need know what `%4` is. According to line 83, `%4` is a `MatMul` with output shape `[3, 8]`. Its inputs are `(%para0_x1, %3)`. The shape of the first input (namely given arg `x`) is `[3, 32]` and the shape of the second input (namely `self.weight`) is `[32, 8]`. To meet the requirement of `BiasAdd` with the data shape `[4]`, the shape of `%4` output needs to be `[3, 4]`. Therefore, we modify `self.weight` by `self.weight = Parameter(initializer('normal', [32, 4]), name="weight")`. diff --git a/tutorials/source_zh_cn/debug/error_analysis/mindir.md b/tutorials/source_zh_cn/debug/error_analysis/mindir.md index 355965e070..ec3be2237d 100644 --- a/tutorials/source_zh_cn/debug/error_analysis/mindir.md +++ b/tutorials/source_zh_cn/debug/error_analysis/mindir.md @@ -4,7 +4,7 @@ ## 概述 -在图模式`set_context(mode=GRAPH_MODE)`下运行用MindSpore编写的模型时,若设置了环境变量`MS_DEV_SAVE_GRAPHS`的值为2,运行时会输出一些图编译过程中生成的中间文件,称为IR文件。当前主要有两种格式的IR文件: +在即时编译(Just-In-Time Compilation,JIT)模式下运行用MindSpore编写的模型时,若设置了环境变量`MS_DEV_SAVE_GRAPHS`的值为2,运行时会输出一些图编译过程中生成的中间文件,称为IR文件。当前主要有两种格式的IR文件: - ir后缀结尾的IR文件:一种比较直观易懂的以文本格式描述模型结构的文件,可以直接用文本编辑软件查看。 - dot后缀结尾的IR文件:若设置了环境变量`MS_DEV_SAVE_GRAPHS`的值为3, 运行时会输出后缀为dot的ir文件。该文件描述了不同节点间的拓扑关系,可以用[graphviz](http://graphviz.org)将此文件作为输入生成图片,方便用户直观地查看模型结构。 @@ -59,11 +59,9 @@ os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = "path/to/ir/files" ```python import os -import mindspore as ms -import mindspore.nn as nn -from mindspore import ops +import mindspore +from mindspore import nn, ops -ms.set_context(mode=ms.GRAPH_MODE) os.environ['MS_DEV_SAVE_GRAPHS'] = '2' os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' @@ -74,6 +72,7 @@ class Net(nn.Cell): def func(x, y): return ops.div(x, y) + @mindspore.jit def construct(self, x, y): a = ops.sub(x, 1) b = ops.add(a, y) @@ -81,8 +80,8 @@ class Net(nn.Cell): b = ops.mul(b, self.func(a, b)) return b -input1 = ms.Tensor(3, ms.float32) -input2 = ms.Tensor(2, ms.float32) +input1 = mindspore.tensor(3, mindspore.float32) +input2 = mindspore.tensor(2, mindspore.float32) net = Net() out = net(input1, input2) print(out) @@ -90,7 +89,7 @@ print(out) ### ir文件介绍 -使用文本编辑软件(例如`vi`)打开执行完后输出的IR文件`18_execute_0161.ir`,内容如下所示(此处版本为MindSpore 2.3,后续版本中内容可能会有一些细微变化): +使用文本编辑软件(例如`vi`)打开执行完后输出的IR文件`18_execute_0161.ir`,内容如下所示: ```text 1 # IR entry: @19_1___main___Net_construct_304 @@ -278,441 +277,495 @@ MindSpore在编译图的过程中,经常会出现`type_inference`阶段的图 ### 例子1:参数数量不匹配 ```python - 1 import os - 2 import mindspore as ms - 3 import mindspore.nn as nn - 4 from mindspore import ops - 5 - 6 ms.set_context(mode=ms.GRAPH_MODE) - 7 os.environ['MS_DEV_SAVE_GRAPHS'] = '2' - 8 os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' - 9 - 10 class Net(nn.Cell): - 11 def __init__(self): - 12 super().__init__() - 13 - 14 def func(x, y): - 15 return ops.div(x, y) - 16 - 17 def construct(self, x, y): - 18 a = ops.sub(x, 1) - 19 b = ops.add(a, y) - 20 c = ops.mul(b, self.func(a, a, b)) - 21 - 22 input1 = ms.Tensor(3, ms.float32) - 23 input2 = ms.Tensor(2, ms.float32) - 24 net = Net() - 25 out = net(input1, input2) - 26 print(out) +import os +import mindspore +from mindspore import nn, ops + +os.environ['MS_DEV_SAVE_GRAPHS'] = '2' +os.environ['MS_DEV_SAVE_GRAPHS_PATH'] = './ir' + +class Net(nn.Cell): + def __init__(self): + super().__init__() + + def func(x, y): + return ops.div(x, y) + + @mindspore.jit + def construct(self, x, y): + a = ops.sub(x, 1) + b = ops.add(a, y) + c = ops.mul(b, self.func(a, a, b)) + +input1 = mindspore.tensor(3, mindspore.float32) +input2 = mindspore.tensor(2, mindspore.float32) +net = Net() +out = net(input1, input2) +print(out) ``` 会出现如下的报错: ```text 1 Traceback (most recent call last): - 2 File "t2.py", line 23, in + 2 File "/workspace/mindspore/test2.py", line 24, in 3 out = net(input1, input2) - 4 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 701, in __call__ - 5 out = self.compile_and_run(*args, **kwargs) - 6 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1051, in compile_and_run - 7 self.compile(*args, **kwargs) - 8 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1034, in compile - 9 _cell_graph_executor.compile(self, *self._compile_args, phase=self.phase, - 10 File "/workspace/mindspore/build/package/mindspore/common/api.py", line 1815, in compile - 11 result = self._graph_executor.compile(obj, args, kwargs, phase, self._use_vm_mode()) - 12 TypeError: The parameters number of the function is 2, but the number of provided arguments is 3. - 13 FunctionGraph ID : func_40 - 14 NodeInfo: In file t2.py:12~13, 4~28 - 15 def func(x, y): - 16 - 17 ---------------------------------------------------- - 18 - C++ Call Stack: (For framework developers) - 19 ---------------------------------------------------- - 20 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:104 DoJump - 21 - 22 ---------------------------------------------------- - 23 - The Traceback of Net Construct Code: - 24 ---------------------------------------------------- - 25 # 0 In file t2.py:18, 23~41 - 26 c = ops.mul(b, self.func(a, a, b)) - 27 ^~~~~~~~~~~~~~~~~~ - 28 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) + 4 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/nn/cell.py", line 1338, in __call__ + 5 return self.construct(*args, **kwargs) + 6 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 1090, in staging_specialize + 7 out = jit_executor(*args, **kwargs) + 8 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 180, in wrapper + 9 results = fn(*arg, **kwargs) + 10 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 667, in __call__ + 11 raise err + 12 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 663, in __call__ + 13 phase = self.compile(self.fn.__name__, *args_list, **kwargs) + 14 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 781, in compile + 15 is_compile = self._graph_executor.compile( + 16 TypeError: The parameters number of the function is 2, but the number of provided arguments is 3. + 17 FunctionGraph ID : func_7 + 18 NodeInfo: In file /workspace/mindspore/test2.py:12~13, 4~28 + 19 def func(x, y): + 20 + 21 ---------------------------------------------------- + 22 - C++ Call Stack: (For framework developers) + 23 ---------------------------------------------------- + 24 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:98 DoJump + 25 + 26 ---------------------------------------------------- + 27 - The Traceback of Net Construct Code: + 28 ---------------------------------------------------- + 29 # 0 In file /workspace/mindspore/test2.py:19, 23~41 + 30 c = ops.mul(b, self.func(a, a, b)) + 31 ^~~~~~~~~~~~~~~~~~ + 32 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) ``` 以上的报错信息为:“TypeError: The parameters number of the function is 2, but the number of provided arguments is 3...”。 -表明`FunctionGraph ID : func_40`只需要2个参数,但是却提供了3个参数。从“The function call stack ...”中,可以知道出错的代码为:“In file t2.py:18 ... self.func(a, a, b)”,是因为该处的函数调用传入参数的数目过多。 +表明`FunctionGraph ID : func_7`只需要2个参数,但是却提供了3个参数。从“The Traceback of Net Construct Code”中,可以知道出错的代码为:“In file /workspace/mindspore/test2.py:19 ... self.func(a, a, b)”,是因为该处的函数调用传入参数的数目过多。 -但如果报错信息不直观或者需要查看IR中已推导出的部分图信息,使用文本编辑软件(例如,vi)打开报错信息中的提示的文件(第28行括号中):`/workspace/mindspore/rank_0/om/analyze_fail.ir`,文件中除了上述报错信息,还有如下内容(此处版本为MindSpore 2.3,后续版本中内容可能会有一些细微变化): +但如果报错信息不直观或者需要查看IR中已推导出的部分图信息,使用文本编辑软件(例如,vi)打开报错信息中的提示的文件(第32行括号中):`/workspace/mindspore/rank_0/om/analyze_fail.ir`,文件中除了上述报错信息,还有如下内容: ```text 1 # =============================================================================================== - 2 # The following shows the IR when the function graphs evaluation fails to help locate the problem. - 3 # You can search the last ------------------------> to the node which is evaluated failure. - 4 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. - 5 # =============================================================================================== - 6 - 7 # IR entry: @__main___Net_construct_11 - 8 # Total subgraphs: 0 - 9 - 10 # Total params: 2 - 11 # Params: - 12 %para1_x: - 13 %para2_y: - 14 - 15 subgraph attr: - 16 subgraph instance: __main___Net_construct_11 : 0x12fb85c18 - 17 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 18 subgraph @__main___Net_construct_11() { - 19 %0(CNode_3) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) - 20 : (, ) -> () - 21 #scope: (Default) - 22 - 23 #------------------------> 0 - 24 %1(CNode_2) = %0(%para1_x, %para2_y) - 25 : (, ) -> () - 26 #scope: (Default) - 27 Return(%1) - 28 : () - 29 #scope: (Default) - 30 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 31 } - 32 # Order: - 33 # 1: @__main___Net_construct_11:CNode_3{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} - 34 # 2: @__main___Net_construct_11:CNode_2{[0]: CNode_3, [1]: param_x, [2]: param_y} - 35 # 3: @__main___Net_construct_11:CNode_44{[0]: ValueNode Return, [1]: CNode_2} - 36 - 37 - 38 subgraph attr: - 39 subgraph instance: __main___Net_construct_11 : 0x12fac0218 - 40 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 41 subgraph @__main___Net_construct_11(%para0_x, %para0_y) { - 42 %0(CNode_12) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) - 43 : (, ) -> () - 44 #scope: (Default) - 45 # In file t2.py:16, 12~15/ a = ops.sub(x, 1)/ - 46 %1(CNode_17) = getattr(%0, "mul") - 47 : (, ) -> () - 48 #scope: (Default) - 49 # In file t2.py:18, 12~19/ c = ops.mul(b, self.func(a, a, b))/ - 50 %2(CNode_15) = getattr(%0, "add") - 51 : (, ) -> () - 52 #scope: (Default) - 53 # In file t2.py:17, 12~19/ b = ops.add(a, y)/ - 54 %3(CNode_13) = getattr(%0, "sub") - 55 : (, ) -> () - 56 #scope: (Default) - 57 # In file t2.py:16, 12~19/ a = ops.sub(x, 1)/ - 58 %4(a) = %3(%para0_x, I64(1)) - 59 : (, ) -> () - 60 #scope: (Default) - 61 # In file t2.py:16, 12~25/ a = ops.sub(x, 1)/ - 62 %5(b) = %2(%4, %para0_y) - 63 : (, ) -> () - 64 #scope: (Default) - 65 # In file t2.py:17, 12~25/ b = ops.add(a, y)/ - 66 %6(CNode_18) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], func) - 67 : (, ) -> () + 2 # The following shows the last analyze fail log message. + 3 # =============================================================================================== + 4 + 5 ---------------------------------------------------- + 6 - Caught exception: + 7 ---------------------------------------------------- + 8 The parameters number of the function is 2, but the number of provided arguments is 3. + 9 FunctionGraph ID : func_7 + 10 NodeInfo: In file /workspace/mindspore/test2.py:12~13, 4~28 + 11 def func(x, y): + 12 + 13 ---------------------------------------------------- + 14 - C++ Call Stack: (For framework developers) + 15 ---------------------------------------------------- + 16 mindspore/ccsrc/pipeline/jit/ps/static_analysis/stack_frame.cc:98 DoJump + 17 + 18 ---------------------------------------------------- + 19 - The Traceback of Net Construct Code: + 20 ---------------------------------------------------- + 21 # 0 In file /workspace/mindspore/test2.py:19, 23~41 + 22 c = ops.mul(b, self.func(a, a, b)) + 23 ^~~~~~~~~~~~~~~~~~ + 24 + 25 # =============================================================================================== + 26 # The following shows the IR when the function graphs evaluation fails to help locate the problem. + 27 # You can search the last ------------------------> to the node which is evaluated failure. + 28 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. + 29 # =============================================================================================== + 30 + 31 # IR entry: @__main___Net_construct_8 + 32 # Total subgraphs: 0 + 33 + 34 # Total params: 2 + 35 # Params: + 36 %para1_x: + 37 %para2_y: + 38 + 39 subgraph attr: + 40 subgraph instance: __main___Net_construct_8 : 0xf1667a0 + 41 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 42 subgraph @__main___Net_construct_8() { + 43 %0(CNode_1) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) + 44 : (, ) -> () + 45 #scope: (Default) + 46 + 47 #------------------------> 0 + 48 %1(CNode_2) = %0(%para1_x, %para2_y) + 49 : (, ) -> () + 50 #scope: (Default) + 51 Return(%1) + 52 : () + 53 #scope: (Default) + 54 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 55 } + 56 # Order: + 57 # 1: @__main___Net_construct_8:CNode_1{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} + 58 # 2: @__main___Net_construct_8:CNode_2{[0]: CNode_1, [1]: param_x, [2]: param_y} + 59 # 3: @__main___Net_construct_8:CNode_9{[0]: ValueNode Return, [1]: CNode_2} + 60 + 61 + 62 subgraph attr: + 63 subgraph instance: __main___Net_construct_8 : 0xf4c9fb0 + 64 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ + 65 subgraph @__main___Net_construct_8(%para0_x, %para0_y) { + 66 %0(CNode_10) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) + 67 : (, ) -> () 68 #scope: (Default) - 69 # In file t2.py:18, 23~32/ c = ops.mul(b, self.func(a, a, b))/ - 70 - 71 #------------------------> 1 - 72 %7(CNode_19) = %6(%4, %4, %5) - 73 : (, , ) -> () - 74 #scope: (Default) - 75 # In file t2.py:18, 23~41/ c = ops.mul(b, self.func(a, a, b))/ - 76 %8(c) = %1(%5, %7) - 77 : (, ) -> () - 78 #scope: (Default) - 79 # In file t2.py:18, 12~42/ c = ops.mul(b, self.func(a, a, b))/ - 80 %9(CNode_22) = StopGradient(%8) - 81 : () -> () - 82 #scope: (Default) - 83 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 84 %10(CNode_21) = Depend(None, %9) primitive_attrs: {side_effect_propagate: I64(1)} cnode_attrs: {topo_sort_rhs_first: Bool(1)} - 85 : (, ) -> () - 86 #scope: (Default) - 87 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 88 Return(%10) - 89 : () - 90 #scope: (Default) - 91 # In file t2.py:15~18, 4~42/ def construct(self, x, y):/ - 92 } - 93 # Order: - 94 # 1: @__main___Net_construct_11:CNode_12{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} - 95 # 2: @__main___Net_construct_11:CNode_13{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode sub} - 96 # 3: @__main___Net_construct_11:CNode_45{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 97 # 5: @__main___Net_construct_11:a{[0]: CNode_13, [1]: param_x, [2]: ValueNode 1} - 98 # 6: @__main___Net_construct_11:CNode_15{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode add} - 99 # 7: @__main___Net_construct_11:CNode_46{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -100 # 9: @__main___Net_construct_11:b{[0]: CNode_15, [1]: a, [2]: param_y} -101 # 10: @__main___Net_construct_11:CNode_17{[0]: ValueNode getattr, [1]: CNode_12, [2]: ValueNode mul} -102 # 11: @__main___Net_construct_11:CNode_18{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode func} -103 # 12: @__main___Net_construct_11:CNode_47{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -104 # 14: @__main___Net_construct_11:CNode_19{[0]: CNode_18, [1]: a, [2]: a, [3]: b} -105 # 15: @__main___Net_construct_11:CNode_48{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -106 # 17: @__main___Net_construct_11:c{[0]: CNode_17, [1]: b, [2]: CNode_19} -107 # 19: @__main___Net_construct_11:CNode_44{[0]: ValueNode Return, [1]: CNode_21} -108 -109 -110 # =============================================================================================== -111 # The total of function graphs in evaluation stack: 2 -112 # =============================================================================================== -113 -114 -115 # =============================================================================================== -116 # The rest function graphs are the following: -117 # =============================================================================================== -118 No more function graphs. + 69 # In file /workspace/mindspore/test2.py:17, 12~15/ a = ops.sub(x, 1)/ + 70 %1(CNode_11) = getattr(%0, "mul") + 71 : (, ) -> () + 72 #scope: (Default) + 73 # In file /workspace/mindspore/test2.py:19, 12~19/ c = ops.mul(b, self.func(a, a, b))/ + 74 %2(CNode_12) = getattr(%0, "add") + 75 : (, ) -> () + 76 #scope: (Default) + 77 # In file /workspace/mindspore/test2.py:18, 12~19/ b = ops.add(a, y)/ + 78 %3(CNode_13) = getattr(%0, "sub") + 79 : (, ) -> () + 80 #scope: (Default) + 81 # In file /workspace/mindspore/test2.py:17, 12~19/ a = ops.sub(x, 1)/ + 82 %4(a) = %3(%para0_x, I64(1)) + 83 : (, ) -> () + 84 #scope: (Default) + 85 # In file /workspace/mindspore/test2.py:17, 12~25/ a = ops.sub(x, 1)/ + 86 %5(b) = %2(%4, %para0_y) + 87 : (, ) -> () + 88 #scope: (Default) + 89 # In file /workspace/mindspore/test2.py:18, 12~25/ b = ops.add(a, y)/ + 90 %6(CNode_14) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], func) + 91 : (, ) -> () + 92 #scope: (Default) + 93 # In file /workspace/mindspore/test2.py:19, 23~32/ c = ops.mul(b, self.func(a, a, b))/ + 94 + 95 #------------------------> 1 + 96 %7(CNode_15) = %6(%4, %4, %5) + 97 : (, , ) -> () + 98 #scope: (Default) + 99 # In file /workspace/mindspore/test2.py:19, 23~41/ c = ops.mul(b, self.func(a, a, b))/ +100 %8(c) = %1(%5, %7) +101 : (, ) -> () +102 #scope: (Default) +103 # In file /workspace/mindspore/test2.py:19, 12~42/ c = ops.mul(b, self.func(a, a, b))/ +104 %9(CNode_16) = StopGradient(%8) +105 : () -> () +106 #scope: (Default) +107 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +108 %10(CNode_17) = Depend(None, %9) primitive_attrs: {side_effect_propagate: I64(1)} cnode_attrs: {topo_sort_rhs_first: Bool(1)} +109 : (, ) -> () +110 #scope: (Default) +111 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +112 Return(%10) +113 : () +114 #scope: (Default) +115 # In file /workspace/mindspore/test2.py:15~19, 4~42/ @mindspore.jit/ +116 } +117 # Order: +118 # 1: @__main___Net_construct_8:CNode_10{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} +119 # 2: @__main___Net_construct_8:CNode_13{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode sub} +120 # 3: @__main___Net_construct_8:CNode_18{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +121 # 5: @__main___Net_construct_8:a{[0]: CNode_13, [1]: param_x, [2]: ValueNode 1} +122 # 6: @__main___Net_construct_8:CNode_12{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode add} +123 # 7: @__main___Net_construct_8:CNode_19{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +124 # 9: @__main___Net_construct_8:b{[0]: CNode_12, [1]: a, [2]: param_y} +125 # 10: @__main___Net_construct_8:CNode_11{[0]: ValueNode getattr, [1]: CNode_10, [2]: ValueNode mul} +126 # 11: @__main___Net_construct_8:CNode_14{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode func} +127 # 12: @__main___Net_construct_8:CNode_20{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +128 # 14: @__main___Net_construct_8:CNode_15{[0]: CNode_14, [1]: a, [2]: a, [3]: b} +129 # 15: @__main___Net_construct_8:CNode_21{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +130 # 17: @__main___Net_construct_8:c{[0]: CNode_11, [1]: b, [2]: CNode_15} +131 # 19: @__main___Net_construct_8:CNode_9{[0]: ValueNode Return, [1]: CNode_17} +132 +133 +134 # =============================================================================================== +135 # The total of function graphs in evaluation stack: 2 +136 # =============================================================================================== +137 +138 +139 # =============================================================================================== +140 # The rest function graphs are the following: +141 # =============================================================================================== +142 No more function graphs. ``` -`analyze_fail.ir`文件与前文介绍过的ir文件格式一致,唯一有区别的地方在于`analyze_fail.ir`文件中会指出推导出错的节点所在的位置,即第71行的`------------------------> 1`。该箭头指向了推导出错的节点,为`%7(CNode_19) = %6(%4, %4, %5) ...`。 +`analyze_fail.ir`文件与前文介绍过的ir文件格式一致,唯一有区别的地方在于`analyze_fail.ir`文件中会指出推导出错的节点所在的位置,即第95行的`------------------------> 1`。该箭头指向了推导出错的节点,为`%7(CNode_15) = %6(%4, %4, %5) ...`。 根据`(%4, %4, %5)`可知,该节点的输入参数有三个。从源码解析调用栈中可以知道实际该函数为`self.func`,在脚本中的定义为`def func(x, y):...`。 在函数定义中,只需要两个参数,故会在此处出现推导失败的报错,需要修改脚本中传入的参数个数以解决该问题。 ### 例子2:BiasAdd输入之间shape不匹配 ```python - 1 import numpy as np - 2 import mindspore as ms - 3 from mindspore import nn, ops, set_context, Tensor, Parameter - 4 from mindspore.common.initializer import initializer - 5 - 6 ms.set_context(mode=ms.GRAPH_MODE) - 7 - 8 class Net(nn.Cell): - 9 def __init__(self): - 10 super(Net, self).__init__() - 11 self.weight = Parameter(initializer('normal', [32, 8]), name="weight") - 12 self.bias = Parameter(initializer('zeros', [4]), name="bias") - 13 - 14 def construct(self, x1): - 15 x = ops.matmul(x1, self.weight) - 16 x = ops.bias_add(x, self.bias) - 17 return x - 18 - 19 net = Net() - 20 x = Tensor(np.arange(3*32).reshape(3, 32), ms.float32) - 21 out = net(x) - 22 print('out', out.shape) +import numpy as np +import mindspore +from mindspore import nn, ops, Tensor, Parameter +from mindspore.common.initializer import initializer + +class Net(nn.Cell): + def __init__(self): + super(Net, self).__init__() + self.weight = Parameter(initializer('normal', [32, 8]), name="weight") + self.bias = Parameter(initializer('zeros', [4]), name="bias") + + @mindspore.jit + def construct(self, x1): + x = ops.matmul(x1, self.weight) + x = ops.bias_add(x, self.bias) + return x + +net = Net() +x = mindspore.tensor(np.arange(3*32).reshape(3, 32), mindspore.float32) +out = net(x) +print('out', out.shape) ``` 会出现如下的报错: ```text 1 Traceback (most recent call last): - 2 File "t2.py", line 21, in + 2 File "/workspace/mindspore/test2.py", line 20, in 3 out = net(x) - 4 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 701, in __call__ - 5 out = self.compile_and_run(*args, **kwargs) - 6 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1051, in compile_and_run - 7 self.compile(*args, **kwargs) - 8 File "/workspace/mindspore/build/package/mindspore/nn/cell.py", line 1034, in compile - 9 _cell_graph_executor.compile(self, *self._compile_args, phase=self.phase, - 10 File "/workspace/mindspore/build/package/mindspore/common/api.py", line 1815, in compile - 11 result = self._graph_executor.compile(obj, args, kwargs, phase, self._use_vm_mode()) - 12 ValueError: For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector]{3, 8}. - 13 - 14 ---------------------------------------------------- - 15 - C++ Call Stack: (For framework developers) - 16 ---------------------------------------------------- - 17 mindspore/core/ops/ops_func_impl/bias_add.cc:71 CheckShapeValid - 18 - 19 ---------------------------------------------------- - 20 - The Traceback of Net Construct Code: - 21 ---------------------------------------------------- - 22 # 0 In file t2.py:16, 11~37 - 23 x = ops.bias_add(x, self.bias) - 24 ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 25 # 1 In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 11~37 - 26 return bias_add_op(input_x, bias) - 27 ^~~~~~~~~~~~~~~~~~~~~~~~~~ - 28 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) + 4 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/nn/cell.py", line 1338, in __call__ + 5 return self.construct(*args, **kwargs) + 6 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 1090, in staging_specialize + 7 out = jit_executor(*args, **kwargs) + 8 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 180, in wrapper + 9 results = fn(*arg, **kwargs) + 10 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 667, in __call__ + 11 raise err + 12 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 663, in __call__ + 13 phase = self.compile(self.fn.__name__, *args_list, **kwargs) + 14 File "/workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/common/api.py", line 781, in compile + 15 is_compile = self._graph_executor.compile( + 16 ValueError: For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector] {3, 8}. + 17 + 18 ---------------------------------------------------- + 19 - C++ Call Stack: (For framework developers) + 20 ---------------------------------------------------- + 21 mindspore/ops/infer/ops_func_impl//bias_add.cc:71 CheckShapeValid + 22 + 23 ---------------------------------------------------- + 24 - The Traceback of Net Construct Code: + 25 ---------------------------------------------------- + 26 # 0 In file /workspace/mindspore/test2.py:15, 12~38 + 27 x = ops.bias_add(x, self.bias) + 28 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 29 # 1 In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37 + 30 return bias_add_op(input_x, bias) + 31 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 32 (See file '/workspace/mindspore/rank_0/om/analyze_fail.ir' for more details. Get instructions about `analyze_fail.ir` at https://www.mindspore.cn/search?inputValue=analyze_fail.ir) ``` -根据以上报错可知,是算子`BiasAdd`的第一个输入和第二个输入的`shape`不匹配导致的错误。为了进一步了解算子的`shape`是经过了什么样的变化,使用文本编辑软件(例如,vi)打开报错信息中的提示的文件:`/workspace/mindspore/rank_0/om/analyze_fail.ir`,文件中除了上述报错信息,还有如下内容(此处版本为MindSpore 2.3,后续版本中内容可能会有一些细微变化): +根据以上报错可知,是算子`BiasAdd`的第一个输入和第二个输入的`shape`不匹配导致的错误。为了进一步了解算子的`shape`是经过了什么样的变化,使用文本编辑软件(例如,vi)打开报错信息中的提示的文件:`/workspace/mindspore/rank_0/om/analyze_fail.ir`,文件中除了上述报错信息,还有如下内容: ```text 1 # =============================================================================================== - 2 # The following shows the IR when the function graphs evaluation fails to help locate the problem. - 3 # You can search the last ------------------------> to the node which is evaluated failure. - 4 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. - 5 # =============================================================================================== - 6 - 7 # IR entry: @__main___Net_construct_6 - 8 # Total subgraphs: 0 + 2 # The following shows the last analyze fail log message. + 3 # =============================================================================================== + 4 + 5 ---------------------------------------------------- + 6 - Caught exception: + 7 ---------------------------------------------------- + 8 For 'BiasAdd', bias[0] shape should be equal to input_x[1] shape when data_format is 0, but got bias shape: .[const vector]{4}, input_shape: [const vector]{3, 8}. 9 - 10 # Total params: 3 - 11 # Params: - 12 %para1_x1: - 13 %para2_weight: : has_default - 14 %para3_bias: : has_default - 15 - 16 subgraph attr: - 17 subgraph instance: __main___Net_construct_6 : 0x128910818 - 18 # In file t2.py:14~17, 4~15/ def construct(self, x1):/ - 19 subgraph @__main___Net_construct_6() { - 20 %0(CNode_3) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) - 21 : (, ) -> () - 22 #scope: (Default) - 23 - 24 #------------------------> 0 - 25 %1(CNode_2) = %0(%para1_x1) - 26 : () -> () - 27 #scope: (Default) - 28 Return(%1) - 29 : () - 30 #scope: (Default) - 31 # In file t2.py:17, 7~15/ return x/ - 32 } - 33 # Order: - 34 # 1: @__main___Net_construct_6:CNode_3{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} - 35 # 2: @__main___Net_construct_6:CNode_2{[0]: CNode_3, [1]: param_x1} - 36 # 3: @__main___Net_construct_6:CNode_162{[0]: ValueNode Return, [1]: CNode_2} - 37 - 38 - 39 subgraph attr: - 40 subgraph instance: __main___Net_construct_6 : 0x14bb64c18 - 41 # In file t2.py:14~17, 4~15/ def construct(self, x1):/ - 42 subgraph @__main___Net_construct_6(%para0_x1) { - 43 %0(CNode_7) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) - 44 : (, ) -> () - 45 #scope: (Default) - 46 # In file t2.py:15, 11~14/ x = ops.matmul(x1, self.weight)/ - 47 %1(CNode_11) = getattr(%0, "bias_add") - 48 : (, ) -> () - 49 #scope: (Default) - 50 # In file t2.py:16, 11~23/ x = ops.bias_add(x, self.bias)/ - 51 %2(CNode_8) = getattr(%0, "matmul") - 52 : (, ) -> () - 53 #scope: (Default) - 54 # In file t2.py:15, 11~21/ x = ops.matmul(x1, self.weight)/ - 55 %3(CNode_9) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], weight) - 56 : (, ) -> () - 57 #scope: (Default) - 58 # In file t2.py:15, 26~37/ x = ops.matmul(x1, self.weight)/ - 59 %4(x) = %2(%para0_x1, %3) - 60 : (, ) -> () - 61 #scope: (Default) - 62 # In file t2.py:15, 11~38/ x = ops.matmul(x1, self.weight)/ - 63 %5(CNode_12) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], bias) - 64 : (, ) -> () - 65 #scope: (Default) - 66 # In file t2.py:16, 27~36/ x = ops.bias_add(x, self.bias)/ - 67 - 68 #------------------------> 1 - 69 %6(x) = %1(%4, %5) - 70 : (, ) -> () - 71 #scope: (Default) - 72 # In file t2.py:16, 11~37/ x = ops.bias_add(x, self.bias)/ - 73 Return(%6) - 74 : () - 75 #scope: (Default) - 76 # In file t2.py:17, 7~15/ return x/ - 77 } - 78 # Order: - 79 # 1: @__main___Net_construct_6:CNode_7{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} - 80 # 2: @__main___Net_construct_6:CNode_8{[0]: ValueNode getattr, [1]: CNode_7, [2]: ValueNode matmul} - 81 # 3: @__main___Net_construct_6:CNode_9{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode weight} - 82 # 4: @__main___Net_construct_6:CNode_163{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 83 # 6: @__main___Net_construct_6:x{[0]: CNode_8, [1]: param_x1, [2]: CNode_9} - 84 # 7: @__main___Net_construct_6:CNode_11{[0]: ValueNode getattr, [1]: CNode_7, [2]: ValueNode bias_add} - 85 # 8: @__main___Net_construct_6:CNode_12{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode bias} - 86 # 9: @__main___Net_construct_6:CNode_164{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} - 87 # 11: @__main___Net_construct_6:x{[0]: CNode_11, [1]: x, [2]: CNode_12} - 88 # 12: @__main___Net_construct_6:CNode_162{[0]: ValueNode Return, [1]: x} - 89 - 90 - 91 subgraph attr: - 92 subgraph instance: bias_add_14 : 0x128910e18 - 93 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6244~6280, 0~37/def bias_add(input_x, bias):/ - 94 subgraph @bias_add_14(%para0_input_x, %para0_bias) { - 95 %0(CNode_15) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], _get_cache_prim) - 96 : (, ) -> () - 97 #scope: (Default) - 98 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~33/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ - 99 %1(CNode_16) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], P) -100 : (, ) -> () -101 #scope: (Default) -102 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 34~35/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -103 %2(CNode_17) = getattr(%1, "BiasAdd") -104 : (, ) -> () -105 #scope: (Default) -106 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 34~43/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -107 %3(CNode_18) = %0(%2) -108 : () -> () -109 #scope: (Default) -110 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~44/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -111 %4(CNode_131) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], make_dict) -112 : (, ) -> () -113 #scope: (Default) -114 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -115 %5(CNode_132) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) -116 : (, ) -> () -117 #scope: (Default) -118 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -119 %6(CNode_133) = %5("data_format") -120 : () -> () + 10 ---------------------------------------------------- + 11 - C++ Call Stack: (For framework developers) + 12 ---------------------------------------------------- + 13 mindspore/ops/infer/ops_func_impl//bias_add.cc:71 CheckShapeValid + 14 + 15 ---------------------------------------------------- + 16 - The Traceback of Net Construct Code: + 17 ---------------------------------------------------- + 18 # 0 In file /workspace/mindspore/test2.py:15, 12~38 + 19 x = ops.bias_add(x, self.bias) + 20 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 21 # 1 In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37 + 22 return bias_add_op(input_x, bias) + 23 ^~~~~~~~~~~~~~~~~~~~~~~~~~ + 24 + 25 # =============================================================================================== + 26 # The following shows the IR when the function graphs evaluation fails to help locate the problem. + 27 # You can search the last ------------------------> to the node which is evaluated failure. + 28 # Refer to https://www.mindspore.cn/search?inputValue=analyze_fail.ir to get more instructions. + 29 # =============================================================================================== + 30 + 31 # IR entry: @__main___Net_construct_3 + 32 # Total subgraphs: 0 + 33 + 34 # Total params: 3 + 35 # Params: + 36 %para1_x1: + 37 %para2_weight: : has_default + 38 %para3_bias: : has_default + 39 + 40 subgraph attr: + 41 subgraph instance: __main___Net_construct_3 : 0x13bfdd40 + 42 # In file /workspace/mindspore/test2.py:12~16, 4~16/ @mindspore.jit/ + 43 subgraph @__main___Net_construct_3() { + 44 %0(CNode_5) = resolve(NameSpace[Entry: '__main__.Net.construct'], __main__.Net.construct) + 45 : (, ) -> () + 46 #scope: (Default) + 47 + 48 #------------------------> 0 + 49 %1(CNode_6) = %0(%para1_x1) + 50 : () -> () + 51 #scope: (Default) + 52 Return(%1) + 53 : () + 54 #scope: (Default) + 55 # In file /workspace/mindspore/test2.py:16, 8~16/ return x/ + 56 } + 57 # Order: + 58 # 1: @__main___Net_construct_3:CNode_5{[0]: ValueNode resolve, [1]: ValueNode Entry: '__main__.Net.construct', [2]: ValueNode __main__.Net.construct} + 59 # 2: @__main___Net_construct_3:CNode_6{[0]: CNode_5, [1]: param_x1} + 60 # 3: @__main___Net_construct_3:CNode_7{[0]: ValueNode Return, [1]: CNode_6} + 61 + 62 + 63 subgraph attr: + 64 subgraph instance: __main___Net_construct_3 : 0x13f5fc20 + 65 # In file /workspace/mindspore/test2.py:12~16, 4~16/ @mindspore.jit/ + 66 subgraph @__main___Net_construct_3(%para0_x1) { + 67 %0(CNode_8) = resolve(NameSpace[SymbolStr: 'Namespace:__main__'], ops) + 68 : (, ) -> () + 69 #scope: (Default) + 70 # In file /workspace/mindspore/test2.py:14, 12~15/ x = ops.matmul(x1, self.weight)/ + 71 %1(CNode_9) = getattr(%0, "bias_add") + 72 : (, ) -> () + 73 #scope: (Default) + 74 # In file /workspace/mindspore/test2.py:15, 12~24/ x = ops.bias_add(x, self.bias)/ + 75 %2(CNode_10) = getattr(%0, "matmul") + 76 : (, ) -> () + 77 #scope: (Default) + 78 # In file /workspace/mindspore/test2.py:14, 12~22/ x = ops.matmul(x1, self.weight)/ + 79 %3(CNode_11) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], weight) + 80 : (, ) -> () + 81 #scope: (Default) + 82 # In file /workspace/mindspore/test2.py:14, 27~38/ x = ops.matmul(x1, self.weight)/ + 83 %4(x) = %2(%para0_x1, %3) + 84 : (, ) -> () + 85 #scope: (Default) + 86 # In file /workspace/mindspore/test2.py:14, 12~39/ x = ops.matmul(x1, self.weight)/ + 87 %5(CNode_12) = resolve(NameSpace[ClassMember: 'Namespace:__main__..'], bias) + 88 : (, ) -> () + 89 #scope: (Default) + 90 # In file /workspace/mindspore/test2.py:15, 28~37/ x = ops.bias_add(x, self.bias)/ + 91 + 92 #------------------------> 1 + 93 %6(x) = %1(%4, %5) + 94 : (, ) -> () + 95 #scope: (Default) + 96 # In file /workspace/mindspore/test2.py:15, 12~38/ x = ops.bias_add(x, self.bias)/ + 97 Return(%6) + 98 : () + 99 #scope: (Default) +100 # In file /workspace/mindspore/test2.py:16, 8~16/ return x/ +101 } +102 # Order: +103 # 1: @__main___Net_construct_3:CNode_8{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:__main__', [2]: ValueNode ops} +104 # 2: @__main___Net_construct_3:CNode_10{[0]: ValueNode getattr, [1]: CNode_8, [2]: ValueNode matmul} +105 # 3: @__main___Net_construct_3:CNode_11{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode weight} +106 # 4: @__main___Net_construct_3:CNode_13{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +107 # 6: @__main___Net_construct_3:x{[0]: CNode_10, [1]: param_x1, [2]: CNode_11} +108 # 7: @__main___Net_construct_3:CNode_9{[0]: ValueNode getattr, [1]: CNode_8, [2]: ValueNode bias_add} +109 # 8: @__main___Net_construct_3:CNode_12{[0]: ValueNode resolve, [1]: ValueNode ClassMember: 'Namespace:__main__..', [2]: ValueNode bias} +110 # 9: @__main___Net_construct_3:CNode_14{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +111 # 11: @__main___Net_construct_3:x{[0]: CNode_9, [1]: x, [2]: CNode_12} +112 # 12: @__main___Net_construct_3:CNode_7{[0]: ValueNode Return, [1]: x} +113 +114 +115 subgraph attr: +116 subgraph instance: bias_add_4 : 0x13f65d00 +117 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7057~7093/def bias_add(input_x, bias):/ +118 subgraph @bias_add_4(%para0_input_x, %para0_bias) { +119 %0(CNode_15) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], _get_cache_prim) +120 : (, ) -> () 121 #scope: (Default) -122 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -123 %7(CNode_135) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) -124 : (, ) -> () +122 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~33/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +123 %1(CNode_16) = resolve(NameSpace[SymbolStr: 'Namespace:mindspore.ops.function.nn_func'], P) +124 : (, ) -> () 125 #scope: (Default) -126 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -127 %8(CNode_136) = %7("NCHW") -128 : () -> () +126 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 34~35/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +127 %2(CNode_17) = getattr(%1, "BiasAdd") +128 : (, ) -> () 129 #scope: (Default) -130 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -131 %9(CNode_21) = %4(%6, %8) -132 : (, ) -> () +130 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 34~43/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +131 %3(CNode_18) = %0(%2) +132 : () -> () 133 #scope: (Default) -134 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -135 %10(bias_add_op) = UnpackCall_unpack_call(%3, %9) -136 : (, ) -> () +134 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~44/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +135 %4(CNode_19) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], make_dict) +136 : (, ) -> () 137 #scope: (Default) -138 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6279, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ -139 -140 #------------------------> 2 -141 %11(CNode_22) = %10(%para0_input_x, %para0_bias) -142 : (, ) -> () -143 #scope: (Default) -144 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 11~37/ return bias_add_op(input_x, bias)/ -145 Return(%11) -146 : () -147 #scope: (Default) -148 # In file /workspace/mindspore/build/package/mindspore/ops/function/nn_func.py:6280, 4~37/ return bias_add_op(input_x, bias)/ -149 } -150 # Order: -151 # 1: @bias_add_14:CNode_15{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode _get_cache_prim} -152 # 2: @bias_add_14:CNode_16{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode P} -153 # 3: @bias_add_14:CNode_17{[0]: ValueNode getattr, [1]: CNode_16, [2]: ValueNode BiasAdd} -154 # 4: @bias_add_14:CNode_166{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -155 # 6: @bias_add_14:CNode_18{[0]: CNode_15, [1]: CNode_17} -156 # 7: @bias_add_14:CNode_132{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -157 # 8: @bias_add_14:CNode_133{[0]: CNode_132, [1]: ValueNode data_format} -158 # 9: @bias_add_14:CNode_135{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -159 # 10: @bias_add_14:CNode_136{[0]: CNode_135, [1]: ValueNode NCHW} -160 # 11: @bias_add_14:CNode_131{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode make_dict} -161 # 12: @bias_add_14:CNode_21{[0]: CNode_131, [1]: CNode_133, [2]: CNode_136} -162 # 13: @bias_add_14:bias_add_op{[0]: ValueNode MetaFuncGraph-unpack_call.20, [1]: CNode_18, [2]: CNode_21} -163 # 14: @bias_add_14:CNode_167{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} -164 # 16: @bias_add_14:CNode_22{[0]: bias_add_op, [1]: param_input_x, [2]: param_bias} -165 # 17: @bias_add_14:CNode_165{[0]: ValueNode Return, [1]: CNode_22} -166 -167 -168 # =============================================================================================== -169 # The total of function graphs in evaluation stack: 3/5 (Ignored 2 internal frames). -170 # =============================================================================================== -171 -172 -173 # =============================================================================================== -174 # The rest function graphs are the following: -175 # =============================================================================================== -176 No more function graphs. +138 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +139 %5(CNode_20) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) +140 : (, ) -> () +141 #scope: (Default) +142 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +143 %6(CNode_21) = %5("data_format") +144 : () -> () +145 #scope: (Default) +146 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +147 %7(CNode_22) = resolve(NameSpace[CommonOPS: 'Namespace:mindspore._extends.parse.trope'], MakeTuple) +148 : (, ) -> () +149 #scope: (Default) +150 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +151 %8(CNode_23) = %7("NCHW") +152 : () -> () +153 #scope: (Default) +154 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +155 %9(CNode_24) = %4(%6, %8) +156 : (, ) -> () +157 #scope: (Default) +158 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +159 %10(bias_add_op) = DoUnpackCall(%3, %9) +160 : (, ) -> () +161 #scope: (Default) +162 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7092, 18~64/ bias_add_op = _get_cache_prim(P.BiasAdd)(data_format="NCHW")/ +163 +164 #------------------------> 2 +165 %11(CNode_25) = %10(%para0_input_x, %para0_bias) +166 : (, ) -> () +167 #scope: (Default) +168 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 11~37/ return bias_add_op(input_x, bias)/ +169 Return(%11) +170 : () +171 #scope: (Default) +172 # In file /workspace/mindspore/tools/anaconda3/lib/python3.9/site-packages/mindspore/ops/function/nn_func.py:7093, 4~37/ return bias_add_op(input_x, bias)/ +173 } +174 # Order: +175 # 1: @bias_add_4:CNode_15{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode _get_cache_prim} +176 # 2: @bias_add_4:CNode_16{[0]: ValueNode resolve, [1]: ValueNode SymbolStr: 'Namespace:mindspore.ops.function.nn_func', [2]: ValueNode P} +177 # 3: @bias_add_4:CNode_17{[0]: ValueNode getattr, [1]: CNode_16, [2]: ValueNode BiasAdd} +178 # 4: @bias_add_4:CNode_26{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +179 # 6: @bias_add_4:CNode_18{[0]: CNode_15, [1]: CNode_17} +180 # 7: @bias_add_4:CNode_20{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +181 # 8: @bias_add_4:CNode_21{[0]: CNode_20, [1]: ValueNode data_format} +182 # 9: @bias_add_4:CNode_22{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +183 # 10: @bias_add_4:CNode_23{[0]: CNode_22, [1]: ValueNode NCHW} +184 # 11: @bias_add_4:CNode_19{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode make_dict} +185 # 12: @bias_add_4:CNode_24{[0]: CNode_19, [1]: CNode_21, [2]: CNode_23} +186 # 13: @bias_add_4:bias_add_op{[0]: ValueNode DoUnpackCall, [1]: CNode_18, [2]: CNode_24} +187 # 14: @bias_add_4:CNode_27{[0]: ValueNode resolve, [1]: ValueNode CommonOPS: 'Namespace:mindspore._extends.parse.trope', [2]: ValueNode MakeTuple} +188 # 16: @bias_add_4:CNode_25{[0]: bias_add_op, [1]: param_input_x, [2]: param_bias} +189 # 17: @bias_add_4:CNode_28{[0]: ValueNode Return, [1]: CNode_25} +190 +191 +192 # =============================================================================================== +193 # The total of function graphs in evaluation stack: 3/5 (Ignored 2 internal frames). +194 # =============================================================================================== +195 +196 +197 # =============================================================================================== +198 # The rest function graphs are the following: +199 # =============================================================================================== +200 No more function graphs. ``` -搜索`------------------------>`来到第68行,即推导出错的位置。根据`...(%4, %5): (, ) -> (``)`可知,算子`BiasAdd`的输入是`%4`和`%5`这两个节点。其中,`%4`的shape是`[3, 8]`,`%5`的shape是`[4]`,不符合算子API中`BiasAdd`算子的描述`bias (Tensor) - 偏置Tensor,shape为 (C)。C必须与 input_x 的通道维度C相同...`的要求,故此处报错。 +搜索`------------------------>`来到第92行,即推导出错的位置。根据`...(%4, %5): (, ) -> (``)`可知,算子`BiasAdd`的输入是`%4`和`%5`这两个节点。其中,`%4`的shape是`[3, 8]`,`%5`的shape是`[4]`,不符合算子API中`BiasAdd`算子的描述`bias (Tensor) - 偏置Tensor,shape为 (C)。C必须与 input_x 的通道维度C相同...`的要求,故此处报错。 因此,为了解决该问题,可以修改`%4`的shape,或修改`%5`(即`self.bias`)的shape。 - 如果修改`%5`(也就是`self.bias`)的维度,只需要改成`self.bias = Parameter(initializer('zeros', [8]), name="bias")`。 -- 如果修改`%4`的shape,先要明白`%4`是什么。根据第59行可知,这是一个`MatMul`算子,输出shape是`[3, 8]`。该算子的输入是`(%para0_x1, %3)`,第一个输入的shape是`[3, 32]`(即传入的参数`x`),第二个输入shape是`[32, 8]`(即`self.weight`)。为了满足和shape为`[4]`的数据`BiasAdd`的要求,需要使得`%4`的输出shape为`[3, 4]`,因此修改`self.weight`为`self.weight = Parameter(initializer('normal', [32, 4]), name="weight")`。 +- 如果修改`%4`的shape,先要明白`%4`是什么。根据第83行可知,这是一个`MatMul`算子,输出shape是`[3, 8]`。该算子的输入是`(%para0_x1, %3)`,第一个输入的shape是`[3, 32]`(即传入的参数`x`),第二个输入shape是`[32, 8]`(即`self.weight`)。为了满足和shape为`[4]`的数据`BiasAdd`的要求,需要使得`%4`的输出shape为`[3, 4]`,因此修改`self.weight`为`self.weight = Parameter(initializer('normal', [32, 4]), name="weight")`。 -- Gitee