Skip to content

Conversation

@icemelon
Copy link
Member

@icemelon icemelon commented Dec 20, 2018

  • Add MXNet test examples to Relay
  • Fix a bug in BiasAddSimplifier. Thanks to @merrymercy for the patch.

@icemelon icemelon requested a review from merrymercy December 20, 2018 01:35
@merrymercy
Copy link
Member

merrymercy commented Dec 20, 2018

I already did type correction in
https://github.com/dmlc/tvm/blob/838e7181dd5e16aa5c7a87bbfbf11b5b42a80f1a/src/relay/pass/canonicalize_ops.cc#L29
And the following multiple bias_add example works. Could you give me a broken case?

import tvm
from tvm import relay

x = relay.var("x", shape=(1, 64, 56, 56))
bias = relay.var("bias")
bias2 = relay.var("bias")
weight = relay.var("weight")
y = relay.nn.conv2d(x, weight, channels=64, kernel_size=(3, 3), padding=(1, 1))
y = relay.nn.bias_add(y, bias)
y = relay.nn.bias_add(y, bias2)
y = relay.Function(relay.ir_pass.free_vars(y), y)

a = relay.ir_pass.infer_type(y)
a = relay.ir_pass.canonicalize_ops(a)

print(a.astext())

@icemelon
Copy link
Member Author

icemelon commented Dec 20, 2018

If you add another stmt in between these two bias_add, it will fail.

import tvm
from tvm import relay

x = relay.var("x", shape=(1, 64, 56, 56))
bias = relay.var("bias")
bias2 = relay.var("bias")
weight = relay.var("weight")
weight2 = relay.var("weight")
y = relay.nn.conv2d(x, weight, channels=64, kernel_size=(3, 3), padding=(1, 1))
y = relay.nn.bias_add(y, bias)
y = relay.nn.conv2d(y, weight2, channels=128, kernel_size=(3, 3), padding=(1, 1))
y = relay.nn.bias_add(y, bias2)
y = relay.Function(relay.ir_pass.free_vars(y), y)

a = relay.ir_pass.infer_type(y)
a = relay.ir_pass.canonicalize_ops(a)

print(a.astext())

@merrymercy
Copy link
Member

Try this one line change!
Other changes in this pr look good to me.

diff --git a/src/relay/pass/canonicalize_ops.cc b/src/relay/pass/canonicalize_ops.cc
index 77cd59e2..4482dc39 100644
--- a/src/relay/pass/canonicalize_ops.cc
+++ b/src/relay/pass/canonicalize_ops.cc
@@ -22,7 +22,7 @@ class BiasAddSimplifier : public ExprMutator {
       CHECK_EQ(call->args.size(), 2);
       const BiasAddAttrs* param = call->attrs.as<BiasAddAttrs>();
 
-      auto ttype = call->args[0]->type_as<TensorTypeNode>();
+      auto ttype = n->args[0]->type_as<TensorTypeNode>();
       size_t n_dim = ttype->shape.size();
       Expr expanded_bias = ExpandBiasToMatchAxis(call->args[1], n_dim, {param->axis});
       Expr ret = Add(call->args[0], expanded_bias);

@icemelon
Copy link
Member Author

Thanks @merrymercy. This change fixed the issue. Updated it this PR.

@merrymercy merrymercy merged commit 97ca403 into apache:master Dec 20, 2018
@icemelon icemelon deleted the mx branch December 20, 2018 22:52
zhiics pushed a commit to zhiics/tvm that referenced this pull request Dec 21, 2018
* Add MXNet test example for relay
* Fix a bug in BiasAddSimplifier
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Dec 27, 2018
* Add MXNet test example for relay
* Fix a bug in BiasAddSimplifier
@tqchen
Copy link
Member

tqchen commented Dec 27, 2018

This PR seems to be duplicated with https://github.com/dmlc/tvm/tree/master/tests/python/frontend/mxnet should we consolidate everything into one location?

wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
* Add MXNet test example for relay
* Fix a bug in BiasAddSimplifier
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
* Add MXNet test example for relay
* Fix a bug in BiasAddSimplifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants