From 326bf8291abac09b843def6aa84e7176e989a150 Mon Sep 17 00:00:00 2001 From: guru4elephant <35550832+guru4elephant@users.noreply.github.com> Date: Fri, 24 May 2019 15:26:32 +0800 Subject: [PATCH] add Run Prepared Ctx (#17616) add Run Prepared Ctx, fix pybind problem --- paddle/fluid/pybind/pybind.cc | 8 ++++++++ python/paddle/fluid/executor.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 67496d738f..a7036246af 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -1052,6 +1052,14 @@ All parameter, weight, gradient are variables in Paddle. create_local_scope, create_vars, feed_holder_name, fetch_holder_name); }) + .def("run_cached_prepared_ctx", + [](Executor &self, ExecutorPrepareContext *ctx, Scope *scope, + bool create_local_scope = true, bool create_vars = true, + bool keep_kids = false) { + pybind11::gil_scoped_release release; + self.RunPreparedContext(ctx, scope, create_local_scope, + create_vars, keep_kids); + }) .def("prepare_ctx_cache", &Executor::PrepareCtxCache, py::call_guard()) .def("run", [](Executor &self, const ProgramDesc &prog, Scope *scope, diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index 4c47a309e5..c44535f3dc 100644 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -719,7 +719,7 @@ class Executor(object): if not use_program_cache: exe.run(program.desc, scope, 0, True, True, fetch_var_name) else: - exe.run_prepared_ctx(ctx, scope, True, True, False) + exe.run_cached_prepared_ctx(ctx, scope, True, True, False) outs = self._fetch_data(fetch_list, fetch_var_name, scope) if return_numpy: outs = as_numpy(outs) -- GitLab