From 0d53f5afa7ea7175c673f8640fe98ea83be37954 Mon Sep 17 00:00:00 2001 From: mapingshuo Date: Tue, 23 Jun 2020 10:15:47 +0800 Subject: [PATCH] avoid saving shared params repeatedly (#3561) (#3823) * avoid saving shared params repeatedly (#3561) * test=develop Co-authored-by: zhupengyang Co-authored-by: huzhiqiang <912790387@qq.com> --- lite/model_parser/model_parser.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lite/model_parser/model_parser.cc b/lite/model_parser/model_parser.cc index 77c7543d6b..b253c911a3 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(); -- GitLab