From ec115140273184e62354c0055d4d0ee3054b61d0 Mon Sep 17 00:00:00 2001 From: Dong Zhihong Date: Sat, 14 Oct 2017 14:49:22 -0700 Subject: [PATCH] "fix findVar logic" --- paddle/framework/block_desc.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/paddle/framework/block_desc.cc b/paddle/framework/block_desc.cc index e71eb3cb510..e2446bde6d5 100644 --- a/paddle/framework/block_desc.cc +++ b/paddle/framework/block_desc.cc @@ -21,16 +21,19 @@ namespace framework { VarDescBind *BlockDescBind::Var(const std::string &name) { need_update_ = true; auto it = vars_.find(name); - PADDLE_ENFORCE(it == vars_.end(), "Duplicated variable %s", name); - auto var = new VarDescBind(name); + if (it != vars_.end()) { + return it->secon.get(); + } + auto *var = new VarDescBind(name); vars_[name].reset(var); return var; } VarDescBind *BlockDescBind::FindVar(const std::string &name) const { auto it = vars_.find(name); - PADDLE_ENFORCE(it != vars_.end(), - "Can not find variable %s in current block.", name); + if (it == vars_.end()) { + return nullptr; + } return it->second.get(); } -- GitLab