You could create a custom nn.Module and execute the desired operation in its forward method.
The parameters and buffers (if available) can be created in the __init__. This tutorial 15 explains it in more detail.