Skip to content

Commit

Permalink
[BYOC] Remove ext params stored in metadata from params to avoid dupl…
Browse files Browse the repository at this point in the history
…ication (apache#7977)

* Remove ext params stored in metadata from params to avoid duplication

* Add test for duplicate params
  • Loading branch information
Trevor Morris authored and trevor-m committed May 11, 2021
1 parent b857c1b commit 91f62ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/relay/backend/build_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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:
Expand Down
2 changes: 2 additions & 0 deletions tests/python/relay/test_external_codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def test_load_params_with_constants_in_ext_codegen():
mod = transform.PartitionGraph()(mod)

graph_module = relay.build(mod, target="llvm", params=params)
# Params will be stored in metadata module.
assert len(graph_module.get_params()) == 0
lib = update_lib(graph_module.get_lib())
rt_mod = tvm.contrib.graph_executor.create(graph_module.get_graph_json(), lib, tvm.cpu(0))
rt_mod.load_params(runtime.save_param_dict(graph_module.get_params()))
Expand Down

0 comments on commit 91f62ea

Please sign in to comment.