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
cuDNN v6 dilated convolution #2858
Conversation
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.
Thank you for PR! I put comments, so could you check them?
@@ -33,7 +33,7 @@ def _pair(x): | |||
|
|||
class Convolution2DFunction(function.Function): | |||
|
|||
def __init__(self, stride=1, pad=0, cover_all=False, **kwargs): | |||
def __init__(self, stride=1, pad=0, cover_all=False, dilate=1, **kwargs): |
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 seems you put dilate
option in Convolution2DFunction
, but it is not supported in CPU mode. This is misleading for users. Further, if Convolution2DFunction
supports dilation feature fully, then DilatedConvolution2DFunction
will become the subset of it. This means we will have some sort of overlapping codes. I think there are two ways to fix this.
- Do not modify
Convolution2DFunction
(i.e., do not putdilate
option here) and modify only the dilated function. - Complete to implement
dilate
argument (i.e., implement dilation in CPU mode) and make the current dilated function just callsConvolution2DFunction
internally.
How do you think about this?
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.
(Please look at my comment below)
assert out_w > 0, 'Width in the output should be positive.' | ||
|
||
y = cuda.cupy.empty((n, out_c, out_h, out_w), dtype=x.dtype) | ||
# print('# conv_2d.py:120, y.shape: {}'.format(y.shape)) # debug |
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.
Please remove debug message.
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.
Noted, will remove it.
@@ -101,7 +101,8 @@ class Convolution2D(link.Link): | |||
""" # NOQA | |||
|
|||
def __init__(self, in_channels, out_channels, ksize=None, stride=1, pad=0, | |||
nobias=False, initialW=None, initial_bias=None, **kwargs): | |||
dilate=1, nobias=False, initialW=None, initial_bias=None, |
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.
Similar problem holds for the link.
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.
(Please look at my comment below)
Thank you for the feedback.
I was not sure which was better when I sent the PR, but now I think the option two would be better mainly because:
What would you think? |
Thank you for your opinion. Now I discussed with chainer core developers about this since merge is a little big change. They and I consider merging two similar functions is a good contribution, but it is somehow different from the objective in this PR. So, I recommend you to do (1) implementing cuDNN v6 dilated conv and (2) merging the two functions in separate PRs. I guess you may do either one ((1) or (2)) at first. If you feel making two PRs is troublesome, however, doing the two things in one PR is probably admissible. |
Thank you for the comment. I agree your comment that it is not a small change to make two functions together. So, I will focus mainly on implementing dilated convolution feature in |
So, I assume we are working on only (1) in this PR. |
Thank you for the feedback. |
I've fixed |
Thank you for adding tests. My comments are:
|
@@ -61,6 +70,9 @@ def check_type_forward(self, in_types): | |||
) | |||
|
|||
def forward_cpu(self, inputs): | |||
if getattr(self, '_func', False): |
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.
Knowing that we will work on merging tasks (2) right after this PR, this part is unused in this PR as far as I could see. So, to avoid confusion, it might be better to remove this part in this PR. How do you think about this? The same thing holds for backward_cpu
.
Thank you for the comment. I've updated the branch based on your comment:
Note that I've not added a BTW, no failure has been observed so far when running nosetests with cuDNN 5.1 and 6.0. |
@@ -388,6 +398,8 @@ def convolution_2d(x, W, b=None, stride=1, pad=0, cover_all=False, **kwargs): | |||
``pad=p`` and ``pad=(p, p)`` are equivalent. | |||
cover_all (bool): If ``True``, all spatial locations are convoluted | |||
into some output pixels. | |||
dilate (int or pair of ints): Dilation factor of filter applications. | |||
``dilate=d`` and ``dilate=(d, d)`` are equivalent. |
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.
How about putting a reference to DilatedConvolution2DFunction
class? I guess dilated convolution is not familiar with beginners.
Thank you. Now the code looks good to me. I put one minor comment. |
@anaruse Cloud you resolve conflicts? |
57a868c
to
55530a4
Compare
Conflicts: chainer/functions/connection/convolution_2d.py chainer/functions/connection/deconvolution_2d.py tests/chainer_tests/functions_tests/connection_tests/test_dilated_convolution_2d.py
jenkins, test this please. |
I got error on CUDA v5 environment. |
Thank you for pointing it out. it was fixed. |
jenkins, test this please. |
Please merge or rebase master, and fix |
Conflicts: chainer/utils/conv.py
Thanks for your comment. The conflict was resolved. |
jenkins, test this please. |
I got following error. Please fix test of dilated conv.
|
Could you tell me CUDA version, cuDNN version, etc. when that error occurred? |
I got error on CUDA7/cuDNN4 and CUDA8/cuDNN51. |
Please run the test again. I think the error is already resolved by the last commit. I've confirmed the error above does not happen with CUDA8 and cuDNN 5.1. |
jenkins, test this please. |
LGTM! |
This PR is related to dilated convolution (#2693) and enabling Chainer to use an implementation of dilated convolution in cuDNN v6. Note that you need to use this branch of Cupy (cupy/cupy#133).