|
|
|
@ -121,13 +121,27 @@ void PipelineTrainer::Initialize(const TrainerDesc& trainer_desc,
|
|
|
|
|
|
|
|
|
|
|
|
void PipelineTrainer::InitFirstScopeQueue(ScopeQueue* scope_queue,
|
|
|
|
void PipelineTrainer::InitFirstScopeQueue(ScopeQueue* scope_queue,
|
|
|
|
int pipeline_id,
|
|
|
|
int pipeline_id,
|
|
|
|
const ProgramDesc& main_program) {
|
|
|
|
const ProgramDesc& main_program,
|
|
|
|
|
|
|
|
const Scope& root_scope) {
|
|
|
|
for (int i = 0; i < scope_queue_size_; ++i) {
|
|
|
|
for (int i = 0; i < scope_queue_size_; ++i) {
|
|
|
|
Scope* scope = &pipeline_scopes_[pipeline_id]->NewScope();
|
|
|
|
Scope* scope = &pipeline_scopes_[pipeline_id]->NewScope();
|
|
|
|
for (auto& var : main_program.Block(0).AllVars()) {
|
|
|
|
for (auto& var : main_program.Block(0).AllVars()) {
|
|
|
|
if (!var->Persistable()) {
|
|
|
|
if (!var->Persistable()) {
|
|
|
|
auto* ptr = scope->Var(var->Name());
|
|
|
|
auto* ptr = scope->Var(var->Name());
|
|
|
|
InitializeVariable(ptr, var->GetType());
|
|
|
|
InitializeVariable(ptr, var->GetType());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (section_num_ == 1) { // Means only one section and it must be
|
|
|
|
|
|
|
|
// CUDAPlace, so copy all persistable vars to
|
|
|
|
|
|
|
|
// pipeline scope
|
|
|
|
|
|
|
|
const LoDTensor& root_tensor =
|
|
|
|
|
|
|
|
root_scope.FindVar(var->Name())->Get<LoDTensor>();
|
|
|
|
|
|
|
|
LoDTensor* gpu_tensor = pipeline_scopes_[pipeline_id]
|
|
|
|
|
|
|
|
->Var(var->Name())
|
|
|
|
|
|
|
|
->GetMutable<LoDTensor>();
|
|
|
|
|
|
|
|
platform::Place place = platform::CUDAPlace(pipeline_id);
|
|
|
|
|
|
|
|
TensorCopy(*static_cast<const Tensor*>(&root_tensor), place,
|
|
|
|
|
|
|
|
static_cast<Tensor*>(gpu_tensor));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scope_queue->Send(scope);
|
|
|
|
scope_queue->Send(scope);
|
|
|
|
@ -162,7 +176,8 @@ void PipelineTrainer::InitTrainerEnv(const ProgramDesc& main_program,
|
|
|
|
if (i == 0) {
|
|
|
|
if (i == 0) {
|
|
|
|
pipeline_scopes_[j] = &root_scope_->NewScope();
|
|
|
|
pipeline_scopes_[j] = &root_scope_->NewScope();
|
|
|
|
CopyParameters(*root_scope_, j);
|
|
|
|
CopyParameters(*root_scope_, j);
|
|
|
|
InitFirstScopeQueue(scope_queues_[0].back().get(), j, main_program);
|
|
|
|
InitFirstScopeQueue(scope_queues_[0].back().get(), j, main_program,
|
|
|
|
|
|
|
|
*root_scope_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -192,7 +207,7 @@ void PipelineTrainer::InitTrainerEnv(const ProgramDesc& main_program,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pipeline_num_ > 1) {
|
|
|
|
if (pipeline_num_ > 1 && sync_steps_ != -1) {
|
|
|
|
construct_sync_functor();
|
|
|
|
construct_sync_functor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|