From 52c6ea75d0211dac9dd5a2925ffb77e3026a41f6 Mon Sep 17 00:00:00 2001 From: SunAhong1993 Date: Sat, 12 Sep 2020 17:01:04 +0800 Subject: [PATCH] modify optimizer --- x2paddle/core/program.py | 32 +- x2paddle/op_mapper/pytorch2paddle/aten.py | 28 +- x2paddle/op_mapper/pytorch2paddle/prim.py | 3 +- .../op_mapper/pytorch2paddle/prim2code.py | 18 +- .../pytorch2paddle/pytorch_op_mapper.py | 1 + .../optimizer/fusion/batchnorm2d_fuser.py | 225 +- x2paddle/optimizer/fusion/fc_fuser.py | 12 +- .../fusion/interpolate_bilinear_fuser.py | 2422 ++++++++++------- x2paddle/optimizer/optimizer.py | 11 +- x2paddle/optimizer/pattern_matcher.py | 68 +- 10 files changed, 1696 insertions(+), 1124 deletions(-) diff --git a/x2paddle/core/program.py b/x2paddle/core/program.py index 839d806..d30a239 100644 --- a/x2paddle/core/program.py +++ b/x2paddle/core/program.py @@ -128,10 +128,30 @@ class PaddleGraph(object): for output in layer.outputs: outputs_from_nodes[output] = layer_id + # 将block的输出用于父图 + if inputs is not None and outputs is not None and set( + layer.outputs).issubset(outputs): + if layer_id not in self.edges_out: + self.edges_out[layer_id] = list() + self.edges_out[layer_id].append(-1) + + # 处理子图 if len(layer.blocks) > 0: for block in layer.blocks: block.build(layer.inputs, layer.outputs) + # 删除不必要的节点 + invalid_list = list() + for layer_id, layer in self.layers.items(): + if len(self.layers) > 1: + if self.edges_in.get(layer_id, 0) == 0 and self.edges_out.get( + layer_id, 0) == 0 and layer.kernel != "prim.assert" \ + and layer.kernel != "prim.exception" \ + and layer.kernel != "prim.warnings": + invalid_list.append(layer_id) + for layer_id in invalid_list: + self.layers.pop(layer_id) + if self.graph_type == "dygraph": self.get_dygraph_inputs() if len(self.outputs) == 0: @@ -244,7 +264,8 @@ class PaddleGraph(object): else: self.gen_dygraph_code(save_dir) self.dump_dygraph_parameter(save_dir) - self.dygraph2static(save_dir, input_shapes) #[[None, 3, 224, 224]] + +# self.dygraph2static(save_dir, input_shapes) #[[None, 3, 224, 224]] def dump_parameter(self, param_name, param, save_dir): if not os.path.exists(save_dir): @@ -367,13 +388,8 @@ class PaddleGraph(object): gen_head() for layer_id, layer in self.layers.items(): - if len(self.layers) > 1: - if self.edges_in.get(layer_id, 0) == 0 and self.edges_out.get( - layer_id, 0) == 0 and layer.kernel != "prim.assert" \ - and layer.kernel != "prim.exception" \ - and layer.kernel != "prim.warnings": - continue - if "paddle.nn" in layer.kernel or layer.kernel == "fluid.dygraph.base.to_variable": + if ("paddle.nn" in layer.kernel and "functional" not in layer.kernel + ) or layer.kernel == "fluid.dygraph.base.to_variable": line = "{}".format( layer.outputs[0] ) if layer.kernel == "fluid.dygraph.base.to_variable" and not layer.attrs[ diff --git a/x2paddle/op_mapper/pytorch2paddle/aten.py b/x2paddle/op_mapper/pytorch2paddle/aten.py index 468ce1d..b23ef36 100644 --- a/x2paddle/op_mapper/pytorch2paddle/aten.py +++ b/x2paddle/op_mapper/pytorch2paddle/aten.py @@ -3229,17 +3229,35 @@ def aten_upsample_bilinear2d(mapper, graph, node): current_outputs = [output_name] # 处理输入0,即%x.13 mapper._check_input(graph, inputs_node[0], inputs_name[0], current_outputs) - layer_inputs["input"] = inputs_name[0] + layer_inputs["x"] = inputs_name[0] # 获取当前节点输入的list current_inputs = list(layer_inputs.values()) # 处理输入1,即%4963 if inputs_name[1] in mapper.attrs: - layer_attrs["out_shape"] = mapper.attrs[inputs_name[1]] + layer_attrs["size"] = mapper.attrs[inputs_name[1]] else: mapper._check_input(graph, inputs_node[1], inputs_name[1], current_outputs) - layer_inputs["out_shape"] = inputs_name[1] + layer_inputs["size"] = inputs_name[1] current_inputs.append(inputs_name[1]) + graph.add_layer( + "prim.isinstance", + inputs={"input": inputs_name[1]}, + outputs=[inputs_name[1] + "_isinstance"], + cls="paddle.fluid.Variable") + graph.add_layer( + "prim.if", {"input": inputs_name[1] + "_isinstance"}, + outputs=[inputs_name[0] + "_if1"]) + if_layer = graph.layers[list(graph.layers.keys())[-1]] + block = PaddleGraph(if_layer, graph_type="dygraph") + block.add_layer( + "prim.var2list", + inputs={"input": inputs_name[1]}, + outputs=[inputs_name[1]]) + if_layer.add_block(block) + block = PaddleGraph(if_layer, graph_type="dygraph") + if_layer.add_block(block) + if_layer.inputs["input-0"] = inputs_name[1] # 处理输入2,即%5421 if inputs_name[2] in mapper.attrs: layer_attrs["align_corners"] = mapper.attrs[inputs_name[2]] @@ -3261,10 +3279,10 @@ def aten_upsample_bilinear2d(mapper, graph, node): inputs=list_layer_inputs, outputs=[output_name + "_assert"], type="eq") - layer_inputs["scale"] = inputs_name[3] + layer_inputs["scale_factor"] = inputs_name[3] layer_attrs["align_mode"] = 0 graph.add_layer( - "fluid.layers.interpolate", + "paddle.nn.functional.interpolate", inputs=layer_inputs, outputs=layer_outputs, **layer_attrs) diff --git a/x2paddle/op_mapper/pytorch2paddle/prim.py b/x2paddle/op_mapper/pytorch2paddle/prim.py index 8cbab9b..4a56fe6 100644 --- a/x2paddle/op_mapper/pytorch2paddle/prim.py +++ b/x2paddle/op_mapper/pytorch2paddle/prim.py @@ -442,7 +442,8 @@ def prim_shape(mapper, graph, node): # 获取当前节点输入的list current_inputs = list(layer_inputs.values()) - graph.add_layer("prim.shape", inputs=layer_inputs, outputs=layer_outputs) + graph.add_layer( + "fluid.layers.shape", inputs=layer_inputs, outputs=layer_outputs) return current_inputs, current_outputs diff --git a/x2paddle/op_mapper/pytorch2paddle/prim2code.py b/x2paddle/op_mapper/pytorch2paddle/prim2code.py index d9179f8..04bf22d 100644 --- a/x2paddle/op_mapper/pytorch2paddle/prim2code.py +++ b/x2paddle/op_mapper/pytorch2paddle/prim2code.py @@ -172,10 +172,11 @@ def prim_if(layer, indent=1, init_func=[], forward_func=[]): forward_func.extend(b_forward_lines) block = layer.blocks[1] if len(block.layers) > 0: - line = "else:" - forward_func.extend(gen_codes([line], indent=indent)) b_init_lines, b_forward_lines = block.gen_dygraph_code( indent=indent + 1) + if len(b_forward_lines) != 0: + line = "else:" + forward_func.extend(gen_codes([line], indent=indent)) init_func.extend(b_init_lines) forward_func.extend(b_forward_lines) @@ -191,6 +192,13 @@ def prim_is(layer, indent=1, init_func=[], forward_func=[]): forward_func.extend(gen_codes([line], indent=indent)) +def prim_isinstance(layer, indent=1, init_func=[], forward_func=[]): + line = "{} = isinstance({}, {})".format(layer.outputs[0], + get_value(layer, "input"), + layer.attrs["cls"]) + forward_func.extend(gen_codes([line], indent=indent)) + + def prim_isnot(layer, indent=1, init_func=[], forward_func=[]): line = "{} = {} is not {}".format(layer.outputs[0], get_value(layer, "x"), @@ -370,6 +378,12 @@ def prim_type(layer, indent=1, init_func=[], forward_func=[]): forward_func.extend(gen_codes([line], indent=indent)) +def prim_var2list(layer, indent=1, init_func=[], forward_func=[]): + line = "{} = {}.numpy().tolist()".format(layer.outputs[0], + get_value(layer, "input")) + forward_func.extend(gen_codes([line], indent=indent)) + + def prim_warnings(layer, indent=1, init_func=[], forward_func=[]): lines = ["import warnings"] line = "warnings.warn({}, stacklevel={})".format( diff --git a/x2paddle/op_mapper/pytorch2paddle/pytorch_op_mapper.py b/x2paddle/op_mapper/pytorch2paddle/pytorch_op_mapper.py index 937d7bc..26564e8 100644 --- a/x2paddle/op_mapper/pytorch2paddle/pytorch_op_mapper.py +++ b/x2paddle/op_mapper/pytorch2paddle/pytorch_op_mapper.py @@ -81,6 +81,7 @@ class PyTorchOpMapper(OpMapper): node = ivalue.node() if str(ivalue.type()) != "Tensor": graph.set_name(str(ivalue.type()).split(".")[-1]) + continue inputs, outputs = self.data(graph, node, ivalue.unique()) # 转换中间节点 for node in script_graph.nodes(): diff --git a/x2paddle/optimizer/fusion/batchnorm2d_fuser.py b/x2paddle/optimizer/fusion/batchnorm2d_fuser.py index 1a21e26..85f06aa 100644 --- a/x2paddle/optimizer/fusion/batchnorm2d_fuser.py +++ b/x2paddle/optimizer/fusion/batchnorm2d_fuser.py @@ -25,215 +25,122 @@ class BatchNorm2dFuser(FuseBase): def build_pattern(self): """ 描述需要替换的batchnorm2d图结构。 batchnorm2d层模式python实现代码示例: - x2214 = fluid.layers.shape(x2207) - x2214 = len(x2214) - x2215 = x2214 != x2213 - if x2215 : - raise RaiseException(x2212) - if x2218 : - x2220 = self.x2220 - x2221 = x2220 + x2209 - self.x2220 = x2221 - x2227 = False - if x2227 : - x2230 = fluid.layers.shape(x2207.shape) - x2231 = 'Exception' - x2236 = x2230[x2233] - x2237 = len(x2230) - x2238 = x2237 - x2234 - x2241 = x2236 - for _x2240 in range(x2238): - x2242 = _x2240 + x2234 - x2243 = x2230[x2242] - x2244 = x2241 * x2243 - x2239 = x2244 - x2245 = x2239 == x2235 - if x2245 : - raise RaiseException(x2231) - x2248 = self.batchnorm41(x2207) + x336 = fluid.layers.shape(input=x334) + x336 = len(x336) + x337 = x336 != 4 + if x337 : + raise RaiseException('Exception') + if False : + x351 = fluid.layers.shape(input=x334) + x352 = x351[0] + x353 = len(x351) + x354 = x353 - 2 + x357 = x352 + for _x356 in range(x354): + x358 = _x356 + 2 + x359 = x351[x358] + x360 = x357 * x359 + x355 = x360 + x361 = x355 == 1 + if x361 : + raise RaiseException('Exception') + x364 = self.batchnorm7(x334) """ def gen_name(id): return "x" + str(id) -# self.pattern.add_layer( -# "prim.constant", inputs={}, outputs=[gen_name(0)], value=1) -# self.pattern.add_layer( -# "prim.constant", inputs={}, outputs=[gen_name(1)], value=0.1) -# self.pattern.add_layer( -# "prim.constant", inputs={}, outputs=[gen_name(2)], value=0.001) -# self.pattern.add_layer( -# "prim.constant", -# inputs={}, -# outputs=[gen_name(3)], -# value="Exception") -# self.pattern.add_layer( -# "prim.constant", inputs={}, outputs=[gen_name(4)], value=4) - self.pattern.add_layer( "fluid.layers.shape", inputs={'input': "bn-input-0"}, - outputs=[gen_name(5)]) + outputs=[gen_name(0)]) self.pattern.add_layer( - "prim.len", inputs={'input': gen_name(5)}, outputs=[gen_name(5)]) + "prim.len", inputs={'input': gen_name(0)}, outputs=[gen_name(0)]) self.pattern.add_layer( - "prim.ne", - inputs={"x": gen_name(5), - "y": "bn-input-9"}, - outputs=[gen_name(6)]) - self.pattern.add_layer("prim.if", {'input': gen_name(6)}, [gen_name(7)]) + "prim.ne", inputs={"x": gen_name(0)}, outputs=[gen_name(1)], y=4) + self.pattern.add_layer("prim.if", {'input': gen_name(1)}, [gen_name(2)]) if_layer1 = self.pattern.layers[list(self.pattern.layers.keys())[-1]] pattern_block0 = PaddleGraph(if_layer1, graph_type="dygraph") pattern_block0.add_layer( "prim.exception", - inputs={"input": "bn-input-1"}, - outputs=[gen_name(8)]) - if_layer1.inputs["input-0"] = "bn-input-1" + inputs={}, + outputs=[gen_name(3)], + input="Exception") if_layer1.add_block(pattern_block0) pattern_block1 = PaddleGraph(if_layer1, graph_type="dygraph") if_layer1.add_block(pattern_block1) - # self.pattern.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(9)], value=False) - self.pattern.add_layer("prim.if", {'input': "bn-input-2"}, - [gen_name(10)]) + self.pattern.add_layer("prim.if", {}, [gen_name(4)], input=False) if_layer2 = self.pattern.layers[list(self.pattern.layers.keys())[-1]] pattern_block0 = PaddleGraph(if_layer2, graph_type="dygraph") - pattern_block0.add_layer( - "fluid.dygraph.base.to_variable", - inputs={}, - outputs=[gen_name(11)], - value="params[{}]".format(string(gen_name(11)))) - pattern_block0.add_layer( - "prim.add", - inputs={"x": gen_name(11), - "y": "bn-input-3"}, - outputs=[gen_name(12)]) - pattern_block0.add_layer( - "prim.set_attr", - inputs={"input": gen_name(12)}, - outputs=["self." + gen_name(11)]) - if_layer2.inputs["input-0"] = "bn-input-3" - if_layer2.add_block(pattern_block0) - pattern_block1 = PaddleGraph(if_layer2, graph_type="dygraph") - if_layer2.add_block(pattern_block1) - # self.pattern.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(13)], value=True) - # self.pattern.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(14)], value=False) - self.pattern.add_layer("prim.if", {'input': "bn-input-4"}, - [gen_name(15)]) - if_layer3 = self.pattern.layers[list(self.pattern.layers.keys())[-1]] - pattern_block0 = PaddleGraph(if_layer3, graph_type="dygraph") pattern_block0.add_layer( "fluid.layers.shape", inputs={'input': "bn-input-0"}, - outputs=[gen_name(16)]) - # pattern_block0.add_layer( - # "prim.constant", - # inputs={}, - # outputs=[gen_name(17)], - # value="Exception") - # pattern_block0.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(18)], value=True) - # pattern_block0.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(19)], value=0) - # pattern_block0.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(20)], value=2) - # pattern_block0.add_layer( - # "prim.constant", inputs={}, outputs=[gen_name(21)], value=1) + outputs=[gen_name(5)]) pattern_block0.add_layer( "prim.getitem", - inputs={"list": gen_name(16), - "index": "bn-input-6"}, - outputs=[gen_name(22)]) + inputs={"list": gen_name(5)}, + outputs=[gen_name(6)], + index=0) pattern_block0.add_layer( - "prim.len", inputs={"input": gen_name(16)}, outputs=[gen_name(23)]) + "prim.len", inputs={"input": gen_name(5)}, outputs=[gen_name(7)]) pattern_block0.add_layer( - "prim.sub", - inputs={"x": gen_name(23), - "y": "bn-input-7"}, - outputs=[gen_name(24)]) + "prim.sub", inputs={"x": gen_name(7)}, outputs=[gen_name(8)], y=2) pattern_block0.add_layer( - "prim.equal", - inputs={"input": gen_name(22)}, - outputs=[gen_name(25)]) + "prim.equal", inputs={"input": gen_name(6)}, outputs=[gen_name(9)]) pattern_block0.add_layer( "prim.loop", - inputs={"input": gen_name(24)}, - outputs=[gen_name(26), gen_name(27)]) + inputs={"input": gen_name(8)}, + outputs=[gen_name(8.1), gen_name(10)]) loop_layer = pattern_block0.layers[list(pattern_block0.layers.keys())[ -1]] pattern_block0_block0 = PaddleGraph(loop_layer, graph_type="dygraph") pattern_block0_block0.add_layer( - "prim.add", - inputs={"x": gen_name(27), - "y": "bn-input-7"}, - outputs=[gen_name(28)]) + "prim.add", inputs={"x": gen_name(10)}, outputs=[gen_name(11)], y=2) pattern_block0_block0.add_layer( "prim.getitem", - inputs={"list": gen_name(16), - "index": gen_name(28)}, - outputs=[gen_name(29)]) + inputs={"list": gen_name(5), + "index": gen_name(11)}, + outputs=[gen_name(12)]) pattern_block0_block0.add_layer( "prim.mul", - inputs={"x": gen_name(25), - "y": gen_name(29)}, - outputs=[gen_name(30)]) + inputs={"x": gen_name(9), + "y": gen_name(12)}, + outputs=[gen_name(13)]) pattern_block0_block0.add_layer( "prim.equal", - inputs={"input": gen_name(30)}, - outputs=[gen_name(26)]) - loop_layer.inputs["input-1"] = "bn-input-7" - loop_layer.inputs["input-2"] = gen_name(16) - loop_layer.inputs["input-3"] = gen_name(25) + inputs={"input": gen_name(13)}, + outputs=[gen_name(8.1)]) + loop_layer.inputs["input-1"] = gen_name(5) + loop_layer.inputs["input-2"] = gen_name(9) loop_layer.add_block(pattern_block0_block0) pattern_block0.add_layer( - "prim.eq", - inputs={"x": gen_name(26), - "y": "bn-input-8"}, - outputs=[gen_name(31)]) + "prim.eq", inputs={"x": gen_name(8.1)}, outputs=[gen_name(14)], y=1) pattern_block0.add_layer( - "prim.if", inputs={"input": gen_name(31)}, outputs=[gen_name(32)]) - if_layer31 = pattern_block0.layers[list(pattern_block0.layers.keys())[ + "prim.if", inputs={"input": gen_name(14)}, outputs=[gen_name(15)]) + if_layer21 = pattern_block0.layers[list(pattern_block0.layers.keys())[ -1]] - pattern_block0_block0 = PaddleGraph(if_layer31, graph_type="dygraph") + pattern_block0_block0 = PaddleGraph(if_layer21, graph_type="dygraph") pattern_block0_block0.add_layer( "prim.exception", - inputs={"input": "bn-input-5"}, - outputs=[gen_name(33)]) - if_layer31.inputs["input-0"] = "bn-input-5" - if_layer31.add_block(pattern_block0_block0) - pattern_block0_block1 = PaddleGraph(if_layer31, graph_type="dygraph") - if_layer31.add_block(pattern_block0_block1) - if_layer3.add_block(pattern_block0) - pattern_block1 = PaddleGraph(if_layer3, graph_type="dygraph") - if_layer3.add_block(pattern_block1) - if_layer3.inputs["input-0"] = "bn-input-5" - if_layer3.inputs["input-1"] = "bn-input-6" - if_layer3.inputs["input-2"] = "bn-input-7" - if_layer3.inputs["input-3"] = "bn-input-7" - if_layer3.inputs["input-4"] = "bn-input-8" - if_layer3.inputs["input-5"] = "bn-input-0" + inputs={}, + outputs=[gen_name(15)], + input="Exception") + if_layer21.add_block(pattern_block0_block0) + pattern_block0_block1 = PaddleGraph(if_layer21, graph_type="dygraph") + if_layer21.add_block(pattern_block0_block1) + if_layer2.add_block(pattern_block0) + pattern_block1 = PaddleGraph(if_layer2, graph_type="dygraph") + if_layer2.add_block(pattern_block1) + if_layer2.inputs["input-0"] = "bn-input-0" self.pattern.add_layer( "paddle.nn.BatchNorm", inputs={"input": "bn-input-0"}, - outputs=[gen_name(34), gen_name(35)], + outputs=[gen_name(16), gen_name(17)], is_test=True, num_channels=160, momentum=0.1, epsilon=0.001) - self.pattern.build(inputs={ - "input-0": "bn-input-0", - "input-1": "bn-input-1", - "input-2": "bn-input-2", - "input-3": "bn-input-3", - "input-4": "bn-input-4", - "input-5": "bn-input-5", - "input-6": "bn-input-6", - "input-7": "bn-input-7", - "input-8": "bn-input-8", - "input-9": "bn-input-9" - }) + self.pattern.build(inputs={"input-0": "bn-input-0"}) def insert_new_layer(self, graph, parameters, matches): new_layer = self.gen_new_layer(parameters, matches) @@ -241,6 +148,10 @@ class BatchNorm2dFuser(FuseBase): graph.layers[new_layer_id] = new_layer matches.pop(new_layer_id) +# for layer in matches.values(): +# print(layer.outputs) +# print("-------") + def gen_new_layer(self, parameters, matches): layers_id = list(matches.keys()) layer = matches[layers_id[-1]] diff --git a/x2paddle/optimizer/fusion/fc_fuser.py b/x2paddle/optimizer/fusion/fc_fuser.py index 8e27c95..8b2341f 100644 --- a/x2paddle/optimizer/fusion/fc_fuser.py +++ b/x2paddle/optimizer/fusion/fc_fuser.py @@ -28,7 +28,7 @@ class FcFuser(FuseBase): fc层模式python实现代码示例: x133 = x128.shape x133 = len(x133) - x134 = x133 == x131 + x134 = x133 == 2 if x134 : classifier_6_weight = self.classifier_6_weight x136 = fluid.layers.transpose(x=classifier_6_weight, perm=[1, 0]) @@ -55,9 +55,9 @@ class FcFuser(FuseBase): "prim.len", inputs={'input': gen_name(2)}, outputs=[gen_name(2)]) self.pattern.add_layer( "prim.eq", - inputs={"eq0": gen_name(2), - "eq1": "fc-input-1"}, - outputs=[gen_name(3)]) + inputs={"eq0": gen_name(2)}, + outputs=[gen_name(3)], + eq1=2) self.pattern.add_layer("prim.if", {'input': gen_name(3)}, [gen_name(4)]) self.pattern.outputs.append(gen_name(4)) if_layer1 = self.pattern.layers[list(self.pattern.layers.keys())[-1]] @@ -122,9 +122,7 @@ class FcFuser(FuseBase): "prim.equal", inputs={'input': gen_name(13)}, outputs=[gen_name(4)]) if_layer1.add_block(pattern_block1) - self.pattern.build( - inputs={"input-0": "fc-input-0", - "input-1": "fc-input-1"}) + self.pattern.build(inputs={"input-0": "fc-input-0"}) def insert_new_layer(self, graph, parameters, matches): new_layer = self.gen_new_layer(parameters, matches) diff --git a/x2paddle/optimizer/fusion/interpolate_bilinear_fuser.py b/x2paddle/optimizer/fusion/interpolate_bilinear_fuser.py index f368670..9b49039 100644 --- a/x2paddle/optimizer/fusion/interpolate_bilinear_fuser.py +++ b/x2paddle/optimizer/fusion/interpolate_bilinear_fuser.py @@ -21,958 +21,1532 @@ from x2paddle.core.util import * class InterpolateBilinearFuser(FuseBase): def __init__(self): super(InterpolateBilinearFuser, self).__init__(graph_type="dygraph") + import torch + torch_version = torch.__version__ + torch_version_part = torch_version.split(".") + if int(torch_version_part[0]) == 1 and int(torch_version_part[1]) > 5: + self.version_gt_150 = True + else: + self.version_gt_150 = False def build_pattern(self): """ 描述需要替换的双线性插值图结构。 interpolate_bilinear层模式python实现代码示例: - x2834 = 'Exception' - x2835 = None - x2836 = 2 - x2837 = 3 - x2838 = 1 - x2839 = 0 - x2840 = 4 - x2841 = 5 - x2842 = None - x2843 = x2832.shape - x2843 = len(x2843) - x2844 = x2843 - x2836 - x2845 = [] - for _x2847 in range(x2844): - x2845.append(x2835) - x2848 = (x2832, x9, x3, x3) - x2849 = x2832.shape - x2849 = len(x2849) - x2850 = x2849 == x2837 - if x2850 : - raise RaiseException(x2834) - x2851 = x2842 + x3016 = fluid.layers.shape(input=x3005) + x3016 = len(x3016) + x3017 = x3016 - 2 + x3018 = [] + for _x3020 in range(x3017): + x3018.append(None) + x3021 = (x3005, x8, None, None) + x3022 = fluid.layers.shape(input=x3005) + x3022 = len(x3022) + x3023 = x3022 == 3 + if x3023 : + raise RaiseException('Exception') + x3024 = None else: - x2853 = x2832.shape - x2853 = len(x2853) - x2854 = x2853 == x2840 - if x2854 : - x2857 = True - x2858 = 'Exception' - x2859 = False - x2860 = None - x2861 = 'The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. ' - x2862 = 0 - x2863 = 9223372036854775807 - x2864 = 1 - x2865 = 2 - x2866 = None - x2867 = None - x2868 = None - x2869 = None - x2870 = None - x2871, x2872, x2873, x2874 = x2848 - x2875 = x2872 is x2860 - if x2875 : - x2878 = x2873 is x2860 - x2876 = x2878 - x2877 = x2872 + x3026 = fluid.layers.shape(input=x3005) + x3026 = len(x3026) + x3027 = x3026 == 4 + if x3027 : + x3044, x3045, x3046, x3047 = x3021 + x3048 = x3045 is None + if x3048 : + x3051 = x3046 is None + x3049 = x3051 + x3050 = x3045 else: - x2879 = x2872 - x2876 = x2859 - x2877 = x2879 - if x2876 : - raise RaiseException(x2858) - x2882 = x2877 is not x2860 - if x2882 : - x2885 = x2877 - x2886 = x2873 is not x2860 - x2883 = x2886 - x2884 = x2885 + x3052 = x3045 + x3049 = False + x3050 = x3052 + if x3049 : + raise RaiseException('Exception') + x3055 = x3050 is not None + if x3055 : + x3058 = x3050 + x3059 = x3046 is not None + x3056 = x3059 + x3057 = x3058 else: - x2883 = x2859 - x2884 = x2877 - if x2883 : - raise RaiseException(x2858) - x2887 = x2868 - x2888 = x2869 + x3056 = False + x3057 = x3050 + if x3056 : + raise RaiseException('Exception') + x3060 = None + x3061 = None else: - x2887 = x2873 - x2888 = x2884 - x2890 = x2887 is not x2860 - if x2890 : - x2892 = x2887 - x2893 = len(x2892) - x2894 = x2893 != x2836 - if x2894 : - raise RaiseException(x2858) - x2891 = x2892 + x3060 = x3046 + x3061 = x3057 + x3063 = x3060 is not None + if x3063 : + x3065 = x3060 + x3066 = len(x3065) + x3067 = x3066 != 2 + if x3067 : + raise RaiseException('Exception') + x3064 = x3065 else: - x2891 = x2887 - x2897 = x2888 is not x2860 - if x2897 : - x2899 = x2888 - x2898 = x2899 + x3064 = x3060 + x3070 = x3061 is not None + if x3070 : + x3072 = x3061 + x3071 = x3072 else: - x2898 = x2866 - if x2897 : - x2900 = x2898 + x3071 = None + if x3070 : + x3073 = x3071 else: - x2901 = x2891 is not x2860 - if x2901 : - x2903 = x2891 - x2902 = x2903 + x3074 = x3064 is not None + if x3074 : + x3076 = x3064 + x3075 = x3076 else: - raise RaiseException(x2858) - x2902 = x2867 - x2905 = x2874 is x2860 - if x2905 : - x2907 = len(x2902) - x2908 = x2907 > x2862 - x2912 = x2859 - x2913 = x2862 - for x2910 in range(x2863): - x2914 = x2902[x2913] - x2915 = math.floor(x2914) - x2916 = x2915 != x2914 - if x2916 : - x2917 = x2859 - x2918 = x2916 + raise RaiseException('Exception') + x3075 = None + x3078 = x3047 is None + if x3078 : + x3080 = len(x3075) + x3081 = x3080 > 0 + x3086 = 0 + for x3083 in range(2147483647): + x3087 = x3075[x3086] + x3088 = math.floor(x3087) + x3089 = x3088 != x3087 + if x3089 : + x3090 = False + x3091 = x3089 else: - x2917 = x2870 - x2918 = x2870 - if x2916 : - x2919 = x2917 - x2920 = x2918 + x3090 = None + x3091 = None + if x3089 : + x3092 = x3090 + x3093 = x3091 else: - x2919 = x2857 - x2920 = x2916 - x2921 = x2913 + x2864 - x2922 = x2921 < x2907 - x2923 = x2922 and x2919 - x2909 = x2920 - x2910 = x2921 - if x2909 : + x3092 = True + x3093 = x3089 + x3094 = x3086 + 1 + x3095 = x3094 < x3080 + x3096 = x3095 and x3092 + x3082 = x3093 + x3083 = x3094 + if x3082 : import warnings - warnings.warn(x2861, stacklevel=2) - x2926 = [] - for _x2928 in range(x2836): - x2929 = _x2928 + x2865 - x2930 = x2871.shape - x2931 = float(x2930) - x2932 = x2902[_x2928] - x2933 = x2931 * x2932 - x2934 = math.floor(x2933) - x2926.append(x2934) - x2900 = x2926 - x2935 = x2845[x2839] - x2936 = x2845[x2838] - assert x2935 == x2936, 'The x2935 must be x2936!' - x2937 = fluid.layers.interpolate( - input=x2832, out_shape=x2900, scale=x2935, align_corners=False, align_mode=0) - x2855 = x2937 + warnings.warn('The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. ', stacklevel=2) + x3099 = [] + for _x3101 in range(2): + x3102 = _x3101 + 2 + x3103 = fluid.layers.shape(x3044)[x3102] + x3104 = float(x3103) + x3105 = x3075[_x3101] + x3106 = x3104 * x3105 + x3107 = math.floor(x3106) + x3099.append(x3107) + x3073 = x3099 + x3108 = x3018[0] + x3109 = x3018[1] + x3073_isinstance = isinstance(x3073, paddle.fluid.Variable) + if x3073_isinstance : + x3073 = x3073.numpy().tolist() + assert x3108 == x3109, 'The x3108 must be x3109!' + x3110 = paddle.nn.functional.interpolate(x=x3005, size=x3073, scale_factor=x3108, align_corners=False, align_mode=0) + x3028 = x3110 else: - x2938 = x2832.shape - x2938 = len(x2938) - x2939 = x2938 == x2841 - if x2939 : - raise RaiseException(x2834) + x3111 = fluid.layers.shape(input=x3005) + x3111 = len(x3111) + x3112 = x3111 == 5 + if x3112 : + raise RaiseException('Exception') else: - raise RaiseException(x2834) - x2855 = x2842 - x2851 = x2855 + raise RaiseException('Exception') + x3028 = None + x3024 = x3028 """ def gen_name(id): return "x" + str(id) - self.pattern.add_layer( - "prim.constant", - inputs={}, - outputs=[gen_name(0)], - value="Exception") - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(1)], value=None) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(2)], value=2) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(3)], value=3) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(4)], value=1) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(5)], value=0) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(6)], value=4) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(7)], value=5) - self.pattern.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(8)], value=None) - self.pattern.add_layer( - "prim.shape", - inputs={"input": "interpolate-input-0"}, - outputs=[gen_name(9)]) - self.pattern.add_layer( - "prim.len", inputs={"input": gen_name(9)}, outputs=[gen_name(9)]) - self.pattern.add_layer( - "prim.sub", - inputs={"x": gen_name(9), - "y": gen_name(2)}, - outputs=[gen_name(10)]) - self.pattern.add_layer("prim.list", inputs={}, outputs=[gen_name(11)]) - self.pattern.add_layer( - "prim.loop", - inputs={"input": gen_name(10)}, - outputs=[gen_name(12.1), gen_name(12.2)]) - loop_layer = self.pattern.layers[list(self.pattern.layers.keys())[-1]] - pattern_block = PaddleGraph(loop_layer, graph_type="dygraph") - pattern_block.add_layer( - "prim.append", - inputs={"list": gen_name(11), - "element": gen_name(1)}, - outputs=[]) - loop_layer.inputs["input-0"] = gen_name(11) - loop_layer.inputs["input-1"] = gen_name(1) - loop_layer.add_block(pattern_block) - self.pattern.add_layer( - "prim.tuple", - inputs={ - "input0": "interpolate-input-0", - "input1": "interpolate-input-1", - "input2": "interpolate-input-2", - "input3": "interpolate-input-2" - }, - outputs=[gen_name(13)]) - self.pattern.add_layer( - "prim.shape", - inputs={"input": "interpolate-input-0"}, - outputs=[gen_name(14)]) - self.pattern.add_layer( - "prim.len", inputs={"input": gen_name(14)}, outputs=[gen_name(14)]) - self.pattern.add_layer( - "prim.eq", - inputs={"x": gen_name(14), - "y": gen_name(3)}, - outputs=[gen_name(15)]) - self.pattern.add_layer( - "prim.if", inputs={"input": gen_name(15)}, outputs=[gen_name(16)]) - if_layer1 = self.pattern.layers[list(self.pattern.layers.keys())[-1]] - pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") - pattern_block.add_layer( - "prim.exception", - inputs={"input": gen_name(0)}, - outputs=[gen_name(17)]) - pattern_block.add_layer( - "prim.equal", inputs={"input": gen_name(8)}, - outputs=[gen_name(16)]) - if_layer1.inputs["input-0"] = gen_name(0) - if_layer1.inputs["input-1"] = gen_name(8) - if_layer1.add_block(pattern_block) - pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") - pattern_block.add_layer( - "prim.shape", - inputs={"input": "interpolate-input-0"}, - outputs=[gen_name(18)]) - pattern_block.add_layer( - "prim.len", inputs={"input": gen_name(18)}, outputs=[gen_name(18)]) - pattern_block.add_layer( - "prim.eq", - inputs={"x": gen_name(18), - "y": gen_name(6)}, - outputs=[gen_name(19)]) - pattern_block.add_layer( - "prim.if", inputs={"input": gen_name(19)}, outputs=[gen_name(20)]) - if_layer2 = pattern_block.layers[list(pattern_block.layers.keys())[-1]] - pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(21)], value=False) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(22)], value=True) - pattern_block_block.add_layer( - "prim.constant", - inputs={}, - outputs=[gen_name(23)], - value="Exception") - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(24)], value=False) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(25)], value=None) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(26)], value="") - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(26.1)], value=0) - pattern_block_block.add_layer( - "prim.constant", - inputs={}, - outputs=[gen_name(26.2)], - value=9223372036854775807) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(27)], value=1) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(28)], value=2) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(29)], value=None) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(30)], value=None) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(31)], value=None) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(32)], value=None) - pattern_block_block.add_layer( - "prim.constant", inputs={}, outputs=[gen_name(33)], value=None) - pattern_block_block.add_layer( - "prim.tuple_unpack", - inputs={"input": gen_name(13)}, - outputs=[gen_name(34), gen_name(35), gen_name(36), gen_name(37)]) - pattern_block_block.add_layer( - "prim.is", - inputs={"x": gen_name(35), - "y": gen_name(25)}, - outputs=[gen_name(38)]) - pattern_block_block.add_layer( - "prim.if", - inputs={"input": gen_name(38)}, - outputs=[gen_name(39), gen_name(40)]) - if_layer3 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer3, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.is", - inputs={"x": gen_name(36), - "y": gen_name(25)}, - outputs=[gen_name(41)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(41)}, - outputs=[gen_name(39)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(35)}, - outputs=[gen_name(40)]) - if_layer3.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer3, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(35)}, - outputs=[gen_name(42)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(24)}, - outputs=[gen_name(39)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(35)}, - outputs=[gen_name(40)]) - if_layer3.add_block(pattern_block_block_block) - if_layer3.inputs.update({ - "input-0": gen_name(36), - 'input-1': gen_name(25), - 'input-2': gen_name(35), - 'input-3': gen_name(35), - 'input-4': gen_name(24) - }) - pattern_block_block.add_layer( - "prim.if", inputs={"input": gen_name(39)}, outputs=[gen_name(43)]) - if_layer4 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer4, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(23)}, - outputs=[gen_name(44)]) - if_layer4.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer4, graph_type="dygraph") - if_layer4.add_block(pattern_block_block_block) - if_layer4.inputs["input-0"] = gen_name(23) - pattern_block_block.add_layer( - "prim.isnot", - inputs={"x": gen_name(40), - "y": gen_name(25)}, - outputs=[gen_name(45)]) - pattern_block_block.add_layer( - "prim.if", - inputs={"input": gen_name(45)}, - outputs=[gen_name(46), gen_name(47)]) - if_layer5 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer5, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(40)}, - outputs=[gen_name(48)]) - pattern_block_block_block.add_layer( - "prim.isnot", - inputs={"x": gen_name(36), - "y": gen_name(25)}, - outputs=[gen_name(49)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(49)}, - outputs=[gen_name(46)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(48)}, - outputs=[gen_name(47)]) - if_layer5.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer5, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(24)}, - outputs=[gen_name(46)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(40)}, - outputs=[gen_name(47)]) - if_layer5.add_block(pattern_block_block_block) - if_layer5.inputs.update({ - "input-0": gen_name(40), - "input-1": gen_name(36), - "input-2": gen_name(25), - "input-3": gen_name(24), - "input-4": gen_name(40) - }) - pattern_block_block.add_layer( - "prim.if", - inputs={"input": gen_name(46)}, - outputs=[gen_name(50), gen_name(51)]) - if_layer6 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer6, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(23)}, - outputs=[gen_name(52)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(31)}, - outputs=[gen_name(50)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(32)}, - outputs=[gen_name(51)]) - if_layer6.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer6, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(36)}, - outputs=[gen_name(50)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(47)}, - outputs=[gen_name(51)]) - if_layer6.add_block(pattern_block_block_block) - if_layer6.inputs.update({ - "input-0": gen_name(23), - "input-1": gen_name(31), - "input-2": gen_name(32), - "input-3": gen_name(36), - "input-4": gen_name(47) - }) - pattern_block_block.add_layer( - "prim.isnot", - inputs={"x": gen_name(50), - "y": gen_name(25)}, - outputs=[gen_name(53)]) - pattern_block_block.add_layer( - "prim.if", inputs={"input": gen_name(53)}, outputs=[gen_name(54)]) - if_layer7 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer7, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(50)}, - outputs=[gen_name(55)]) - pattern_block_block_block.add_layer( - "prim.len", inputs={"input": gen_name(55)}, outputs=[gen_name(56)]) - pattern_block_block_block.add_layer( - "prim.ne", - inputs={"x": gen_name(56), - "y": gen_name(2)}, - outputs=[gen_name(57)]) - pattern_block_block_block.add_layer( - "prim.if", inputs={"input": gen_name(57)}, outputs=[gen_name(58)]) - if_layer8 = pattern_block_block_block.layers[list( - pattern_block_block_block.layers.keys())[-1]] - pattern_block_block_block_block = PaddleGraph( - if_layer8, graph_type="dygraph") - pattern_block_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(23)}, - outputs=[gen_name(59)]) - if_layer8.add_block(pattern_block_block_block_block) - pattern_block_block_block_block = PaddleGraph( - if_layer8, graph_type="dygraph") - if_layer8.add_block(pattern_block_block_block_block) - if_layer8.inputs["input-0"] = gen_name(23) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(55)}, - outputs=[gen_name(54)]) - if_layer7.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer7, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(50)}, - outputs=[gen_name(54)]) - if_layer7.add_block(pattern_block_block_block) - if_layer7.inputs.update({ - "input-0": gen_name(50), - "input-1": gen_name(2), - "input-2": gen_name(23), - "input-3": gen_name(50) - }) - pattern_block_block.add_layer( - "prim.isnot", - inputs={"x": gen_name(51), - "y": gen_name(25)}, - outputs=[gen_name(60)]) - pattern_block_block.add_layer( - "prim.if", inputs={"input": gen_name(60)}, outputs=[gen_name(61)]) - if_layer9 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph(if_layer9, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(51)}, - outputs=[gen_name(62)]) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(62)}, - outputs=[gen_name(61)]) - if_layer9.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph(if_layer9, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(29)}, - outputs=[gen_name(61)]) - if_layer9.add_block(pattern_block_block_block) - if_layer9.inputs.update({ - "input-0": gen_name(51), - "input-1": gen_name(29) - }) - pattern_block_block.add_layer( - "prim.if", inputs={"input": gen_name(60)}, outputs=[gen_name(63)]) - if_layer10 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph( - if_layer10, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(61)}, - outputs=[gen_name(63)]) - if_layer10.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph( - if_layer10, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.isnot", - inputs={"x": gen_name(54), - "y": gen_name(25)}, - outputs=[gen_name(64)]) - pattern_block_block_block.add_layer( - "prim.if", inputs={"input": gen_name(64)}, outputs=[gen_name(65)]) - if_layer11 = pattern_block_block_block.layers[list( - pattern_block_block_block.layers.keys())[-1]] - pattern_block_block_block_block = PaddleGraph( - if_layer11, graph_type="dygraph") - pattern_block_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(54)}, - outputs=[gen_name(66)]) - pattern_block_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(66)}, - outputs=[gen_name(65)]) - if_layer11.add_block(pattern_block_block_block_block) - pattern_block_block_block_block = PaddleGraph( - if_layer11, graph_type="dygraph") - pattern_block_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(23)}, - outputs=[gen_name(67)]) - pattern_block_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(30)}, - outputs=[gen_name(65)]) - if_layer11.add_block(pattern_block_block_block_block) - if_layer11.inputs.update({ - "input-0": gen_name(54), - "input-1": gen_name(23), - "input-2": gen_name(30) - }) - pattern_block_block_block.add_layer( - "prim.is", - inputs={"x": gen_name(37), - "y": gen_name(25)}, - outputs=[gen_name(68)]) - pattern_block_block_block.add_layer( - "prim.if", inputs={"input": gen_name(68)}, outputs=[gen_name(69)]) - if_layer12 = pattern_block_block_block.layers[list( - pattern_block_block_block.layers.keys())[-1]] - pattern_block_block_block_block = PaddleGraph( - if_layer12, graph_type="dygraph") - pattern_block_block_block_block.add_layer( - "prim.len", inputs={"input": gen_name(65)}, outputs=[gen_name(70)]) - pattern_block_block_block_block.add_layer( - "prim.gt", - inputs={"x": gen_name(70), - "y": gen_name(26.1)}, - outputs=[gen_name(71)]) - pattern_block_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(24)}, - outputs=[gen_name(72)]) - pattern_block_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(26.1)}, - outputs=[gen_name(73)]) - pattern_block_block_block_block.add_layer( - "prim.loop", - inputs={"input": gen_name(26.2)}, - outputs=[gen_name(74), gen_name(75), gen_name(76)]) - loop_layer = pattern_block_block_block_block.layers[list( - pattern_block_block_block_block.layers.keys())[-1]] - pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") - pattern_loop_block.add_layer( - "prim.getitem", - inputs={"list": gen_name(65), - "element": gen_name(73)}, - outputs=[gen_name(74.1)]) - pattern_loop_block.add_layer( - "prim.floor", - inputs={"input": gen_name(74.1)}, - outputs=[gen_name(75.1)]) - pattern_loop_block.add_layer( - "prim.ne", - inputs={"x": gen_name(75.1), - "y": gen_name(74.1)}, - outputs=[gen_name(76)]) - pattern_loop_block.add_layer( - "prim.if", - inputs={"input": gen_name(76)}, - outputs=[gen_name(77), gen_name(78)]) - if_layer13 = pattern_loop_block.layers[list( - pattern_loop_block.layers.keys())[-1]] - pattern_loop_block_block = PaddleGraph(if_layer13, graph_type="dygraph") - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(24)}, - outputs=[gen_name(77)]) - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(76)}, - outputs=[gen_name(78)]) - if_layer13.add_block(pattern_loop_block_block) - pattern_loop_block_block = PaddleGraph(if_layer13, graph_type="dygraph") - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(33)}, - outputs=[gen_name(77)]) - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(33)}, - outputs=[gen_name(78)]) - if_layer13.add_block(pattern_loop_block_block) - if_layer13.inputs.update({ - "input-0": gen_name(24), - "input-1": gen_name(76), - "input-2": gen_name(33), - "input-3": gen_name(33) - }) - pattern_loop_block.add_layer( - "prim.if", - inputs={"input": gen_name(76)}, - outputs=[gen_name(79), gen_name(80)]) - if_layer14 = pattern_loop_block.layers[list( - pattern_loop_block.layers.keys())[-1]] - pattern_loop_block_block = PaddleGraph(if_layer14, graph_type="dygraph") - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(77)}, - outputs=[gen_name(79)]) - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(78)}, - outputs=[gen_name(80)]) - if_layer14.add_block(pattern_loop_block_block) - pattern_loop_block_block = PaddleGraph(if_layer14, graph_type="dygraph") - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(22)}, - outputs=[gen_name(79)]) - pattern_loop_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(76)}, - outputs=[gen_name(80)]) - if_layer14.add_block(pattern_loop_block_block) - if_layer14.inputs.update({ - "input-0": gen_name(77), - "input-1": gen_name(78), - "input-2": gen_name(22), - "input-3": gen_name(76) - }) - pattern_loop_block.add_layer( - "prim.add", - inputs={"x": gen_name(73), - "y": gen_name(27)}, - outputs=[gen_name(81)]) - pattern_loop_block.add_layer( - "prim.lt", - inputs={"x": gen_name(81), - "y": gen_name(70)}, - outputs=[gen_name(82)]) - pattern_loop_block.add_layer( - "prim.and", - inputs={"x": gen_name(82), - "y": gen_name(79)}, - outputs=[gen_name(83)]) - pattern_loop_block.add_layer( - "prim.equal", - inputs={"input": gen_name(80)}, - outputs=[gen_name(74)]) - pattern_loop_block.add_layer( - "prim.equal", - inputs={"input": gen_name(81)}, - outputs=[gen_name(75)]) - loop_layer.add_block(pattern_loop_block) - loop_layer.inputs.update({ - "input-0": gen_name(65), - "input-1": gen_name(73), - "input-2": gen_name(24), - "input-3": gen_name(33), - "input-4": gen_name(33), - "input-5": gen_name(22), - "input-6": gen_name(73), - "input-7": gen_name(27), - "input-8": gen_name(70) - }) - pattern_block_block_block_block.add_layer( - "prim.if", inputs={"input": gen_name(74)}, outputs=[gen_name(84)]) - if_layer15 = pattern_block_block_block_block.layers[list( - pattern_block_block_block_block.layers.keys())[-1]] - pattern_block_block_block_block_block = PaddleGraph( - if_layer15, graph_type="dygraph") - pattern_block_block_block_block_block.add_layer( - "prim.warnings", - inputs={"input": gen_name(26)}, - outputs=[gen_name(85)], - stacklevel=2) - if_layer15.add_block(pattern_block_block_block_block_block) - pattern_block_block_block_block_block = PaddleGraph( - if_layer15, graph_type="dygraph") - if_layer15.add_block(pattern_block_block_block_block_block) - if_layer15.inputs["input-0"] = gen_name(26) - if_layer12.add_block(pattern_block_block_block_block) - pattern_block_block_block_block = PaddleGraph( - if_layer12, graph_type="dygraph") - if_layer12.add_block(pattern_block_block_block_block) - if_layer12.inputs.update({ - "input-0": gen_name(65), - "input-1": gen_name(26.1), - "input-2": gen_name(26.2), - "input-3": gen_name(65), - "input-4": gen_name(24), - "input-5": gen_name(33), - "input-6": gen_name(33), - "input-7": gen_name(22), - "input-8": gen_name(27), - "input-9": gen_name(26) - }) - pattern_block_block_block.add_layer( - "prim.list", inputs={}, outputs=[gen_name(86)]) - pattern_block_block_block.add_layer( - "prim.loop", - inputs={"input": gen_name(2)}, - outputs=[gen_name(87), gen_name(88)]) - loop_layer = pattern_block_block_block.layers[list( - pattern_block_block_block.layers.keys())[-1]] - pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") - pattern_loop_block.add_layer( - "prim.add", - inputs={"x": gen_name(88), - "y": gen_name(28)}, - outputs=[gen_name(89)]) - pattern_loop_block.add_layer( - "prim.shape", - inputs={"input": gen_name(34)}, - outputs=[gen_name(90)]) - pattern_loop_block.add_layer( - "prim.float", - inputs={"input": gen_name(90)}, - outputs=[gen_name(91)]) - pattern_loop_block.add_layer( - "prim.getitem", - inputs={"list": gen_name(65), - "element": gen_name(88)}, - outputs=[gen_name(92)]) - pattern_loop_block.add_layer( - "prim.mul", - inputs={"x": gen_name(91), - "y": gen_name(92)}, - outputs=[gen_name(93)]) - pattern_loop_block.add_layer( - "prim.floor", - inputs={"input": gen_name(93)}, - outputs=[gen_name(94)]) - pattern_loop_block.add_layer( - "prim.append", - inputs={"list": gen_name(86), - "element": gen_name(94)}, - outputs=[]) - loop_layer.add_block(pattern_loop_block) - loop_layer.inputs.update({ - "input-1": gen_name(28), - "input-2": gen_name(34), - "input-3": gen_name(65), - "input-5": gen_name(86) - }) - pattern_block_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(86)}, - outputs=[gen_name(63)]) - if_layer10.add_block(pattern_block_block_block) - if_layer10.inputs.update({ - "input-0": gen_name(61), - "input-1": gen_name(54), - "input-2": gen_name(25), - "input-3": gen_name(54), - "input-4": gen_name(23), - "input-5": gen_name(30), - "input-6": gen_name(37), - "input-7": gen_name(25), - "input-8": gen_name(26.1), - "input-9": gen_name(26.2), - "input-10": gen_name(24), - "input-11": gen_name(33), - "input-12": gen_name(33), - "input-13": gen_name(22), - "input-14": gen_name(27), - "input-15": gen_name(26), - "input-16": gen_name(2), - "input-17": gen_name(28), - "input-18": gen_name(34) - }) - pattern_block_block.add_layer( - "prim.getitem", - inputs={"list": gen_name(11), - "element": gen_name(5)}, - outputs=[gen_name(95)]) - pattern_block_block.add_layer( - "prim.getitem", - inputs={"list": gen_name(11), - "element": gen_name(4)}, - outputs=[gen_name(96)]) - pattern_block_block.add_layer( - "prim.assert", - inputs={"key": gen_name(95), - "value": gen_name(96)}, - outputs=[gen_name(97) + "_assert"], - type="eq") - pattern_block_block.add_layer( - "fluid.layers.interpolate", - inputs={ - "input": "interpolate-input-0", - "out_shape": gen_name(63), - "scale": gen_name(95) - }, - outputs=[gen_name(97)], - align_corners=False, - align_mode=0) - pattern_block_block.add_layer( - "prim.equal", - inputs={"input": gen_name(97)}, - outputs=[gen_name(20)]) - if_layer2.add_block(pattern_block_block) - pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") - pattern_block_block.add_layer( - "prim.shape", - inputs={"input": "interpolate-input-0"}, - outputs=[gen_name(98)]) - pattern_block_block.add_layer( - "prim.len", inputs={"input": gen_name(98)}, outputs=[gen_name(98)]) - pattern_block_block.add_layer( - "prim.eq", - inputs={"x": gen_name(98), - "y": gen_name(7)}, - outputs=[gen_name(99)]) - pattern_block_block.add_layer( - "prim.if", inputs={"input": gen_name(99)}, outputs=[gen_name(100)]) - if_layer16 = pattern_block_block.layers[list( - pattern_block_block.layers.keys())[-1]] - pattern_block_block_block = PaddleGraph( - if_layer16, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(0)}, - outputs=[gen_name(101)]) - if_layer16.add_block(pattern_block_block_block) - pattern_block_block_block = PaddleGraph( - if_layer16, graph_type="dygraph") - pattern_block_block_block.add_layer( - "prim.exception", - inputs={"input": gen_name(0)}, - outputs=[gen_name(102)]) - if_layer16.add_block(pattern_block_block_block) - if_layer16.inputs.update({ - "input-0": gen_name(0), - "input-1": gen_name(0) - }) - pattern_block_block.add_layer( - "prim.equal", inputs={"input": gen_name(8)}, - outputs=[gen_name(20)]) - if_layer2.add_block(pattern_block_block) - if_layer2.inputs.update({ - "input-0": gen_name(13), - "input-1": gen_name(2), - "input-2": gen_name(2), - "input-3": gen_name(11), - "input-4": gen_name(5), - "input-5": gen_name(11), - "input-6": gen_name(4), - "input-7": "interpolate-input-0", - "input-8": "interpolate-input-0", - "input-9": gen_name(7), - "input-10": gen_name(0), - "input-11": gen_name(0), - "input-12": gen_name(8) - }) - pattern_block.add_layer( - "prim.equal", - inputs={"input": gen_name(20)}, - outputs=[gen_name(16)]) - if_layer1.add_block(pattern_block) - if_layer1.inputs.update({ - "input-0": gen_name(0), - "input-1": gen_name(8), - "input-2": "interpolate-input-0", - "input-3": gen_name(6), - "input-4": gen_name(13), - "input-5": gen_name(2), - "input-6": gen_name(2), - "input-7": gen_name(11), - "input-8": gen_name(5), - "input-9": gen_name(11), - "input-10": gen_name(4), - "input-11": "interpolate-input-0", - "input-12": "interpolate-input-0", - "input-13": gen_name(7), - "input-14": gen_name(0), - "input-15": gen_name(0), - "input-16": gen_name(8) - }) - self.pattern.build(inputs={ - "input-0": "interpolate-input-0", - "input-1": "interpolate-input-1", - "input-2": "interpolate-input-2", - }) + if self.version_gt_150: + self.pattern.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(9)]) + self.pattern.add_layer( + "prim.len", + inputs={"input": gen_name(9)}, + outputs=[gen_name(9)]) + self.pattern.add_layer( + "prim.sub", + inputs={"x": gen_name(9)}, + outputs=[gen_name(10)], + y=2) + self.pattern.add_layer( + "prim.list", inputs={}, outputs=[gen_name(11)]) + self.pattern.add_layer( + "prim.loop", + inputs={"input": gen_name(10)}, + outputs=[gen_name(12.1), gen_name(12.2)]) + loop_layer = self.pattern.layers[list(self.pattern.layers.keys())[ + -1]] + pattern_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_block.add_layer( + "prim.append", + inputs={"list": gen_name(11)}, + outputs=[], + element=None) + loop_layer.inputs["input-0"] = gen_name(11) + loop_layer.add_block(pattern_block) + self.pattern.add_layer( + "prim.tuple", + inputs={ + "input0": "interpolate-input-0", + "input1": "interpolate-input-1", + }, + outputs=[gen_name(13)], + input2=None, + input3=None) + self.pattern.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(14)]) + self.pattern.add_layer( + "prim.len", + inputs={"input": gen_name(14)}, + outputs=[gen_name(14)]) + self.pattern.add_layer( + "prim.eq", + inputs={"x": gen_name(14)}, + outputs=[gen_name(15)], + y=3) + self.pattern.add_layer( + "prim.if", + inputs={"input": gen_name(15)}, + outputs=[gen_name(16)]) + if_layer1 = self.pattern.layers[list(self.pattern.layers.keys())[ + -1]] + pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") + pattern_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(17)], + input="Exception") + pattern_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(16)], input=None) + if_layer1.add_block(pattern_block) + pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") + pattern_block.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(18)]) + pattern_block.add_layer( + "prim.len", + inputs={"input": gen_name(18)}, + outputs=[gen_name(18)]) + pattern_block.add_layer( + "prim.eq", + inputs={"x": gen_name(18)}, + outputs=[gen_name(19)], + y=4) + pattern_block.add_layer( + "prim.if", + inputs={"input": gen_name(19)}, + outputs=[gen_name(20)]) + if_layer2 = pattern_block.layers[list(pattern_block.layers.keys())[ + -1]] + pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") + pattern_block_block.add_layer( + "prim.tuple_unpack", + inputs={"input": gen_name(13)}, + outputs=[ + gen_name(34), gen_name(35), gen_name(36), gen_name(37) + ]) + pattern_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(35)}, + outputs=[gen_name(38)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(38)}, + outputs=[gen_name(39), gen_name(40)]) + if_layer3 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer3, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(36)}, + outputs=[gen_name(41)], + y=None) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(41)}, + outputs=[gen_name(39)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(40)]) + if_layer3.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer3, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(42)]) + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(39)], input=False) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(40)]) + if_layer3.add_block(pattern_block_block_block) + if_layer3.inputs.update({ + "input-0": gen_name(36), + 'input-1': gen_name(35), + 'input-2': gen_name(35), + }) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(39)}, + outputs=[gen_name(43)]) + if_layer4 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer4, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(44)], + input="Exception") + if_layer4.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer4, graph_type="dygraph") + if_layer4.add_block(pattern_block_block_block) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(40)}, + outputs=[gen_name(45)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(45)}, + outputs=[gen_name(46), gen_name(47)]) + if_layer5 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer5, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(40)}, + outputs=[gen_name(48)]) + pattern_block_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(36)}, + outputs=[gen_name(49)], + y=None) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(49)}, + outputs=[gen_name(46)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(48)}, + outputs=[gen_name(47)]) + if_layer5.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer5, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(46)], input=False) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(40)}, + outputs=[gen_name(47)]) + if_layer5.add_block(pattern_block_block_block) + if_layer5.inputs.update({ + "input-0": gen_name(40), + "input-1": gen_name(36), + "input-3": gen_name(40) + }) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(46)}, + outputs=[gen_name(50), gen_name(51)]) + if_layer6 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer6, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(52)], + input="Exception") + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(50)], input=None) + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(51)], input=None) + if_layer6.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer6, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(36)}, + outputs=[gen_name(50)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(47)}, + outputs=[gen_name(51)]) + if_layer6.add_block(pattern_block_block_block) + if_layer6.inputs.update({ + "input-0": gen_name(36), + "input-1": gen_name(47) + }) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(50)}, + outputs=[gen_name(53)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(53)}, + outputs=[gen_name(54)]) + if_layer7 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer7, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(50)}, + outputs=[gen_name(55)]) + pattern_block_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(55)}, + outputs=[gen_name(56)]) + pattern_block_block_block.add_layer( + "prim.ne", + inputs={"x": gen_name(56)}, + outputs=[gen_name(57)], + y=2) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(57)}, + outputs=[gen_name(58)]) + if_layer8 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer8, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(59)], + input="Exception") + if_layer8.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer8, graph_type="dygraph") + if_layer8.add_block(pattern_block_block_block_block) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(55)}, + outputs=[gen_name(54)]) + if_layer7.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer7, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(50)}, + outputs=[gen_name(54)]) + if_layer7.add_block(pattern_block_block_block) + if_layer7.inputs.update({ + "input-0": gen_name(50), + "input-1": gen_name(50) + }) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(51)}, + outputs=[gen_name(60)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(60)}, + outputs=[gen_name(61)]) + if_layer9 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer9, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(51)}, + outputs=[gen_name(62)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(62)}, + outputs=[gen_name(61)]) + if_layer9.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer9, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(54)}, + outputs=[gen_name(64)], + y=None) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(64)}, + outputs=[gen_name(65)]) + if_layer11 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer11, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(54)}, + outputs=[gen_name(66)]) + pattern_block_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(66)}, + outputs=[gen_name(65)]) + if_layer11.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer11, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(67)], + input="Exception") + pattern_block_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(65)], input=None) + if_layer11.add_block(pattern_block_block_block_block) + if_layer11.inputs.update({"input-0": gen_name(54), }) + pattern_block_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(37)}, + outputs=[gen_name(68)], + y=None) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(68)}, + outputs=[gen_name(69)]) + if_layer12 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer12, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(65)}, + outputs=[gen_name(70)]) + pattern_block_block_block_block.add_layer( + "prim.gt", + inputs={"x": gen_name(70)}, + outputs=[gen_name(71)], + y=0) + pattern_block_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(72)], input=0) + pattern_block_block_block_block.add_layer( + "prim.loop", + inputs={}, + outputs=[gen_name(74), gen_name(75), gen_name(76.1)], + input=2147483647) + loop_layer = pattern_block_block_block_block.layers[list( + pattern_block_block_block_block.layers.keys())[-1]] + pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_loop_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(65), + "element": gen_name(72)}, + outputs=[gen_name(74.1)]) + pattern_loop_block.add_layer( + "prim.floor", + inputs={"input": gen_name(74.1)}, + outputs=[gen_name(75.1)]) + pattern_loop_block.add_layer( + "prim.ne", + inputs={"x": gen_name(75.1), + "y": gen_name(74.1)}, + outputs=[gen_name(76)]) + pattern_loop_block.add_layer( + "prim.if", + inputs={"input": gen_name(76)}, + outputs=[gen_name(77)]) + if_layer13 = pattern_loop_block.layers[list( + pattern_loop_block.layers.keys())[-1]] + pattern_loop_block_block = PaddleGraph( + if_layer13, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(77)], input=False) + if_layer13.add_block(pattern_loop_block_block) + pattern_loop_block_block = PaddleGraph( + if_layer13, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(77)], input=True) + if_layer13.add_block(pattern_loop_block_block) + pattern_loop_block.add_layer( + "prim.add", + inputs={"x": gen_name(72)}, + outputs=[gen_name(81)], + y=1) + pattern_loop_block.add_layer( + "prim.lt", + inputs={"x": gen_name(81), + "y": gen_name(70)}, + outputs=[gen_name(82)]) + pattern_loop_block.add_layer( + "prim.and", + inputs={"x": gen_name(82), + "y": gen_name(77)}, + outputs=[gen_name(83)]) + pattern_loop_block.add_layer( + "prim.equal", + inputs={"input": gen_name(76)}, + outputs=[gen_name(74)]) + pattern_loop_block.add_layer( + "prim.equal", + inputs={"input": gen_name(81)}, + outputs=[gen_name(75)]) + loop_layer.add_block(pattern_loop_block) + loop_layer.inputs.update({ + "input-0": gen_name(65), + "input-1": gen_name(72), + "input-2": gen_name(72), + "input-3": gen_name(70) + }) + pattern_block_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(74)}, + outputs=[gen_name(84)]) + if_layer15 = pattern_block_block_block_block.layers[list( + pattern_block_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block_block = PaddleGraph( + if_layer15, graph_type="dygraph") + pattern_block_block_block_block_block.add_layer( + "prim.warnings", + inputs={}, + outputs=[gen_name(85)], + stacklevel=2, + input="...") + if_layer15.add_block(pattern_block_block_block_block_block) + pattern_block_block_block_block_block = PaddleGraph( + if_layer15, graph_type="dygraph") + if_layer15.add_block(pattern_block_block_block_block_block) + if_layer12.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer12, graph_type="dygraph") + if_layer12.add_block(pattern_block_block_block_block) + if_layer12.inputs.update({ + "input-0": gen_name(65), + "input-1": gen_name(65), + }) + pattern_block_block_block.add_layer( + "prim.list", inputs={}, outputs=[gen_name(86)]) + pattern_block_block_block.add_layer( + "prim.loop", + inputs={}, + outputs=[gen_name(87), gen_name(88)], + input=2) + loop_layer = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_loop_block.add_layer( + "prim.add", + inputs={"x": gen_name(88)}, + outputs=[gen_name(89)], + y=2) + pattern_loop_block.add_layer( + "prim.shape_dim", + inputs={"input": gen_name(34), + "dim": gen_name(89)}, + outputs=[gen_name(90)]) + pattern_loop_block.add_layer( + "prim.float", + inputs={"input": gen_name(90)}, + outputs=[gen_name(91)]) + pattern_loop_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(65), + "element": gen_name(88)}, + outputs=[gen_name(92)]) + pattern_loop_block.add_layer( + "prim.mul", + inputs={"x": gen_name(91), + "y": gen_name(92)}, + outputs=[gen_name(93)]) + pattern_loop_block.add_layer( + "prim.floor", + inputs={"input": gen_name(93)}, + outputs=[gen_name(94)]) + pattern_loop_block.add_layer( + "prim.append", + inputs={"list": gen_name(86), + "element": gen_name(94)}, + outputs=[]) + loop_layer.add_block(pattern_loop_block) + loop_layer.inputs.update({ + "input-0": gen_name(34), + "input-1": gen_name(65), + "input-2": gen_name(86) + }) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(86)}, + outputs=[gen_name(61)]) + if_layer9.add_block(pattern_block_block_block) + if_layer9.inputs.update({ + "input-0": gen_name(51), + "input-1": gen_name(54), + "input-2": gen_name(54), + "input-3": gen_name(37), + "input-4": gen_name(34) + }) + pattern_block_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(11)}, + outputs=[gen_name(95)], + element=0) + pattern_block_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(11)}, + outputs=[gen_name(96)], + element=1) + pattern_block_block.add_layer( + "prim.isinstance", + inputs={"input": gen_name(61)}, + outputs=["interpolate-input-0_isinstance"], + cls="paddle.fluid.Variable") + pattern_block_block.add_layer( + "prim.if", {"input": "interpolate-input-0_isinstance"}, + outputs=["interpolate-input-0_if1"]) + if_layer_isinstance = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer_isinstance, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.var2list", + inputs={"input": gen_name(61)}, + outputs=[gen_name(61)]) + if_layer_isinstance.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer_isinstance, graph_type="dygraph") + if_layer_isinstance.add_block(pattern_block_block_block) + if_layer_isinstance.inputs["input-0"] = gen_name(61) + pattern_block_block.add_layer( + "prim.assert", + inputs={"key": gen_name(95), + "value": gen_name(96)}, + outputs=[gen_name(97) + "_assert"], + type="eq") + pattern_block_block.add_layer( + "paddle.nn.functional.interpolate", + inputs={ + "input": "interpolate-input-0", + "size": gen_name(61), + "scale_factor": gen_name(95) + }, + outputs=[gen_name(97)], + align_corners=False, + align_mode=0) + pattern_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(97)}, + outputs=[gen_name(20)]) + if_layer2.add_block(pattern_block_block) + pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") + pattern_block_block.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(98)]) + pattern_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(98)}, + outputs=[gen_name(98)]) + pattern_block_block.add_layer( + "prim.eq", + inputs={"x": gen_name(98)}, + outputs=[gen_name(99)], + y=5) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(99)}, + outputs=[gen_name(100)]) + if_layer16 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer16, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(101)], + input="Exception") + if_layer16.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer16, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(102)], + input="Exception") + if_layer16.add_block(pattern_block_block_block) + pattern_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(20)], input=None) + if_layer2.add_block(pattern_block_block) + if_layer2.inputs.update({ + "input-0": gen_name(13), + "input-1": gen_name(13), + "input-2": "interpolate-input-0", + "input-3": gen_name(11), + "input-5": gen_name(11), + }) + pattern_block.add_layer( + "prim.equal", + inputs={"input": gen_name(20)}, + outputs=[gen_name(16)]) + if_layer1.add_block(pattern_block) + if_layer1.inputs.update({ + "input-2": "interpolate-input-0", + "input-4": gen_name(13), + "input-7": gen_name(11), + "input-9": gen_name(11), + "input-11": "interpolate-input-0", + "input-12": "interpolate-input-0", + }) + self.pattern.build(inputs={ + "input-0": "interpolate-input-0", + "input-1": "interpolate-input-1" + }) + else: + self.pattern.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(9)]) + self.pattern.add_layer( + "prim.len", + inputs={"input": gen_name(9)}, + outputs=[gen_name(9)]) + self.pattern.add_layer( + "prim.sub", + inputs={"x": gen_name(9)}, + outputs=[gen_name(10)], + y=2) + self.pattern.add_layer( + "prim.list", inputs={}, outputs=[gen_name(11)]) + self.pattern.add_layer( + "prim.loop", + inputs={"input": gen_name(10)}, + outputs=[gen_name(12.1), gen_name(12.2)]) + loop_layer = self.pattern.layers[list(self.pattern.layers.keys())[ + -1]] + pattern_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_block.add_layer( + "prim.append", + inputs={"list": gen_name(11)}, + outputs=[], + element=None) + loop_layer.inputs["input-0"] = gen_name(11) + loop_layer.add_block(pattern_block) + self.pattern.add_layer( + "prim.tuple", + inputs={ + "input0": "interpolate-input-0", + "input1": "interpolate-input-1", + }, + outputs=[gen_name(13)], + input2=None, + input3=None) + self.pattern.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(14)]) + self.pattern.add_layer( + "prim.len", + inputs={"input": gen_name(14)}, + outputs=[gen_name(14)]) + self.pattern.add_layer( + "prim.eq", + inputs={"x": gen_name(14)}, + outputs=[gen_name(15)], + y=3) + self.pattern.add_layer( + "prim.if", + inputs={"input": gen_name(15)}, + outputs=[gen_name(16)]) + if_layer1 = self.pattern.layers[list(self.pattern.layers.keys())[ + -1]] + pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") + pattern_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(17)], + input="Exception") + pattern_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(16)], input=None) + if_layer1.add_block(pattern_block) + pattern_block = PaddleGraph(if_layer1, graph_type="dygraph") + pattern_block.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(18)]) + pattern_block.add_layer( + "prim.len", + inputs={"input": gen_name(18)}, + outputs=[gen_name(18)]) + pattern_block.add_layer( + "prim.eq", + inputs={"x": gen_name(18)}, + outputs=[gen_name(19)], + y=4) + pattern_block.add_layer( + "prim.if", + inputs={"input": gen_name(19)}, + outputs=[gen_name(20)]) + if_layer2 = pattern_block.layers[list(pattern_block.layers.keys())[ + -1]] + pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") + pattern_block_block.add_layer( + "prim.tuple_unpack", + inputs={"input": gen_name(13)}, + outputs=[ + gen_name(34), gen_name(35), gen_name(36), gen_name(37) + ]) + pattern_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(35)}, + outputs=[gen_name(38)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(38)}, + outputs=[gen_name(39), gen_name(40)]) + if_layer3 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer3, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(36)}, + outputs=[gen_name(41)], + y=None) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(41)}, + outputs=[gen_name(39)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(40)]) + if_layer3.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer3, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(42)]) + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(39)], input=False) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(35)}, + outputs=[gen_name(40)]) + if_layer3.add_block(pattern_block_block_block) + if_layer3.inputs.update({ + "input-0": gen_name(36), + 'input-1': gen_name(35), + 'input-2': gen_name(35), + }) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(39)}, + outputs=[gen_name(43)]) + if_layer4 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer4, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(44)], + input="Exception") + if_layer4.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer4, graph_type="dygraph") + if_layer4.add_block(pattern_block_block_block) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(40)}, + outputs=[gen_name(45)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(45)}, + outputs=[gen_name(46), gen_name(47)]) + if_layer5 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer5, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(40)}, + outputs=[gen_name(48)]) + pattern_block_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(36)}, + outputs=[gen_name(49)], + y=None) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(49)}, + outputs=[gen_name(46)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(48)}, + outputs=[gen_name(47)]) + if_layer5.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer5, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(46)], input=False) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(40)}, + outputs=[gen_name(47)]) + if_layer5.add_block(pattern_block_block_block) + if_layer5.inputs.update({ + "input-0": gen_name(40), + "input-1": gen_name(36), + "input-3": gen_name(40) + }) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(46)}, + outputs=[gen_name(50), gen_name(51)]) + if_layer6 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer6, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(52)], + input="Exception") + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(50)], input=None) + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(51)], input=None) + if_layer6.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer6, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(36)}, + outputs=[gen_name(50)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(47)}, + outputs=[gen_name(51)]) + if_layer6.add_block(pattern_block_block_block) + if_layer6.inputs.update({ + "input-0": gen_name(36), + "input-1": gen_name(47) + }) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(50)}, + outputs=[gen_name(53)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(53)}, + outputs=[gen_name(54)]) + if_layer7 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer7, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(50)}, + outputs=[gen_name(55)]) + pattern_block_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(55)}, + outputs=[gen_name(56)]) + pattern_block_block_block.add_layer( + "prim.ne", + inputs={"x": gen_name(56)}, + outputs=[gen_name(57)], + y=2) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(57)}, + outputs=[gen_name(58)]) + if_layer8 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer8, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(59)], + input="Exception") + if_layer8.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer8, graph_type="dygraph") + if_layer8.add_block(pattern_block_block_block_block) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(55)}, + outputs=[gen_name(54)]) + if_layer7.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer7, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(50)}, + outputs=[gen_name(54)]) + if_layer7.add_block(pattern_block_block_block) + if_layer7.inputs.update({ + "input-0": gen_name(50), + "input-1": gen_name(50) + }) + pattern_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(51)}, + outputs=[gen_name(60)], + y=None) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(60)}, + outputs=[gen_name(61)]) + if_layer9 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer9, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(51)}, + outputs=[gen_name(62)]) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(62)}, + outputs=[gen_name(61)]) + if_layer9.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer9, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(61)], input=None) + if_layer9.add_block(pattern_block_block_block) + if_layer9.inputs.update({"input-0": gen_name(51)}) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(60)}, + outputs=[gen_name(63)]) + if_layer10 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer10, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(61)}, + outputs=[gen_name(63)]) + if_layer10.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer10, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.isnot", + inputs={"x": gen_name(54)}, + outputs=[gen_name(64)], + y=None) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(64)}, + outputs=[gen_name(65)]) + if_layer11 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer11, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(54)}, + outputs=[gen_name(66)]) + pattern_block_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(66)}, + outputs=[gen_name(65)]) + if_layer11.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer11, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(67)], + input="Exception") + pattern_block_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(65)], input=None) + if_layer11.add_block(pattern_block_block_block_block) + if_layer11.inputs.update({"input-0": gen_name(54), }) + pattern_block_block_block.add_layer( + "prim.is", + inputs={"x": gen_name(37)}, + outputs=[gen_name(68)], + y=None) + pattern_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(68)}, + outputs=[gen_name(69)]) + if_layer12 = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block = PaddleGraph( + if_layer12, graph_type="dygraph") + pattern_block_block_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(65)}, + outputs=[gen_name(70)]) + pattern_block_block_block_block.add_layer( + "prim.gt", + inputs={"x": gen_name(70)}, + outputs=[gen_name(71)], + y=0) + pattern_block_block_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(72)], input=0) + pattern_block_block_block_block.add_layer( + "prim.loop", + inputs={}, + outputs=[gen_name(74), gen_name(75), gen_name(76.1)], + input=2147483647) + loop_layer = pattern_block_block_block_block.layers[list( + pattern_block_block_block_block.layers.keys())[-1]] + pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_loop_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(65), + "element": gen_name(72)}, + outputs=[gen_name(74.1)]) + pattern_loop_block.add_layer( + "prim.floor", + inputs={"input": gen_name(74.1)}, + outputs=[gen_name(75.1)]) + pattern_loop_block.add_layer( + "prim.ne", + inputs={"x": gen_name(75.1), + "y": gen_name(74.1)}, + outputs=[gen_name(76)]) + pattern_loop_block.add_layer( + "prim.if", + inputs={"input": gen_name(76)}, + outputs=[gen_name(77), gen_name(78)]) + if_layer13 = pattern_loop_block.layers[list( + pattern_loop_block.layers.keys())[-1]] + pattern_loop_block_block = PaddleGraph( + if_layer13, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(77)], input=False) + pattern_loop_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(76)}, + outputs=[gen_name(78)]) + if_layer13.add_block(pattern_loop_block_block) + pattern_loop_block_block = PaddleGraph( + if_layer13, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(77)], input=None) + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(78)], input=None) + if_layer13.add_block(pattern_loop_block_block) + if_layer13.inputs.update({"input-0": gen_name(76), }) + pattern_loop_block.add_layer( + "prim.if", + inputs={"input": gen_name(76)}, + outputs=[gen_name(79), gen_name(80)]) + if_layer14 = pattern_loop_block.layers[list( + pattern_loop_block.layers.keys())[-1]] + pattern_loop_block_block = PaddleGraph( + if_layer14, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(77)}, + outputs=[gen_name(79)]) + pattern_loop_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(78)}, + outputs=[gen_name(80)]) + if_layer14.add_block(pattern_loop_block_block) + pattern_loop_block_block = PaddleGraph( + if_layer14, graph_type="dygraph") + pattern_loop_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(79)], input=True) + pattern_loop_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(76)}, + outputs=[gen_name(80)]) + if_layer14.add_block(pattern_loop_block_block) + if_layer14.inputs.update({ + "input-0": gen_name(77), + "input-1": gen_name(78), + "input-2": gen_name(76) + }) + pattern_loop_block.add_layer( + "prim.add", + inputs={"x": gen_name(72)}, + outputs=[gen_name(81)], + y=1) + pattern_loop_block.add_layer( + "prim.lt", + inputs={"x": gen_name(81), + "y": gen_name(70)}, + outputs=[gen_name(82)]) + pattern_loop_block.add_layer( + "prim.and", + inputs={"x": gen_name(82), + "y": gen_name(79)}, + outputs=[gen_name(83)]) + pattern_loop_block.add_layer( + "prim.equal", + inputs={"input": gen_name(80)}, + outputs=[gen_name(74)]) + pattern_loop_block.add_layer( + "prim.equal", + inputs={"input": gen_name(81)}, + outputs=[gen_name(75)]) + loop_layer.add_block(pattern_loop_block) + loop_layer.inputs.update({ + "input-0": gen_name(65), + "input-1": gen_name(72), + "input-2": gen_name(72), + "input-3": gen_name(70) + }) + pattern_block_block_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(74)}, + outputs=[gen_name(84)]) + if_layer15 = pattern_block_block_block_block.layers[list( + pattern_block_block_block_block.layers.keys())[-1]] + pattern_block_block_block_block_block = PaddleGraph( + if_layer15, graph_type="dygraph") + pattern_block_block_block_block_block.add_layer( + "prim.warnings", + inputs={}, + outputs=[gen_name(85)], + stacklevel=2, + input="...") + if_layer15.add_block(pattern_block_block_block_block_block) + pattern_block_block_block_block_block = PaddleGraph( + if_layer15, graph_type="dygraph") + if_layer15.add_block(pattern_block_block_block_block_block) + if_layer12.add_block(pattern_block_block_block_block) + pattern_block_block_block_block = PaddleGraph( + if_layer12, graph_type="dygraph") + if_layer12.add_block(pattern_block_block_block_block) + if_layer12.inputs.update({ + "input-0": gen_name(65), + "input-1": gen_name(65), + }) + pattern_block_block_block.add_layer( + "prim.list", inputs={}, outputs=[gen_name(86)]) + pattern_block_block_block.add_layer( + "prim.loop", + inputs={}, + outputs=[gen_name(87), gen_name(88)], + input=2) + loop_layer = pattern_block_block_block.layers[list( + pattern_block_block_block.layers.keys())[-1]] + pattern_loop_block = PaddleGraph(loop_layer, graph_type="dygraph") + pattern_loop_block.add_layer( + "prim.add", + inputs={"x": gen_name(88)}, + outputs=[gen_name(89)], + y=2) + pattern_loop_block.add_layer( + "prim.shape_dim", + inputs={"input": gen_name(34), + "dim": gen_name(89)}, + outputs=[gen_name(90)]) + pattern_loop_block.add_layer( + "prim.float", + inputs={"input": gen_name(90)}, + outputs=[gen_name(91)]) + pattern_loop_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(65), + "element": gen_name(88)}, + outputs=[gen_name(92)]) + pattern_loop_block.add_layer( + "prim.mul", + inputs={"x": gen_name(91), + "y": gen_name(92)}, + outputs=[gen_name(93)]) + pattern_loop_block.add_layer( + "prim.floor", + inputs={"input": gen_name(93)}, + outputs=[gen_name(94)]) + pattern_loop_block.add_layer( + "prim.append", + inputs={"list": gen_name(86), + "element": gen_name(94)}, + outputs=[]) + loop_layer.add_block(pattern_loop_block) + loop_layer.inputs.update({ + "input-0": gen_name(34), + "input-1": gen_name(65), + "input-2": gen_name(86) + }) + pattern_block_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(86)}, + outputs=[gen_name(63)]) + if_layer10.add_block(pattern_block_block_block) + if_layer10.inputs.update({ + "input-0": gen_name(61), + "input-1": gen_name(54), + "input-2": gen_name(54), + "input-3": gen_name(37), + "input-4": gen_name(34) + }) + pattern_block_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(11)}, + outputs=[gen_name(95)], + element=0) + pattern_block_block.add_layer( + "prim.getitem", + inputs={"list": gen_name(11)}, + outputs=[gen_name(96)], + element=1) + pattern_block_block.add_layer( + "prim.isinstance", + inputs={"input": gen_name(63)}, + outputs=["interpolate-input-0_isinstance"], + cls="paddle.fluid.Variable") + pattern_block_block.add_layer( + "prim.if", {"input": "interpolate-input-0_isinstance"}, + outputs=["interpolate-input-0_if1"]) + if_layer_isinstance = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer_isinstance, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.var2list", + inputs={"input": gen_name(63)}, + outputs=[gen_name(63)]) + if_layer_isinstance.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer_isinstance, graph_type="dygraph") + if_layer_isinstance.add_block(pattern_block_block_block) + if_layer_isinstance.inputs["input-0"] = gen_name(63) + pattern_block_block.add_layer( + "prim.assert", + inputs={"key": gen_name(95), + "value": gen_name(96)}, + outputs=[gen_name(97) + "_assert"], + type="eq") + pattern_block_block.add_layer( + "paddle.nn.functional.interpolate", + inputs={ + "input": "interpolate-input-0", + "size": gen_name(63), + "scale_factor": gen_name(95) + }, + outputs=[gen_name(97)], + align_corners=False, + align_mode=0) + pattern_block_block.add_layer( + "prim.equal", + inputs={"input": gen_name(97)}, + outputs=[gen_name(20)]) + if_layer2.add_block(pattern_block_block) + pattern_block_block = PaddleGraph(if_layer2, graph_type="dygraph") + pattern_block_block.add_layer( + "fluid.layers.shape", + inputs={"input": "interpolate-input-0"}, + outputs=[gen_name(98)]) + pattern_block_block.add_layer( + "prim.len", + inputs={"input": gen_name(98)}, + outputs=[gen_name(98)]) + pattern_block_block.add_layer( + "prim.eq", + inputs={"x": gen_name(98)}, + outputs=[gen_name(99)], + y=5) + pattern_block_block.add_layer( + "prim.if", + inputs={"input": gen_name(99)}, + outputs=[gen_name(100)]) + if_layer16 = pattern_block_block.layers[list( + pattern_block_block.layers.keys())[-1]] + pattern_block_block_block = PaddleGraph( + if_layer16, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(101)], + input="Exception") + if_layer16.add_block(pattern_block_block_block) + pattern_block_block_block = PaddleGraph( + if_layer16, graph_type="dygraph") + pattern_block_block_block.add_layer( + "prim.exception", + inputs={}, + outputs=[gen_name(102)], + input="Exception") + if_layer16.add_block(pattern_block_block_block) + pattern_block_block.add_layer( + "prim.equal", inputs={}, outputs=[gen_name(20)], input=None) + if_layer2.add_block(pattern_block_block) + if_layer2.inputs.update({ + "input-0": gen_name(13), + "input-1": gen_name(13), + "input-2": "interpolate-input-0", + "input-3": gen_name(11), + "input-5": gen_name(11), + }) + pattern_block.add_layer( + "prim.equal", + inputs={"input": gen_name(20)}, + outputs=[gen_name(16)]) + if_layer1.add_block(pattern_block) + if_layer1.inputs.update({ + "input-2": "interpolate-input-0", + "input-4": gen_name(13), + "input-7": gen_name(11), + "input-9": gen_name(11), + "input-11": "interpolate-input-0", + "input-12": "interpolate-input-0", + }) + self.pattern.build(inputs={ + "input-0": "interpolate-input-0", + "input-1": "interpolate-input-1" + }) def insert_new_layer(self, graph, parameters, matches): - new_layer = self.gen_new_layer(parameters, matches) + new_layers = self.gen_new_layer(parameters, matches) new_layer_id = list(matches.keys())[0] - graph.layers[new_layer_id] = new_layer + graph.layers[new_layer_id] = new_layers[0] + matches.pop(new_layer_id) + new_layer_id = list(matches.keys())[0] + graph.layers[new_layer_id] = new_layers[1] + block_layer = new_layers[1].blocks[0].layers.pop( + list(new_layers[1].blocks[0].layers.keys())[-1]) + new_layers[1].blocks[0].layers[new_layer_id + ".0.0"] = block_layer + matches.pop(new_layer_id) + new_layer_id = list(matches.keys())[0] + graph.layers[new_layer_id] = new_layers[2] matches.pop(new_layer_id) def gen_new_layer(self, parameters, matches): + layers = list() layers_id = list(matches.keys()) - layer = matches[layers_id[15]] - out_shape = layer.inputs["input1"] - layer = matches[layers_id[21]] + layer = matches[layers_id[6]] + size = layer.inputs["input1"] + layer = matches[layers_id[92]] + layer.inputs["input"] = size + layers.append(layer) + layer = matches[layers_id[93]] + block_layer = layer.blocks[0].layers[list(layer.blocks[0].layers.keys()) + [0]] + block_layer.inputs["input"] = size + block_layer.outputs[0] = size + layer.inputs["input-0"] = size + layers.append(layer) + layer = matches[layers_id[-1]] outputs = layer.outputs - layer = matches[layers_id[128]] - layer.inputs.pop("scale") - layer.inputs["out_shape"] = out_shape + layer = matches[layers_id[96]] + layer.inputs.pop("scale_factor") + layer.inputs["size"] = size layer.outputs = outputs - return layer + layers.append(layer) + return layers diff --git a/x2paddle/optimizer/optimizer.py b/x2paddle/optimizer/optimizer.py index 1e1b42b..ed427a2 100644 --- a/x2paddle/optimizer/optimizer.py +++ b/x2paddle/optimizer/optimizer.py @@ -19,9 +19,14 @@ from x2paddle.optimizer.pass_manager import PassManager class GraphOptimizer(object): def __init__(self): self.passes = [ - "interpolate_bilinear_fuse_pass", "fc_fuse_pass", - "adaptive_pool2d_fuse_pass", "batchnorm2d_fuse_pass", - "constant_fuse_pass", "reshape_fuse_pass", "dropout_fuse_pass" + "constant_fuse_pass", + "batchnorm2d_fuse_pass", + "interpolate_bilinear_fuse_pass", + "fc_fuse_pass", + # "interpolate_bilinear_fuse_pass", + # "fc_fuse_pass", + # "adaptive_pool2d_fuse_pass", "batchnorm2d_fuse_pass", + # "constant_fuse_pass", "reshape_fuse_pass", "dropout_fuse_pass" ] def optimize(self, graph): diff --git a/x2paddle/optimizer/pattern_matcher.py b/x2paddle/optimizer/pattern_matcher.py index 6b7a046..c5b38b0 100644 --- a/x2paddle/optimizer/pattern_matcher.py +++ b/x2paddle/optimizer/pattern_matcher.py @@ -34,7 +34,7 @@ class PatternMatcher(object): 并将子图的id以拓扑排序存放到subgraph_id2layers。 """ - def get_subgraph(pattern, graph, start_index): + def get_subgraph(pattern, graph, start_index, is_subblock=False): pattern_index = 0 pattern_id2layers = pattern.get_global_layers() pattern_ids = list(pattern_id2layers.keys()) @@ -49,13 +49,19 @@ class PatternMatcher(object): # 判断输入连接是否一致 if layer_id in graph.edges_in: if pattern_layer_id not in pattern.edges_in: - print("1--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue else: if len(graph.edges_in[layer_id]) != len( pattern.edges_in[pattern_layer_id]): - print("2--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue layer_in = graph.edges_in[layer_id] pattern_layer_in = pattern.edges_in[pattern_layer_id] for i in range(len(layer_in)): @@ -70,16 +76,22 @@ class PatternMatcher(object): # 判断pattern输入在pattern_ids的索引 # 和graph输入在subgraph_ids的索引一致 continue - print("3--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue # 判断subgraph中的节点是否被外部图使用到(如若被使用到则无效) if layer_id in graph.edges_out: if pattern_layer_id not in pattern.edges_out: if not set(pattern_layer.outputs).issubset( pattern.outputs): # 若pattern当前layer的输出是pattern的输出,则是正确的 - print("4--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue else: if len(graph.edges_out[layer_id]) != len( pattern.edges_out[pattern_layer_id]): @@ -87,27 +99,49 @@ class PatternMatcher(object): if not set(pattern_layer.outputs).issubset( pattern.outputs): # 若pattern当前layer的输出是pattern的输出,则是正确的 - # print("5--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue # 当为控制流时的处理 if layer.kernel == "prim.if" or layer.kernel == "prim.loop": if len(pattern_layer.blocks) != len(layer.blocks): - print("6--") - return False + if pattern_index == 0 or is_subblock: + return False + else: + subgraph_id2layers.pop(layer_id) + continue + is_subblock_match = True for i, b in enumerate(pattern_layer.blocks): - match_info = get_subgraph(pattern_layer.blocks[i], - layer.blocks[i], 0) + match_info = get_subgraph( + pattern_layer.blocks[i], + layer.blocks[i], + 0, + is_subblock=True) if match_info is not False: subgraph_id2layers.update(match_info) else: - print("7--") + is_subblock_match = False + break + if not is_subblock_match: + if pattern_index == 0 or is_subblock: return False + else: + index = list(subgraph_id2layers.keys()).index( + layer_id) + for key in list(subgraph_id2layers.keys())[ + index:]: + subgraph_id2layers.pop(key) + continue pattern_index += 1 if pattern_index == len(pattern.layers): return subgraph_id2layers else: - if pattern_index == 0: + if pattern_index == 0 or is_subblock: return False + else: + continue if pattern_index == len(pattern.layers): return subgraph_id2layers return False -- GitLab