diff --git a/lite/model_parser/model_parser.cc b/lite/model_parser/model_parser.cc index 77c7543d6be778e3763220f3d30a0c58ffc2fdde..b253c911a36dc8896f1fd1db6c27c0a4e3d17994 100644 --- a/lite/model_parser/model_parser.cc +++ b/lite/model_parser/model_parser.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include "lite/core/scope.h" #include "lite/core/tensor.h" #include "lite/core/variable.h" @@ -528,12 +529,16 @@ void SaveCombinedParamsNaive(const std::string &path, auto prog = cpp_prog; auto &main_block_desc = *prog.GetBlock(0); + // set unique_var_names to avoid saving shared params repeatedly + std::unordered_set unique_var_names; for (size_t i = 0; i < main_block_desc.VarsSize(); ++i) { auto &var = *main_block_desc.GetVar(i); - if (var.Name() == "feed" || var.Name() == "fetch" || !var.Persistable()) + if (var.Name() == "feed" || var.Name() == "fetch" || !var.Persistable() || + unique_var_names.count(var.Name()) > 0) continue; naive_buffer::ParamDesc param_desc(desc.AddParam()); SetParamInfoNaive(¶m_desc, exec_scope, var.Name()); + unique_var_names.emplace(var.Name()); } pt_desc.Save();