From 8c7c2053b88c324bdd4fcae8ae27fb44e68656b3 Mon Sep 17 00:00:00 2001 From: Trevor Morris Date: Tue, 4 May 2021 23:53:24 +0000 Subject: [PATCH] Remove ext params stored in metadata from params to avoid duplication --- src/relay/backend/build_module.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/relay/backend/build_module.cc b/src/relay/backend/build_module.cc index 71f19a1c21bcf..88faff22cd310 100644 --- a/src/relay/backend/build_module.cc +++ b/src/relay/backend/build_module.cc @@ -565,6 +565,19 @@ class RelayBuildModule : public runtime::ModuleNode { auto ext_mods = executor_codegen_->GetExternalModules(); ret_.mod = tvm::codegen::CreateMetadataModule(ret_.params, ret_.mod, ext_mods, GetTargetHost(), executor_codegen_->GetMetadata()); + // Remove external params which were stored in metadata module. + for (tvm::runtime::Module mod : ext_mods) { + auto pf_var = mod.GetFunction("get_const_vars"); + if (pf_var != nullptr) { + Array variables = pf_var(); + for (size_t i = 0; i < variables.size(); i++) { + auto it = ret_.params.find(variables[i].operator std::string()); + if (it != ret_.params.end()) { + ret_.params.erase(it); + } + } + } + } } private: