Skip to content

Commit

Permalink
fix recurrent_grad tmp variable@GRAD don't exsit in VariableScope
Browse files Browse the repository at this point in the history
  • Loading branch information
2742195759 committed Nov 9, 2021
1 parent d817388 commit 2c8e584
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions paddle/fluid/framework/new_executor/interpretercore_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ std::vector<OperatorBase*> create_all_ops(const framework::BlockDesc& block) {
}

std::tuple<VariableValueMap, VariableIdMap> build_variable_map(
const VariableNameMap& var_name_map, VariableScope* var_scope) {
const VariableNameMap& var_name_map, VariableScope* var_scope,
bool enforce_exist = true) {
VariableValueMap name2var;
VariableIdMap name2id;
for (auto& item : var_name_map) {
Expand All @@ -183,6 +184,11 @@ std::tuple<VariableValueMap, VariableIdMap> build_variable_map(
vars.reserve(item.second.size());

for (auto& var_name : item.second) {
if (!enforce_exist && !var_scope->HasVar(var_name)) {
// skip the non-exist variable: such as recurrent_grad
VLOG(4) << var_name << " don't exist in variable scope, skip it!";
continue;
}
auto var_id = var_scope->VarId(var_name);
auto* in_var = var_scope->Var(var_id);
vars.push_back(in_var);
Expand Down Expand Up @@ -439,13 +445,15 @@ void build_op_func_list(const platform::Place& place,

VariableValueMap ins_map;
VariableIdMap ins_name2id;
bool enforce_exist = true;
if (op->Type() == "recurrent_grad") enforce_exist = false;
std::tie(ins_map, ins_name2id) =
build_variable_map(inputs_names, var_scope);
build_variable_map(inputs_names, var_scope, enforce_exist);

VariableValueMap outs_map;
VariableIdMap outs_name2id;
std::tie(outs_map, outs_name2id) =
build_variable_map(outputs_names, var_scope);
build_variable_map(outputs_names, var_scope, enforce_exist);

// step 2: build OpFuncNode
OpFuncNode op_func_node;
Expand Down

1 comment on commit 2c8e584

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.