-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fixed issue #3069 by checking op tag #3070
Conversation
I am not sure if we want to introduce the additional attribute, as the number of input channels is implied by the input tensor itself. |
Thanks for your reply. I do feel this fix may not be optimal as well, but since the schedule_conv2d interface doesn’t take in any information about the inputs, it seems impossible to correctly distinguish depthwise and group conv2d. Please do let me know if you have any suggestion. Thanks |
Usually, in this case, we can hide additional information in the attrs field in the compute https://docs.tvm.ai/api/python/tvm.html?highlight=compute#tvm.compute |
Thank you so much for pointing that doc for me. Maybe I didn’t describe very clear about the context of this fix: the target issue happens while using Relay front end to convert a model with group convolution, which implies that I cannot apply a custom function or add a new attribute without changing the existing mechanisms within Relay. Therefore, I’m afraid I cannot see a viable solution based on tvm.compute specifically for the case in issue #3069. Please let me know if you have any other hint, thanks! |
@kumasento We don't need to add extra attrs to conv2d, since autotvm registers "workload" for conv2d compute. In schedule, you can simply call |
@kevinthesun Thank you so much for your valuable comment. I did try that but I could look deeper into this issue - would you mind letting me know where |
@kumasento https://github.com/dmlc/tvm/blob/master/python/tvm/autotvm/task/topi_integration.py#L333 |
Thank you so much @kevinthesun I will try this out tomorrow and get back to you |
Sorry for getting back late. I did a bit more investigation into the I will spend more time in this direction, but if you have any other suggestion, please let me know. Thanks! |
I'm still stuck here. I was trying to figure out the reason why I cannot have a If possible, could anyone give me a hint about where would |
@kumasento |
Thanks! I am checking it now |
@vinx13 Thank you so much for your help and now I can avoid adding new attributes to If I'm on the right track, I will move on to implement some test cases for this PR. @tqchen @kevinthesun would you mind taking a look at this solution as well? Thanks |
@@ -133,12 +141,18 @@ def schedule_conv2d(attrs, outs, target): | |||
if groups == 1 and layout == "NHWC": | |||
return topi.generic.schedule_conv2d_nhwc(outs) | |||
if groups != 1: | |||
if layout == "NCHW": | |||
# collect in_channels to distinguish depthwise and group conv2d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I updated the logic to distinguish depthwise and group conv2d
topi/python/topi/x86/conv2d.py
Outdated
@@ -523,3 +523,15 @@ def traverse(op): | |||
|
|||
traverse(outs[0].op) | |||
return s | |||
|
|||
@autotvm.register_topi_compute(nn.group_conv2d_nchw, 'cpu', 'direct') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this is where the registration happens.
op = _find_conv2d_op(outs[0].op) | ||
assert op is not None | ||
|
||
is_depthwise = 'depthwise' in op.tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure whether it is a good way to go but it seems that checking whether depthwise
is within the tag
value is much easier and intuitive.
topi/python/topi/x86/conv2d.py
Outdated
@@ -27,7 +27,7 @@ | |||
from .. import generic, tag | |||
from .. import nn | |||
from ..util import get_const_tuple | |||
from ..nn.conv2d import conv2d, conv2d_NCHWc, \ | |||
from ..nn.conv2d import conv2d, conv2d_NCHWc, _group_conv2d_nchw, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd better not importing an internal function. I think in nn.py we don't need an extra internal function for group_conv2d_nchw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've removed this update since there is no need to register TOPI compute for group_covn2d_nchw now
Maybe it's worth adding a test case to verify the correct schedules are fetched for different kind of conv2d? |
python/tvm/relay/op/nn/_nn.py
Outdated
if layout == "NHWC" and kernel_layout == "HWOI": | ||
return topi.generic.schedule_depthwise_conv2d_nhwc(outs) | ||
else: | ||
if layout == "NCHW": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
layout in ['NCHW', 'NCHW4c']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just updated
topi/python/topi/x86/conv2d.py
Outdated
@@ -523,3 +523,15 @@ def traverse(op): | |||
|
|||
traverse(outs[0].op) | |||
return s | |||
|
|||
@autotvm.register_topi_compute(nn.group_conv2d_nchw, 'cpu', 'direct') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to register this as autotvm template since you are using depthwise tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. I've just removed it.
That would be great. I'm still looking for the correct file for adding such test under |
@vinx13 Sure, I have done adding assertions in the latest commit. But the second problem persists. I've dug into the error and noticed that
You may also notice that in the CI error message. Should I alter the shape of the tensor returned from |
@kumasento group_conv in NCHWc layout on cuda is not intended to be used diredctly. The autotvm registration is incorrect. Currently group_conv2d on CUDA have only
Since we don't have a |
I think it might due to UPDATE: I just noticed your comment :) Yes, I agree with that |
Yes, it is NCHW4c for int8 dtype. It's expected to be called by AlterOpLayout pass |
Removed 'direct' CUDA tests
tests/python/relay/test_op_level2.py
Outdated
padding=(0, 1), channels=10, kernel_size=(1 ,3)) | ||
# mixed precision group conv2d | ||
# NOTE(kumasento): This test cannot pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to schedule a group_conv2d_NCHW4c_int8
command here but this test failed. Needs some further investigation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kumasento By default we use direct
schedule, so this test won't pass on CUDA. I would suggest disabling CUDA target for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I will just remove these commented lines of tests.
@vinx13 would you mind having another round of reviewing? Thanks! |
topi/python/topi/nn/conv2d.py
Outdated
@@ -575,6 +575,11 @@ def group_conv2d_nchw(Input, Filter, stride, padding, dilation, groups, out_dtyp | |||
else: | |||
dilation_h, dilation_w = dilation | |||
|
|||
if Input.dtype == 'int8': | |||
tag = 'group_conv2d_NCHWc_int8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is generic compute function that can handle any dtype and should not be tagged as NCHWc
. There is another implementation optimized for int8 for CUDA backend.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I've just removed that. Thanks for pointing it out.
Will leave the PR management to @vinx13 |
thanks @kumasento @kevinthesun @tqchen this is merged |
* Fixed issue apache#3069 by adding in_channels * Registerd group_conv2d_nchw as topi compute * Improved by checking tag value * Removed group_conv2d_nchw topi registration * Added test for relay group_conv2d_nchw * Added assertions to forbid small group size * Removed hard-coded oc_block_factor * Added explanatory comments to group_conv2d_nchw_cuda * Updated group_conv2d_nchw_cuda schedule Removed 'direct' CUDA tests * Reverted an accidental change in a conv2d test * Fixed indentation problems * Fixed a mis-commented line * Reverted change in group_conv2d_nchw tag * Removed commented int8 group_conv2d test * Fixed group size assertions in group_conv2d_nchw_cuda
* Fixed issue apache#3069 by adding in_channels * Registerd group_conv2d_nchw as topi compute * Improved by checking tag value * Removed group_conv2d_nchw topi registration * Added test for relay group_conv2d_nchw * Added assertions to forbid small group size * Removed hard-coded oc_block_factor * Added explanatory comments to group_conv2d_nchw_cuda * Updated group_conv2d_nchw_cuda schedule Removed 'direct' CUDA tests * Reverted an accidental change in a conv2d test * Fixed indentation problems * Fixed a mis-commented line * Reverted change in group_conv2d_nchw tag * Removed commented int8 group_conv2d test * Fixed group size assertions in group_conv2d_nchw_cuda
This PR intends to fix issue #3069.
Changes:
in_channels
to theConv2DAttrs
interface, as well as theconv2d
make function.depthwise
orgroup
conv2d.Please do not hesitate to let me know what can be improved.
@tqchen @Huyuwei @vinx13 any review from you will be very helpful, thanks!