From cda893fcad5a791deb6fd990372052d7de1a3ecc Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Wed, 9 Jun 2021 11:38:26 +0800 Subject: [PATCH] [Dy2Stat]Modify into core.ops.run_program (#33246) * Modify into core.ops.run_program * add DDout in core.ops.run_program * fix typo * add DOut * fix typo * put DOut last --- paddle/fluid/pybind/op_function_generator.cc | 3 +++ .../dygraph_to_static/partial_program.py | 26 +++++++------------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/paddle/fluid/pybind/op_function_generator.cc b/paddle/fluid/pybind/op_function_generator.cc index bf3c7784321..bab4ac36353 100644 --- a/paddle/fluid/pybind/op_function_generator.cc +++ b/paddle/fluid/pybind/op_function_generator.cc @@ -65,6 +65,7 @@ std::map> op_ins_map = { {"box_coder", {"PriorBox", "PriorBoxVar", "TargetBox"}}, {"momentum", {"Param", "Grad", "Velocity", "LearningRate"}}, {"rnn", {"Input", "PreState", "WeightList", "SequenceLength"}}, + {"run_program", {"X", "Params"}}, }; // NOTE(zhiqiu): Like op_ins_map. @@ -98,6 +99,7 @@ std::map> op_outs_map = { {"rnn", {"DropoutState", "Reserve", "Out", "State"}}, {"lamb", {"ParamOut", "Moment1Out", "Moment2Out", "Beta1PowOut", "Beta2PowOut"}}, + {"run_program", {"DOut"}}, }; // NOTE(zhiqiu): Commonly, the outputs in auto-generated OP function are @@ -148,6 +150,7 @@ std::map> op_passing_outs_map = { {"lamb", {"ParamOut", "Moment1Out", "Moment2Out", "Beta1PowOut", "Beta2PowOut"}}, {"rnn", {"DropoutState"}}, + {"run_program", {"Out", "DOut", "OutScope"}}, }; // NOTE(pangyoki): Tensor View Strategy. diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py b/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py index 719b06c659f..f2c91809869 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/partial_program.py @@ -221,23 +221,15 @@ class PartialProgramLayer(layers.Layer): def forward(self, inputs): in_vars, out_vars, tmp_scope_vec = self._prepare(inputs) - framework._dygraph_tracer().trace_op( - type='run_program', - inputs={ - 'X': valid_vars(in_vars), - 'Params': valid_vars(self._params) - }, - outputs={ - 'Out': valid_vars(out_vars), - 'OutScope': tmp_scope_vec, - 'DOut': valid_vars(self._double_grads) - }, - attrs={ - 'global_block': self.program.desc.block(0), - 'start_op_index': 0, - 'end_op_index': self._infer_program.desc.block(0).op_size(), - 'is_test': not self.training - }) + + attrs = ('global_block', self.program.desc.block(0), 'start_op_index', + 0, 'end_op_index', self._infer_program.desc.block(0).op_size(), + 'is_test', not self.training) + core.ops.run_program( + valid_vars(in_vars), + valid_vars(self._params), + valid_vars(out_vars), tmp_scope_vec, + valid_vars(self._double_grads), *attrs) restored_nest_out = self._restore_out(out_vars) return self._remove_no_value(restored_nest_out) -- GitLab