Let me try to explain again.
I have a class that I wrote which performs convolution. Let’s call it custom_conv. It is an autograd.Function, so it has a forward and a backward method. In the backward method, it computes the weight gradient, bias gradient, and input gradient, and returns those values. Currently custom_conv is just performing standard convolution with nothing new added.
I want to validate that custom_conv is working correctly by comparing to the gradients computed by pytorch’s conv2d function. Since these should be return values of conv2d’s backward method, I’m hoping I can access them somehow.
In the code snippet above, I simply wanted to show that calling .backwards() does not return these values. I’ve added a few more comments that hopefully make that clearer. Is there an alternate way to add a hook to return these values?
You suggest using .parameters().  What should I call this on? torch.nn.functional.conv2d does not have a parameters method. Neither does the tensor it returns. Are you suggesting that I should be using a convolutional layer instead? Like torch.nn.Conv2d?