Created by: SunAhong1993
7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 from x2paddle.optimizer.linear_pass import LinearPass, LinearMatcher 16 17 18 class GraphOptimizer(object): 19 def __init__(self): 20 linear_pass = LinearPass() 21 linear_matcher = LinearMatcher() 22 self.passes = {linear_pass: linear_matcher} 33 break 34 for j, block in enumerate(layer.blocks): 35 if len(block.layers) > 0: 36 layer.blocks[j], is_update_block = self.run(block) 37 if is_update_block: 38 break 39 if i + 1 == len(graph.layers): 40 return graph, is_update_graph 41 42 def optimize(self, graph): 43 # 开始优化 44 for _pass, matcher in self.passes.items(): 45 self.current_pass = _pass 46 self.current_matcher = matcher 47 graph, _ = self.run(graph) 48 print("{} done!".format(_pass.__class__.__name__)) 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License" 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 from x2paddle.core.program import PaddleGraph 16 17 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 from x2paddle.core.program import PaddleGraph 16 17 18 class Pass(object): 19 def __init__(self): 20 self.pattern = PaddleGraph() 21 self.build_pattern() 22