you can write a new nn.module like this
class CustomConv(nn.module):
    def __init__(self):
        weights = nn.Parameter(torch.randn(3, 1))
    # initialize module

    def forward(self, input):
    # custom convolution here

and use it like this
conv = CustomConv()
features = conv(input)

and it will work with .backward()
but it will work like torch.nn.conv2d rather than torch.nn.functional.conv2d()
and you need to use nn.Parameter() for weights