From 987ab9e325a6b316243d1f9575b23f0acfefd860 Mon Sep 17 00:00:00 2001 From: diadestiny <1247889154@qq.com> Date: Thu, 22 Feb 2024 04:35:42 +0000 Subject: [PATCH 1/3] support_RETURN_CONST --- .../jit/sot/opcode_translator/executor/opcode_executor.py | 7 +++++++ .../opcode_translator/executor/opcode_inline_executor.py | 4 ++++ test/sot/skip_files_py312 | 5 ----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py b/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py index 8614356ce3a85c..c5be329ab297fb 100644 --- a/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py +++ b/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py @@ -2118,3 +2118,10 @@ def RETURN_VALUE(self, instr: Instruction): self.new_code = self._graph.pycode_gen.gen_pycode() self.guard_fn = self._graph.guard_fn return Stop(state="Return") + + def RETURN_CONST(self, instr: Instruction): + ret_const = self._co_consts[instr.arg] + self._graph.start_compile(ret_const) + self._graph.pycode_gen.gen_return() + self.new_code = self._graph.pycode_gen.gen_pycode() + return Stop(state="Return") diff --git a/python/paddle/jit/sot/opcode_translator/executor/opcode_inline_executor.py b/python/paddle/jit/sot/opcode_translator/executor/opcode_inline_executor.py index 4baa64e8841075..3832d05f044487 100644 --- a/python/paddle/jit/sot/opcode_translator/executor/opcode_inline_executor.py +++ b/python/paddle/jit/sot/opcode_translator/executor/opcode_inline_executor.py @@ -283,6 +283,10 @@ def RETURN_VALUE(self, instr: Instruction): self.return_value = self.stack.pop() return Stop(state="Return") + def RETURN_CONST(self, instr: Instruction): + self.return_value = self._co_consts[instr.arg] + return Stop(state="Return") + def _break_graph_when_if(self, result, instr: Instruction): """ Helper method to raise a BreakGraphError when breaking the graph in a jump operation. diff --git a/test/sot/skip_files_py312 b/test/sot/skip_files_py312 index ad1b19a2a4481d..e5ebbe7315666a 100644 --- a/test/sot/skip_files_py312 +++ b/test/sot/skip_files_py312 @@ -19,16 +19,11 @@ ./test_inplace_api.py ./test_min_graph_size.py ./test_numpy_var_if.py -./test_output_restoration.py ./test_side_effects.py -./test_simulate_initialize.py -./test_sir_rollback.py ./test_sot_cost_model.py ./test_sot_export.py ./test_sot_resnet.py ./test_sot_resnet50_backward.py -./test_specialization.py ./test_str_format.py ./test_tensor_dtype_in_guard.py ./test_dtype.py -./test_builtin_bool.py From 2fb10c499016538c9b8773afe6d4a86c032e6720 Mon Sep 17 00:00:00 2001 From: diadestiny <1247889154@qq.com> Date: Thu, 22 Feb 2024 09:12:49 +0000 Subject: [PATCH 2/3] extract compile return func --- .../opcode_translator/executor/opcode_executor.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py b/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py index c5be329ab297fb..860f972418aa58 100644 --- a/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py +++ b/python/paddle/jit/sot/opcode_translator/executor/opcode_executor.py @@ -2109,6 +2109,13 @@ def RETURN_VALUE(self, instr: Instruction): len(self.stack) == 1 ), f"Stack must have one element, but get {len(self.stack)} elements." ret_val = self.stack.pop() + return self.compile_return(ret_val) + + def RETURN_CONST(self, instr: Instruction): + ret_const = self._co_consts[instr.arg] + return self.compile_return(ret_const) + + def compile_return(self, ret_val): compile_fn = self._graph.get_compiled_fn(ret_val) if compile_fn.graph_size() < ENV_MIN_GRAPH_SIZE.get(): self.new_code = None @@ -2118,10 +2125,3 @@ def RETURN_VALUE(self, instr: Instruction): self.new_code = self._graph.pycode_gen.gen_pycode() self.guard_fn = self._graph.guard_fn return Stop(state="Return") - - def RETURN_CONST(self, instr: Instruction): - ret_const = self._co_consts[instr.arg] - self._graph.start_compile(ret_const) - self._graph.pycode_gen.gen_return() - self.new_code = self._graph.pycode_gen.gen_pycode() - return Stop(state="Return") From 7fde0610580741467ac5f6a5cd22becb8e65226b Mon Sep 17 00:00:00 2001 From: diadestiny <1247889154@qq.com> Date: Thu, 22 Feb 2024 12:31:38 +0000 Subject: [PATCH 3/3] open test_sot_export, test_str_format --- test/sot/skip_files_py312 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/sot/skip_files_py312 b/test/sot/skip_files_py312 index 10d593561bf425..d79956533e2d3b 100644 --- a/test/sot/skip_files_py312 +++ b/test/sot/skip_files_py312 @@ -16,7 +16,5 @@ ./test_min_graph_size.py ./test_side_effects.py ./test_sot_cost_model.py -./test_sot_export.py ./test_sot_resnet.py ./test_sot_resnet50_backward.py -./test_str_format.py