Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RELAY] Port winograd ops to relay #2356

Merged
merged 8 commits into from
Jan 7, 2019
Merged

Conversation

merrymercy
Copy link
Member

@merrymercy merrymercy commented Dec 31, 2018

  • Port winograd related ops to relay. Now benchmarks under apps/benchmark for nvidia gpu/arm cpu/mali gpu can be compiled by relay without performance regression.
  • Fix scalar and concatenate in alter_op_layout

To make alter_op_layout in TOPI support both NNVM and Relay, a new argument F is added, which can be either relay.op or nnvm.sym.

Know issues:

  • NCHWc in x86 backend has not been ported yet

Copy link
Member

@vinx13 vinx13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an issue that alter_op_layout doesn't work with scalar
e.g. relay.add(relay.nn.conv2d(...), relay.const(1.0)) output of conv2d will fallback to original layout because the inferred layout of constant is undef

@@ -151,7 +151,8 @@ def optimize(func, params=None):
func = ir_pass.combine_parallel_conv2d(func)

if cfg.pass_enabled("FoldConstant"):
func = ir_pass.fold_constant(func)
with _target.create("llvm"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new target is unnecessary because FoldConstant always creates a new llvm target

Copy link
Member Author

@merrymercy merrymercy Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, can you compile inception_v3 with relay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can compile inception v3 without AlterOpLayout, otherwise I got type_infer.cc:314: the function is provided too many arguments (nullptr)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -38,7 +38,7 @@ struct Conv2DAttrs : public tvm::AttrsNode<Conv2DAttrs> {
IndexExpr channels;
Array<IndexExpr> kernel_size;
std::string data_layout;
std::string weight_layout;
std::string kernel_layout;
Copy link
Member Author

@merrymercy merrymercy Jan 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose: rename weight_layout to kernel_layout to make relay consistent with nnvm and mxnet

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@merrymercy
Copy link
Member Author

merrymercy commented Jan 3, 2019

@vinx13 That issue is because the zero dimensional layout of a scalar is not defined. Fixed by my commit 78eaf0e

@@ -222,7 +225,8 @@ def build(func,
cfg = BuildConfig.current

with tophub_context:
func = optimize(func, params)
with target:
Copy link
Member

@zhiics zhiics Jan 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May I ask why we need to have with target here? Is it used by layout altering? It seems that constant folding is not target dependent because it always uses llvm as the target.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhiics alter_op_layout relies on current target to query autotvm log

Copy link
Member

@zhiics zhiics Jan 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vinx13 I just saw that. Thanks for your quick response. Can we pass the target to alter layout? I am asking is because for heterogeneous compilation we will pass in multiple targets. It is probably not convenient to know which target to be with here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I passed target as an argument and use it explicitly for target-specific passes. Alter_op_layout calls functions similar to topi compute/topi schedule and will modify the graph, so I think it is not straightforward to port it to heterogeneous compilation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@merrymercy Thanks. It doesn't really solve the problem. But I think we can keep it like this first because it at least won't break homogeneous execution. I will think about it later in the heterogeneous pass.

// NOTE: Do not check weight shape here!
// Different backend requires different layout to compute
// the batch gemm stage in winograd efficiently, but we want to
// make this NNVM symbol work for all backends.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we update this comment?


for (auto new_arg : new_args) {
// NOTE: do not support nested tuple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to generically handle nested tuples, the handling of nested tuples has appeared in multiple places including the execution + optimization of AD.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I leave it to later PRs..

@@ -523,9 +523,8 @@ def _callback(op):

##### REGISTER ALTER OP LAYOUT #####
@conv2d_alter_layout.register(["arm_cpu"])
def _alter_conv2d_layout_arm(attrs, inputs, tinfos):
def _alter_conv2d_layout_arm(attrs, inputs, tinfos, F):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we provide a documentation comment here with information about the parameters including F?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

@jroesch
Copy link
Member

jroesch commented Jan 4, 2019

Overall looks good, just some minor comments.

@merrymercy
Copy link
Member Author

merrymercy commented Jan 6, 2019

comments are fixed @jroesch @zhiics
ready for merge @tqchen

@srkreddy1238
Copy link
Contributor

thanks @merrymercy .
This PR fixes #2382. I verified it.
Also I noted weights_layout -> kernal_layout for convolution param.

Copy link
Contributor

@srkreddy1238 srkreddy1238 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AlterOpLayout changes LGTM.

@tqchen
Copy link
Member

tqchen commented Jan 7, 2019

Since this PR fixes some bugs that other PRs are pending on. I am going to merge this in.

The proposed change of weight_layout->kernel_layout needs some further discussion(in particular, the meaning of the "kernel", does it refer to the weight, or only spatial part of the weight), but because relay has not been released as a stable branch and kernel_layout was closer to NNVMv1, I won't view this as a regression for now.

@tqchen tqchen merged commit 426e3bb into apache:master Jan 7, 2019
@tqchen
Copy link
Member

tqchen commented Jan 7, 2019

zhiics pushed a commit to zhiics/tvm that referenced this pull request Jan 7, 2019
@merrymercy merrymercy deleted the relay-winograd branch January 9, 2019 11:34
FrozenGene pushed a commit to FrozenGene/tvm that referenced this pull request Jan 10, 2019
@ZihengJiang ZihengJiang mentioned this pull request Feb 1, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
wweic pushed a commit to neo-ai/tvm that referenced this pull request Feb 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants