diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc index be87549ecbfbc17782776ffc6f08be33f0f5d049..9d114ed0c19f7e684249a51286c2bcd8cd225c30 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.cc @@ -1218,6 +1218,16 @@ std::unordered_set GetSpecialOpNames() { }; } +void BuildId2VarName(const std::map& var_name_2_id, + std::unordered_map* id_2_var_name) { + PADDLE_ENFORCE_NOT_NULL( + id_2_var_name, + phi::errors::InvalidArgument("id2_var_name can not be null")); + for (auto [var_name, id] : var_name_2_id) { + id_2_var_name->insert({id, var_name}); + } +} + } // namespace interpreter } // namespace framework } // namespace paddle diff --git a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.h b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.h index 186f9459fbac7a68586490ca80d54d07bf33bacc..33b89cac542d488e7514351113e6630a30092efc 100644 --- a/paddle/fluid/framework/new_executor/interpreter/interpreter_util.h +++ b/paddle/fluid/framework/new_executor/interpreter/interpreter_util.h @@ -116,6 +116,8 @@ void BuildOpFuncList( void BuildVariableScope(const framework::BlockDesc& block, const ExecutionConfig& execution_config, VariableScope* var_scope); +void BuildId2VarName(const std::map& var_name_2_id, + std::unordered_map* id_2_var_name); void LogDeviceMemoryStats(const platform::Place& place); diff --git a/paddle/fluid/framework/new_executor/new_ir_interpreter.cc b/paddle/fluid/framework/new_executor/new_ir_interpreter.cc index e026e914adb575cc312288eba37c8d4da95eedc8..37cecdad1308e33cf5c01fad4119e055b435d732 100644 --- a/paddle/fluid/framework/new_executor/new_ir_interpreter.cc +++ b/paddle/fluid/framework/new_executor/new_ir_interpreter.cc @@ -194,11 +194,10 @@ std::string NewIRInterpreter::GetNameById(int id) const { // typically when the target variable is not existed in the original program // desc, but created by interpretercore. // For example, created and used by d2h_copy or h2d_copy operator. - auto it = std::find_if(var_name_2_id_.begin(), - var_name_2_id_.end(), - [id](const auto& pair) { return pair.second == id; }); - if (it != var_name_2_id_.end()) { - return it->first; + + auto it = id_2_var_name_.find(id); + if (it != id_2_var_name_.end()) { + return it->second; } return ""; } @@ -925,6 +924,9 @@ FetchList NewIRInterpreter::Run(const std::vector& feed_names, &variable_2_var_name_, &var_name_2_id_, &variable_list_); + + interpreter::BuildId2VarName(var_name_2_id_, &id_2_var_name_); + VLOG(4) << "Done BuildScope"; VLOG(4) << DebugValueInfo(); diff --git a/paddle/fluid/framework/new_executor/new_ir_interpreter.h b/paddle/fluid/framework/new_executor/new_ir_interpreter.h index 841e9136a2ecc1b693ad7d74c638f593e23ec94d..b37b26d107560f899d7698c98767555603d62846 100644 --- a/paddle/fluid/framework/new_executor/new_ir_interpreter.h +++ b/paddle/fluid/framework/new_executor/new_ir_interpreter.h @@ -208,6 +208,7 @@ class NewIRInterpreter : public InterpreterBaseImpl { variable_2_var_name_; std::map var_name_2_id_; + std::unordered_map id_2_var_name_; std::vector variable_list_;