Skip to content

Commit

Permalink
fix relay.build to not change the module argument in place
Browse files Browse the repository at this point in the history
  • Loading branch information
t-vi committed Jun 16, 2020
1 parent 99745a4 commit 758002d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/relay/backend/build_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class RelayBuildModule : public runtime::ModuleNode {
*/
IRModule Optimize(IRModule relay_module, const TargetsMap& targets,
const std::unordered_map<std::string, runtime::NDArray>& params) {
IRModuleNode* relay_module_ptr = relay_module.CopyOnWrite();
if (params.size()) {
CHECK(relay_module->ContainGlobalVar("main")) << "Missing the main entry function";
GlobalVar main_glb_var = relay_module->GetGlobalVar("main");
Expand Down
7 changes: 6 additions & 1 deletion tests/python/relay/test_cpp_build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def test_basic_build():
targets = {
tvm.tir.IntImm("int32", ctx.device_type): tgt
}
g_json, mmod, params = relay.build(tvm.IRModule.from_expr(func), targets, "llvm", params=params)
mod = tvm.IRModule.from_expr(func)
func_in_mod = mod["main"]
assert mod["main"] == func_in_mod, "cannot compare function to itself"

g_json, mmod, params = relay.build(mod, targets, "llvm", params=params)
assert mod["main"] == func_in_mod, "relay.build changed module in-place"

# test
rt = tvm.contrib.graph_runtime.create(g_json, mmod, ctx)
Expand Down

0 comments on commit 758002d

Please sign in to comment.