diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 67496d738f6f5df41379226a20db010f7b2dbe17..a7036246afdac9724dd72cc12dc0825195977378 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 4c47a309e54336ac9c8ad4bde4965d74a70ff216..c44535f3dc6d762296a76f9a2248cbd0cffd32d4 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)