-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Relay][Frontend][BugFix] Fixed relay grouped convolution selection #3020
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
Conversation
|
@Wheest ,
|
| groups = attrs.groups | ||
| layout = attrs.data_layout | ||
| kernel_layout = attrs.kernel_layout | ||
| channels = attrs.channels #TODO should be input channels |
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.
it is not safe to use attrs.channels since this attr is optinoal
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.
In that case, the in_channels needs to be exposed to the function. Either by being added to the attrs (defined at nn.h:51), or passing it as an extra argument (such as the tinfo suggestion) by every caller of it in the codebase.
Would there ever be any cases when the in_channels would be indeterminate when this function is called?
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.
in_channels should be available from the shape of input / weight after type infer
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.
@Wheest As suggested in #3070 (comment), you can get input channels via outs[0].op.attrs["workload"]. Can you check if this work for you?
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 for the insight @vinx13, I would never have groked all of the info that outs stores. I can confirm that setting in_channels = outs[0].op.attrs['workload'][1][1] works for groups==1 and groups==in_channels. However, interestingly when 1<groups<in_channels, it seems that outs[0].op.attrs.items is empty. This suggests that whatever calls schedule_conv2d does not set outs[0].op.attrs.items correctly when using grouped convolutions. Am investigating why.
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.
Hi @Wheest, I did notice such circumstances in my PR. Please let me know if you have any new discovery :)
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.
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.
@vinx13 You might be correct - depthwise_conv2d_nchw has been properly registered while group_conv2d_nchw has not. I'm working on fixing that
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'll hold until then. Why would autotvm templates be used in this workflow? I thought that the process is:
- Define model in using high level Relay API (with the bug in this PR happening here).
- Generate model description in Relay IR
- Compile model to chosen backend.
As I understand it, you might use autotvm at step 3. to tune and optimise the program. But I thought of it a "separate tool" in the tvm suite, not used in step 1 or 2.
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.
Actually we only need extra attributes when calling schedule. One way is to add attributes needed in topi compute. Autotvm already did this, but we can also register them manually. For the group conv case, we can add an attribute when calling tvm.compute
|
Have tried using the OpenCL backend with grouped convolutions, using the example in the notebook gist. However, this backend only works with This happens after the Relay schedule phase, though I'm still tracing what is going wrong. Pointers from codebase aficionado appreciated. |
I was experiencing an error, where grouped convolution didn't work for
groups!=num_input_channels.It turns out that in
python/tvm/relay/op/nn/_nn.py, ifgroups!=1, then depthwise convolution is used. This is incorrect, since a depthwise convolution isgroups==input_channels.This pull request attempts to fix the issue.
However, note that the
attrsobject does not have a property forinput_channels, onlyoutput_channels. The latter is what the fix uses. This does not affect correctness in the current implementation, since depthwise convolution always hasinput_channels==output_channels.However, if depthwise convolution has a
depth_multiplierparameter, whereNfilters are applied to each input channel, then the current bug fix would not be correct. As it stands, depth multiplied depthwise convolutions do not seem to be implemented right now.This Jupyter notebook demonstrates the problem that the PR fixes.