From 5cccc69f1a2b0cb71df4d607b2a39cfbef05f89d Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 22 Apr 2020 19:10:29 +0800 Subject: [PATCH] update name generator, test=develop (#24048) * update name generator, test=develop * use c++ unique name generator, test=develop --- paddle/fluid/pybind/imperative.cc | 2 ++ paddle/fluid/pybind/op_function_generator.cc | 3 +-- python/paddle/fluid/unique_name.py | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/pybind/imperative.cc b/paddle/fluid/pybind/imperative.cc index 93a3137b99..3b4deb76c8 100644 --- a/paddle/fluid/pybind/imperative.cc +++ b/paddle/fluid/pybind/imperative.cc @@ -741,6 +741,8 @@ void BindImperative(py::module *m_ptr) { .def("_get_program_desc_tracer", &imperative::Tracer::GetProgramDescTracer, py::return_value_policy::reference) + .def("_generate_unique_name", &imperative::Tracer::GenerateUniqueName, + py::arg("key") = "tmp") .def("trace", [](imperative::Tracer &self, const std::string &type, const PyNameVarBaseMap &ins, const PyNameVarBaseMap &outs, diff --git a/paddle/fluid/pybind/op_function_generator.cc b/paddle/fluid/pybind/op_function_generator.cc index 62f1de35ae..3154ed0186 100644 --- a/paddle/fluid/pybind/op_function_generator.cc +++ b/paddle/fluid/pybind/op_function_generator.cc @@ -232,8 +232,7 @@ GenerateOpFunctions(const std::string& module_name) { } std::string function_args = ""; if (input_args == "") { - function_args = - paddle::string::Sprintf(FUNCTION_ARGS_NO_INPUT, input_args); + function_args = FUNCTION_ARGS_NO_INPUT; } else { function_args = paddle::string::Sprintf(FUNCTION_ARGS, input_args); } diff --git a/python/paddle/fluid/unique_name.py b/python/paddle/fluid/unique_name.py index 6129bd1c80..bf7d5b1edd 100644 --- a/python/paddle/fluid/unique_name.py +++ b/python/paddle/fluid/unique_name.py @@ -119,11 +119,14 @@ def generate(key): # would save model in static graph mode, and load it in dygraph # mode. Therefore, we keep the variable name of Parameter currently. # -# Please fix me if a better method is found. +# Please fix me if a better method is found. +# +# NOTE(zhiqiu): use c++ unique_name_generator in dygraph mode, +# in order to keep name consistency. def generate_with_ignorable_key(key): - from .framework import in_dygraph_mode + from .framework import in_dygraph_mode, _dygraph_tracer if in_dygraph_mode(): - key = "tmp" + return _dygraph_tracer()._generate_unique_name() return generator(key) -- GitLab