diff --git a/paddle/fluid/train/custom_trainer/feed/accessor/dense_input_accessor.cc b/paddle/fluid/train/custom_trainer/feed/accessor/dense_input_accessor.cc index 1957b695c17a73c876fc36c0586a8b7559b75e56..29b0724ae35ff0e63bfcedd9664a8c3527ccfa29 100644 --- a/paddle/fluid/train/custom_trainer/feed/accessor/dense_input_accessor.cc +++ b/paddle/fluid/train/custom_trainer/feed/accessor/dense_input_accessor.cc @@ -78,43 +78,6 @@ int32_t DenseInputAccessor::forward(SampleInstance* samples, size_t num, return 0; } -int32_t DenseInputAccessor::backward(SampleInstance* samples, size_t num, - paddle::framework::Scope* scope) { - if (!_need_gradient) { - return 0; - } - size_t data_buffer_idx = 0; - std::vector regions; - for (auto& variable : _x_variables) { - auto* tensor = scope->Var(variable.gradient_name)-> - GetMutable(); - auto* grad_data = tensor->mutable_data(_trainer_context->cpu_place); - regions.emplace_back(grad_data, variable.dim); - } - auto* ps_client = _trainer_context->pslib->ps_client(); - auto push_status = ps_client->push_dense(regions.data(), regions.size(), _table_id); - //push_status.get(); - if (!FLAGS_feed_trainer_debug_dense_name.empty()) { - std::stringstream ssm; - for (auto& variable : _x_variables) { - ssm.str(""); - if (variable.name != FLAGS_feed_trainer_debug_dense_name) { - continue; - } - auto& tensor = scope->Var(variable.gradient_name)-> - Get(); - const auto* var_data = tensor.data(); - for (size_t data_idx = 0; data_idx < variable.dim; ++data_idx) { - if (data_idx > 0) - ssm << ","; - ssm << var_data[data_idx]; - } - VLOG(2) << "[DEBUG]push_dense: " << ssm.str(); - } - } - return 0; -} - int32_t DenseInputAccessor::collect_persistables(paddle::framework::Scope* scope) { // 首次同步pull,之后异步pull if (_data_buffer == nullptr) { @@ -178,6 +141,43 @@ int32_t DenseInputAccessor::collect_persistables_name(std::vector& return 0; } +int32_t DenseInputAccessor::backward(SampleInstance* samples, size_t num, + paddle::framework::Scope* scope) { + if (!_need_gradient) { + return 0; + } + size_t data_buffer_idx = 0; + std::vector regions; + for (auto& variable : _x_variables) { + auto* tensor = scope->Var(variable.gradient_name)-> + GetMutable(); + auto* grad_data = tensor->mutable_data(_trainer_context->cpu_place); + regions.emplace_back(grad_data, variable.dim); + } + auto* ps_client = _trainer_context->pslib->ps_client(); + auto push_status = ps_client->push_dense(regions.data(), regions.size(), _table_id); + //push_status.get(); + if (!FLAGS_feed_trainer_debug_dense_name.empty()) { + std::stringstream ssm; + for (auto& variable : _x_variables) { + ssm.str(""); + if (variable.name != FLAGS_feed_trainer_debug_dense_name) { + continue; + } + auto& tensor = scope->Var(variable.gradient_name)-> + Get(); + const auto* var_data = tensor.data(); + for (size_t data_idx = 0; data_idx < variable.dim; ++data_idx) { + if (data_idx > 0) + ssm << ","; + ssm << var_data[data_idx]; + } + VLOG(2) << "[DEBUG]push_dense: " << ssm.str(); + } + } + return 0; +} + int32_t EbdVariableInputAccessor::forward(SampleInstance* samples, size_t num, paddle::framework::Scope* scope) { CHECK(_x_variables.size() == 1); diff --git a/paddle/fluid/train/custom_trainer/feed/executor/multi_thread_executor.cc b/paddle/fluid/train/custom_trainer/feed/executor/multi_thread_executor.cc index e7ef07b0fd4ad5acc5f7990a49dc4826a797d6f8..3e027589f2f02b4097366a7b00b58757738e3d9b 100644 --- a/paddle/fluid/train/custom_trainer/feed/executor/multi_thread_executor.cc +++ b/paddle/fluid/train/custom_trainer/feed/executor/multi_thread_executor.cc @@ -2,6 +2,8 @@ #include "paddle/fluid/train/custom_trainer/feed/io/file_system.h" #include "paddle/fluid/train/custom_trainer/feed/monitor/monitor.h" #include "paddle/fluid/train/custom_trainer/feed/executor/multi_thread_executor.h" +#include "paddle/fluid/framework/executor.h" +#include "paddle/fluid/framework/program_desc.h" namespace paddle { namespace custom_trainer {