Note that it’s not necessary to derive from nn.Module to write your functions, and everything can be handled with normal python functions, and backpropagation will just work fine (if you pass in a Variable).