From c4204bbfff4a0045556d312a4a9c49b010fcd056 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Tue, 1 Aug 2023 11:23:24 +0800 Subject: [PATCH] test close trace (#55787) * test close old dygraph trace --- paddle/fluid/pybind/imperative.cc | 110 -------------------------- python/paddle/fluid/dygraph/tracer.py | 18 +---- 2 files changed, 1 insertion(+), 127 deletions(-) diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 5c090b55c6b..7c12ae5fddf 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -2284,116 +2284,6 @@ void BindImperative(py::module *m_ptr) { return std::make_tuple( kernelsig_ins, kernelsig_attrs, kernelsig_outs); } - }) - .def("trace", - [](imperative::Tracer &self, - const std::string &type, - const PyNameVarBaseMap &ins, - const PyNameVarBaseMap &outs, - framework::AttributeMap attrs, - const platform::CustomPlace &place, - bool trace_backward, - const std::map &inplace_map = {}) { - auto ins_map = ConvertToNameVarBaseMap(ins); - auto outs_map = ConvertToNameVarBaseMap(outs); - { - py::gil_scoped_release release; - self.TraceOp(type, - std::move(ins_map), - std::move(outs_map), - std::move(attrs), - place, - trace_backward, - inplace_map); - } - }) - .def("trace", - [](imperative::Tracer &self, - const std::string &type, - const PyNameVarBaseMap &ins, - const PyNameVarBaseMap &outs, - framework::AttributeMap attrs, - const platform::XPUPlace &place, - bool trace_backward, - const std::map &inplace_map = {}) { - auto ins_map = ConvertToNameVarBaseMap(ins); - auto outs_map = ConvertToNameVarBaseMap(outs); - { - py::gil_scoped_release release; - self.TraceOp(type, - std::move(ins_map), - std::move(outs_map), - std::move(attrs), - place, - trace_backward, - inplace_map); - } - }) - .def("trace", - [](imperative::Tracer &self, - const std::string &type, - const PyNameVarBaseMap &ins, - const PyNameVarBaseMap &outs, - framework::AttributeMap attrs, - const platform::CUDAPlace &place, - bool trace_backward, - const std::map &inplace_map = {}) { - auto ins_map = ConvertToNameVarBaseMap(ins); - auto outs_map = ConvertToNameVarBaseMap(outs); - { - py::gil_scoped_release release; - self.TraceOp(type, - std::move(ins_map), - std::move(outs_map), - std::move(attrs), - place, - trace_backward, - inplace_map); - } - }) - .def("trace", - [](imperative::Tracer &self, - const std::string &type, - const PyNameVarBaseMap &ins, - const PyNameVarBaseMap &outs, - framework::AttributeMap attrs, - const platform::IPUPlace &place, - bool trace_backward, - const std::map &inplace_map = {}) { - auto ins_map = ConvertToNameVarBaseMap(ins); - auto outs_map = ConvertToNameVarBaseMap(outs); - { - py::gil_scoped_release release; - self.TraceOp(type, - std::move(ins_map), - std::move(outs_map), - std::move(attrs), - place, - trace_backward, - inplace_map); - } - }) - .def("trace", - [](imperative::Tracer &self, - const std::string &type, - const PyNameVarBaseMap &ins, - const PyNameVarBaseMap &outs, - framework::AttributeMap attrs, - const platform::CPUPlace &place, - bool trace_backward, - const std::map &inplace_map = {}) { - auto ins_map = ConvertToNameVarBaseMap(ins); - auto outs_map = ConvertToNameVarBaseMap(outs); - { - py::gil_scoped_release release; - self.TraceOp(type, - std::move(ins_map), - std::move(outs_map), - std::move(attrs), - place, - trace_backward, - inplace_map); - } }); // define parallel context diff --git a/python/paddle/fluid/dygraph/tracer.py b/python/paddle/fluid/dygraph/tracer.py index d55ad22e223..f079d194612 100644 --- a/python/paddle/fluid/dygraph/tracer.py +++ b/python/paddle/fluid/dygraph/tracer.py @@ -324,23 +324,7 @@ class Tracer(core.Tracer): type, inputs, outputs, attrs, stop_gradient, inplace_map ) else: - # this block is used to convert attrs according to the opproto - # since `trace` handles AttributeMap directly, without other - # modification to the passed attribute map, so we change it before - # `trace` - if framework.OpProtoHolder.instance().has_op_proto(type): - proto = framework.OpProtoHolder.instance().get_op_proto(type) - attrs = framework.canonicalize_attrs(attrs, proto) - - self.trace( - type, - inputs, - outputs, - attrs, - framework._current_expected_place(), - self._has_grad and not stop_gradient, - inplace_map if inplace_map else {}, - ) + raise ValueError("trace_op only work in dygraph mode") def train_mode(self): self._train_mode = True -- GitLab