From 88d71fa2f9655c206d398088effe3cb1a43dafc4 Mon Sep 17 00:00:00 2001 From: Qiao Longfei Date: Thu, 17 Jan 2019 17:30:27 +0800 Subject: [PATCH] support num_iteration_per_run --- .../framework/details/async_ssa_graph_executor.cc | 3 +++ paddle/fluid/framework/details/execution_strategy.h | 2 ++ paddle/fluid/pybind/pybind.cc | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/paddle/fluid/framework/details/async_ssa_graph_executor.cc b/paddle/fluid/framework/details/async_ssa_graph_executor.cc index d3e4573e22..ba2e90d052 100644 --- a/paddle/fluid/framework/details/async_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/async_ssa_graph_executor.cc @@ -56,6 +56,9 @@ FeedFetchList AsyncSSAGraphExecutor::Run( for (size_t i = 0; i < places_.size(); ++i) { auto call = [this, i, &fetch_tensors]() -> FeedFetchList { try { + for (size_t j = 0; j < strategy_.num_iteration_per_run_ - 1; ++j) { + executors_[i]->Run(fetch_tensors); + } return executors_[i]->Run(fetch_tensors); } catch (...) { exception_holder_.Catch(std::current_exception()); diff --git a/paddle/fluid/framework/details/execution_strategy.h b/paddle/fluid/framework/details/execution_strategy.h index 37b07e5736..dec4589cad 100644 --- a/paddle/fluid/framework/details/execution_strategy.h +++ b/paddle/fluid/framework/details/execution_strategy.h @@ -28,6 +28,8 @@ struct ExecutionStrategy { size_t num_iteration_per_drop_scope_{1}; ExecutorType type_{kDefault}; bool dry_run_{false}; + size_t num_iteration_per_run_{1}; // only use with async_ssa_graph_executor + // and pyreader with data queue }; } // namespace details diff --git a/paddle/fluid/pybind/pybind.cc b/paddle/fluid/pybind/pybind.cc index 88d12c69b7..b52f99f324 100644 --- a/paddle/fluid/pybind/pybind.cc +++ b/paddle/fluid/pybind/pybind.cc @@ -892,6 +892,17 @@ All parameter, weight, gradient are variables in Paddle. 2. In some NLP model, it may cause the GPU memory is insufficient, in this case, you should reduce `num_iteration_per_drop_scope`. )DOC") + .def_property( + "num_iteration_per_run", + [](const ExecutionStrategy &self) { + return self.num_iteration_per_run_; + }, + [](ExecutionStrategy &self, size_t num_iteration_per_run) { + self.num_iteration_per_run_ = num_iteration_per_run; + }, + R"DOC(This config that how many iteration the executor will run when + user call pe.run() in python + )DOC") .def_property("_dry_run", [](const ExecutionStrategy &self) { return self.dry_run_; }, [](ExecutionStrategy &self, bool dry_run) { -- GitLab