You need to write a custom class which inherits from nn.Module and override the forward() function.
http://pytorch.org/docs/notes/extending.html#extending-torch-nn 3.1k
Example : http://pytorch.org/tutorials/beginner/pytorch_with_examples.html#pytorch-custom-nn-modules 2.2k