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

About conv operation in HW4 #6

Open
DeliMm opened this issue May 26, 2024 · 1 comment
Open

About conv operation in HW4 #6

DeliMm opened this issue May 26, 2024 · 1 comment

Comments

@DeliMm
Copy link

DeliMm commented May 26, 2024

Maybe there is a mistake in the conv's gradient function with the following place

X_grad = conv(out_grad, W_permute, padding=K-1-self.padding)

I have a test case with :

  • A's shape: (1, 16, 16, 1)
  • B's shape: (7, 7, 1, 1)
  • stride=3 & padding=2

When I test the above case, there are some errors with

tests/hw4/test_conv.py::test_op_conv[backward-needle.backend_ndarray.ndarray_backend_cuda-Z_shape16-W_shape16-1-0]  
- ValueError: operands could not be broadcast together with shapes (1,16,16,1) (1,17,17,1)

This function may not have considered the situation of a large convolution kernel during implementation, especially when $(H - 2p + k) \pmod s \ne 0$.

May I ask if it‘s possible to check such case and carry out improvement/perfection? Thanks for your reply.

@Skylight-Lark
Copy link

Skylight-Lark commented Aug 5, 2024

Maybe there is a mistake in the conv's gradient function with the following place

X_grad = conv(out_grad, W_permute, padding=K-1-self.padding)

I have a test case with :

  • A's shape: (1, 16, 16, 1)
  • B's shape: (7, 7, 1, 1)
  • stride=3 & padding=2

When I test the above case, there are some errors with

tests/hw4/test_conv.py::test_op_conv[backward-needle.backend_ndarray.ndarray_backend_cuda-Z_shape16-W_shape16-1-0]  
- ValueError: operands could not be broadcast together with shapes (1,16,16,1) (1,17,17,1)

This function may not have considered the situation of a large convolution kernel during implementation, especially when (H−2p+k)(mods)≠0.

May I ask if it‘s possible to check such case and carry out improvement/perfection? Thanks for your reply.

@PKUFlyingPig @DeliMm
Hello! I think the caculation of OFM's size is wrong:

out_H, out_W = (H-K+1)//self.stride, (W-K+1)//self.stride

As the pytorch doc says:
https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d
The right size is:
(H + 2 * P - K) // self.stride + 1
So the caculation of conv gradient has also some problems, like X.grad conv padding

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

No branches or pull requests

2 participants