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] Conv2D padding representation #4787

Merged
merged 10 commits into from
Feb 5, 2020
Merged

Conversation

zxy844288792
Copy link
Contributor

As discussed here: https://discuss.tvm.ai/t/rfc-conv2d-padding-representation/5394. We agree we should enforce topi.nn.conv2d to accept 4-way padding. We also should have relay.nn.conv2d legalizes the padding to 4-way.

get_pad_tuple is from topi util.py. I deleted some unuseful code and reuse it for relay.op.nn.conv2d.

Thanks for contributing to TVM! Please refer to guideline https://docs.tvm.ai/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.

Copy link
Contributor

@comaniac comaniac left a comment

Choose a reason for hiding this comment

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

Leave some comments.

Also, I found that now we have get_pad_tuple in both Relay and TOPI. I feel that we should remove the TOPI one to enforce the TOPI conv2d input type. @icemelon9 @yzhliu do you guys have any suggestions?

python/tvm/relay/op/nn/nn.py Outdated Show resolved Hide resolved
python/tvm/relay/op/nn/util.py Outdated Show resolved Hide resolved
python/tvm/relay/op/nn/nn.py Outdated Show resolved Hide resolved
topi/python/topi/nn/conv2d.py Outdated Show resolved Hide resolved
@@ -62,6 +61,8 @@ def conv2d(input, filter, strides, padding, dilation, layout='NCHW', out_dtype=N
output : tvm.Tensor
4-D with shape [batch, out_channel, out_height, out_width]
"""
#only accepts 4-way padding
assert len(padding) == 4, "only accepts 4-way padding"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid that you have to add this assertion to all conv2d compute functions. Specifically, all conv2d functions with @autotvm.register_topi_compute(nn.conv2d, ...) decorator should have this assertion. @icemelon9 could you help confirm?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, @comaniac is correct. Probably directly contribute to #4644? 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

@zxy844288792 how about we revert this file first and add a note in python/tvm/relay/op/nn/nn.py to remind us to add it back when #4644 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@comaniac Agree

@comaniac
Copy link
Contributor

LGTM.
@icemelon9 @yzhliu could you help review and merge? Thanks.

@icemelon
Copy link
Member

You should also add get_pad_tuple2d to these contrib conv2d ops, e.g., contrib_conv2d_nchwc

@zxy844288792
Copy link
Contributor Author

You should also add get_pad_tuple2d to these contrib conv2d ops, e.g., contrib_conv2d_nchwc

I have added get_pad_tuple2d for contrib_conv2d_nchwc and contrib_conv2d_nchwc_int8, contrib_conv2d_winograd_without_weight_transform and contrib_conv2d_winograd_nnpack_without_weight_transform

Copy link
Contributor

@kevinthesun kevinthesun left a comment

Choose a reason for hiding this comment

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

LGTM

@icemelon
Copy link
Member

icemelon commented Feb 4, 2020

@zxy844288792 I see that you didn't modify the contrib_depthwise_conv2d_nchwc. Should we also use get_pad_tuple2d for it?

@kevinthesun kevinthesun merged commit 5ea4f0d into apache:master Feb 5, 2020
@kevinthesun
Copy link
Contributor

Thanks @zxy844288792 @icemelon9 @comaniac

anijain2305 pushed a commit to anijain2305/tvm that referenced this pull request Feb 10, 2020
* enforce 4-way padding

* add util with get_pad_tuple

* delete unnecessary arguments

* fix lint

* add container.Array case

* fix cudnn conv2d asymmetric padding logic

* rename get_pad_tuple to get_pad_tuple2d

* revert change for topi/python/topi/nn/conv2d.py

* add get_pad_tuple2d for several contrib conv2d ops

* add get_pad_tuple2d for all conv2d ops
alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 26, 2020
* enforce 4-way padding

* add util with get_pad_tuple

* delete unnecessary arguments

* fix lint

* add container.Array case

* fix cudnn conv2d asymmetric padding logic

* rename get_pad_tuple to get_pad_tuple2d

* revert change for topi/python/topi/nn/conv2d.py

* add get_pad_tuple2d for several contrib conv2d ops

* add get_pad_tuple2d for all conv2d ops
alexwong pushed a commit to alexwong/tvm that referenced this pull request Feb 28, 2020
* enforce 4-way padding

* add util with get_pad_tuple

* delete unnecessary arguments

* fix lint

* add container.Array case

* fix cudnn conv2d asymmetric padding logic

* rename get_pad_tuple to get_pad_tuple2d

* revert change for topi/python/topi/nn/conv2d.py

* add get_pad_tuple2d for several contrib conv2d ops

* add get_pad_tuple2d for all conv2d ops
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Mar 2, 2020
* enforce 4-way padding

* add util with get_pad_tuple

* delete unnecessary arguments

* fix lint

* add container.Array case

* fix cudnn conv2d asymmetric padding logic

* rename get_pad_tuple to get_pad_tuple2d

* revert change for topi/python/topi/nn/conv2d.py

* add get_pad_tuple2d for several contrib conv2d ops

* add get_pad_tuple2d for all conv2d ops
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.

4 participants