diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 830ca049beef555ffda81f92872fcbf83f75881e..8be338df65373da0f53e6f06b8afa0b7c5eee4c3 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -40,6 +40,7 @@ limitations under the License. */ #include "paddle/fluid/framework/lod_rank_table.h" #include "paddle/fluid/framework/lod_tensor.h" #include "paddle/fluid/framework/lod_tensor_array.h" +#include "paddle/fluid/framework/new_exec.h" #include "paddle/fluid/framework/op_info.h" #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/framework/op_version_registry.h" @@ -53,7 +54,6 @@ limitations under the License. */ #include "paddle/fluid/framework/trainer.h" #include "paddle/fluid/framework/type_defs.h" #include "paddle/fluid/framework/version.h" -#include "paddle/fluid/framework/new_exec.h" #include "paddle/fluid/imperative/layer.h" #include "paddle/fluid/memory/allocation/allocator_strategy.h" #include "paddle/fluid/memory/allocation/mmap_allocator.h" @@ -90,7 +90,6 @@ limitations under the License. */ #include "paddle/fluid/pybind/ps_gpu_wrapper_py.h" #include "paddle/fluid/pybind/pybind_boost_headers.h" - #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) #include "paddle/fluid/pybind/nccl_wrapper_py.h" #endif @@ -1897,45 +1896,67 @@ All parameter, weight, gradient are variables in Paddle. }); py::class_(m, "InterpreterCore") - .def(py::init()) - .def("run", [](InterpreterCore &self, const std::unordered_map& input_dict, std::vector vec_fetch_name) { - pybind11::gil_scoped_release release; - std::vector vec_tensor; - std::vector vec_name; - //vec_tensor.reserve( feed.size() ); - //vec_tensor.reserve( feed.size ()) ; - - //auto new_res = input_dict.cast(); - - for ( auto & item : input_dict ) - { - //cerr << "test flag " << test_flag << endl; - //cerr << item.first << endl; - framework::LoDTensor t; - SetTensorFromPyArray(&t, item.second, - platform::CPUPlace(), false); - - //cerr << t.dims() << endl; - //cerr << t.data()[0] << endl; - - vec_name.push_back( item.first ); - vec_tensor.push_back( t ); - } - - - - //std::cerr << "11" << std::endl; - std::vector vec_out; - self.run(vec_name, vec_tensor, vec_fetch_name, vec_out); - //self.Run(prog, scope, block_id, create_local_scope, create_vars, - // fetch_vars); - std::vector< py::array> vec_ret; - for( size_t i = 0; i < vec_out.size(); ++i ) - { - vec_ret.push_back( TensorToPyArray(vec_out[i], true) ) ; - } - return vec_ret; - }); + .def(py::init()) + .def("run", + [](InterpreterCore &self, + const std::unordered_map &input_dict, + std::vector vec_fetch_name) { + pybind11::gil_scoped_release release; + std::vector vec_tensor; + std::vector vec_name; + // vec_tensor.reserve( feed.size() ); + // vec_tensor.reserve( feed.size ()) ; + + // auto new_res = input_dict.cast(); + + for (auto &item : input_dict) { + // cerr << "test flag " << test_flag << endl; + // cerr << item.first << endl; + framework::LoDTensor t; + SetTensorFromPyArray( + &t, item.second, platform::CPUPlace(), false); + + // cerr << t.dims() << endl; + // cerr << t.data()[0] << endl; + + vec_name.push_back(item.first); + vec_tensor.push_back(t); + } + + // std::cerr << "11" << std::endl; + std::vector vec_out; + self.run(vec_name, vec_tensor, vec_fetch_name, vec_out); + // self.Run(prog, scope, block_id, create_local_scope, create_vars, + // fetch_vars); + std::vector vec_ret; + for (size_t i = 0; i < vec_out.size(); ++i) { + vec_ret.push_back(TensorToPyArray(vec_out[i], true)); + } + return vec_ret; + }) + .def("run", + [](InterpreterCore &self, + const std::unordered_map &input_dict, + std::vector vec_fetch_name) { + pybind11::gil_scoped_release release; + std::vector vec_tensor; + std::vector vec_name; + + for (auto &item : input_dict) { + vec_name.push_back(item.first); + vec_tensor.push_back(item.second); + } + + std::vector vec_out; + self.run(vec_name, vec_tensor, vec_fetch_name, vec_out); + + std::vector vec_ret; + for (size_t i = 0; i < vec_out.size(); ++i) { + vec_ret.push_back(TensorToPyArray(vec_out[i], true)); + } + return vec_ret; + }); m.def("init_gflags", framework::InitGflags); m.def("init_glog", framework::InitGLOG);