Function for getting convolution gradients from layer gradients

I’m working with a learning rule that doesn’t operate well with autograd. Given that I have gradients for the output of a convolutional layer, is there a function in pytorch that allows for me to compute the gradients of the weights of a convolutional layer given the inputs and the gradients at the output?

As a simple example, say I have a 4x4 matrix going through a 2x2 convolution with stride 1, padding 0. The output would be a 3x3 matrix, thus the gradients at the output would be a 3x3 matrix. Is there a function I can use (avoiding autograd) that can take this 3x3 matrix and the inputs, and give the gradients for the 2x2 weights of the convolution?