Hello All,
I’m trying to generate subgraph from an existing graph. After going through tvm documentation, I found that PartitionGraph() is recommended to split a graph.
My goal is to generate a sub graph from an existing graph to run on backend. I am able to generate subgraph using PartitionGraph() API. However, while providing the partitioned graph as input to relay.build, I’m seeing an error from TVM.
File “tvm/src/relay/backend/graph_executor_codegen.cc”, line 198 TVMError: Check failed: count > 0 (0 vs. 0) : Expr is not existing in storage plan
Mentioned below is the test case to reproduce the error. Please note, this example is modified from test_multiple_outputs function
def create_graph():
data = relay.var("data", relay.TensorType((1, 3, 224, 224), "float32"))
weight = relay.var("weight", relay.TensorType((16, 3, 3, 3), "float32"))
bn_gamma = relay.var("bn_gamma", relay.TensorType((16,), "float32"))
bn_beta = relay.var("bn_beta", relay.TensorType((16,), "float32"))
bn_mean = relay.var("bn_mean", relay.TensorType((16,), "float32"))
bn_var = relay.var("bn_var", relay.TensorType((16,), "float32"))
data_cb = compiler_begin(data, "test_target")
bn_gamma_cb = compiler_begin(bn_gamma, "test_target")
bn_beta_cb = compiler_begin(bn_beta, "test_target")
bn_mean_cb = compiler_begin(bn_mean, "test_target")
bn_var_cb = compiler_begin(bn_var, "test_target")
w0 = relay.var("w0", relay.TensorType((16, 3, 3, 3), "float32"))
z0 = relay.add(weight, w0)
z0_cb = compiler_begin(z0, "test_target")
conv_o = relay.nn.conv2d(
data=data_cb, weight=z0_cb, kernel_size=(3, 3), channels=16, padding=(1, 1)
)
bn_o = relay.nn.batch_norm(conv_o, bn_gamma_cb, bn_beta_cb, bn_mean_cb, bn_var_cb)
relu_o = relay.nn.relu(bn_o[0])
relu_o_ce = compiler_end(relu_o, "test_target")
bn_omean = bn_o[1]
rebn_omean_ce = compiler_end(bn_omean, "test_target")
bn_ovar = bn_o[2]
bn_ovar_ce = compiler_end(bn_ovar, "test_target")
dummy_mean_abs = relay.abs(rebn_omean_ce)
dummy_ovar_abs = relay.abs(bn_ovar_ce)
dummy_tuple = relay.Tuple((relu_o_ce, dummy_mean_abs, dummy_ovar_abs))
func = relay.Function([data, weight, bn_gamma, bn_beta, bn_mean, bn_var, w0], dummy_tuple)
return func
mod = tvm.IRModule()
// Create relay graph
mod["main"] = create_graph()
// Partition the graph based on annotations in create_graph() function
partitioned = transform.PartitionGraph()(mod)
// Create a new IRModule to store subgraph
new_mod = tvm.IRModule()
// Check for the other function apart from main
for func in partitioned.functions.keys():
func_str = str(func.name_hint)
if(func_str != "main"):
new_mod["main"] = partitioned[func_str]
// Set global symbol attribute to main
new_mod["main"] = new_mod["main"].with_attr("global_symbol", 'main')
json, lib, param = relay.build(new_mod, target="llvm", params=None, mod_name="default")
The last step i.e. relay.build is erroring out.
When I check try to debug the problem, I see that memory_plan_ is getting executed correctly in the following line.
Any help would be greatly appreciated. @comaniac @csullivan
Thanks in advance!