Hello,
Although I haven’t done this myself, I found several threads on the forum.
How to implement a custom convolutional layer and call it from your own network? - PyTorch Forums
Custom convolution layer - PyTorch Forums
I believe there is no better way than writing your own class, this class should be based on nn.Module.
Hope I have helped.