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

Convolution too slow for depthwise when input channels != output channels #347

Closed
dskhudia opened this issue Apr 9, 2020 · 6 comments
Closed

Comments

@dskhudia
Copy link
Contributor

dskhudia commented Apr 9, 2020

This is the root cause of https://discuss.pytorch.org/t/got-slow-speed-on-quantized-model-with-fbgemm-on-x86/74439

fbgemmConv takes the im2col route for such cases and it's too slow. Here are the results for a shape I benchmarked.

"N", "IC", "OC", "H", "W", "G", "kernel", "stride", "pad"
1, 128, 256, 32, 100, 128, 3, 1, 1

FP32 time: 3.55 ms
fbgemmConv time: 86.76ms

cc @jspark1105

@jspark1105
Copy link
Contributor

This is not technically depth-wise convolution because we have 2 output channels per group. We should see if this case should be handled by generalizing the depth-wise kernel or the group conv kernel.

@dskhudia
Copy link
Contributor Author

dskhudia commented Apr 9, 2020

PyTorch defines it as depthwise :-| https://pytorch.org/docs/stable/nn.html#conv2d

When groups == in_channels and out_channels == K * in_channels, where K is a positive integer, this operation is also termed in literature as depthwise convolution.

@jspark1105
Copy link
Contributor

I see. Let me see if we can generalize group conv kernel (first generalize it to support C_per_G != K_per_G and then C_per_G == 1 and K_per_G == 2).

@dskhudia
Copy link
Contributor Author

Would it be easier to add this to depthwise?

@dskhudia
Copy link
Contributor Author

Also if we end up modifying groupwise, we should go for K_per_G == N

@jspark1105
Copy link
Contributor

Yes just looked at groupwise again. I agree it will be easier to add this to depthwise.

jspark1105 added a commit to jspark1105/FBGEMM that referenced this issue Apr 13, 2020
Summary:
Pull Request resolved: pytorch#359

To fix pytorch#347

For review, the core change is in GenerateI8Depthwise.cc . The other changes are mostly updating the interface and tests.

Reviewed By: dskhudia

Differential Revision: D20984303

fbshipit-source-id: 9e28f8957bb325490f43120cc381d5b014dde6be
jspark1105 added a commit to jspark1105/FBGEMM that referenced this issue May 6, 2020
Summary:
Pull Request resolved: pytorch#359

To fix pytorch#347

For review, the core change is in GenerateI8Depthwise.cc . The other changes are mostly updating the interface and tests.

Reviewed By: dskhudia

Differential Revision: D20984303

fbshipit-source-id: 58c016ce33ca5e10051fd33d5b714c01e8d15e76
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 a pull request may close this issue.

2 participants