From 5419da6e7a9bc9f7078e3b77abe664cacaa45bf0 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Thu, 22 Mar 2018 07:01:41 +0000 Subject: [PATCH] Fix bug caused by block_id. --- paddle/fluid/framework/executor.cc | 18 ++++++++---------- paddle/fluid/framework/executor.h | 2 +- paddle/fluid/inference/tests/test_helper.h | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/paddle/fluid/framework/executor.cc b/paddle/fluid/framework/executor.cc index b576e5f39e6..5de2b78f3ae 100644 --- a/paddle/fluid/framework/executor.cc +++ b/paddle/fluid/framework/executor.cc @@ -93,8 +93,9 @@ static void CheckTensorNANOrInf(const std::string& name, "Tensor %s contains NAN", name); } -void Executor::CreateVariables(const ProgramDesc& pdesc, Scope* scope) { - auto& global_block = pdesc.Block(0); +void Executor::CreateVariables(const ProgramDesc& pdesc, Scope* scope, + int block_id) { + auto& global_block = pdesc.Block(block_id); const Scope* ancestor_scope = scope; while (ancestor_scope->parent()) { @@ -318,14 +319,11 @@ std::unique_ptr Executor::Prepare( void Executor::RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope, bool create_local_scope, bool create_vars) { Scope* local_scope = scope; - if (create_vars) { - if (create_local_scope) { - local_scope = &scope->NewScope(); - } else { - } // if (create_local_scope) - } // if (create_vars) - - CreateVariables(ctx->prog_, local_scope); + if (create_vars && create_local_scope) { + local_scope = &scope->NewScope(); + } + + CreateVariables(ctx->prog_, local_scope, ctx->block_id_); for (auto& op : ctx->ops_) { VLOG(3) << place_ << " " << op->DebugStringEx(local_scope); diff --git a/paddle/fluid/framework/executor.h b/paddle/fluid/framework/executor.h index 688ba09f9b9..75ea9a885cc 100644 --- a/paddle/fluid/framework/executor.h +++ b/paddle/fluid/framework/executor.h @@ -60,7 +60,7 @@ class Executor { static std::unique_ptr Prepare( const ProgramDesc& program, int block_id); - void CreateVariables(const ProgramDesc& pdesc, Scope* scope); + void CreateVariables(const ProgramDesc& pdesc, Scope* scope, int block_id); void RunPreparedContext(ExecutorPrepareContext* ctx, Scope* scope, bool create_local_scope = true, diff --git a/paddle/fluid/inference/tests/test_helper.h b/paddle/fluid/inference/tests/test_helper.h index 68dd020f395..9f6c6086964 100644 --- a/paddle/fluid/inference/tests/test_helper.h +++ b/paddle/fluid/inference/tests/test_helper.h @@ -171,7 +171,7 @@ void TestInference(const std::string& dirname, { const bool create_vars = false; if (!create_vars) { - executor.CreateVariables(*inference_program, scope); + executor.CreateVariables(*inference_program, scope, 0); } // Ignore the profiling results of the first run -- GitLab