Solved by ptrblck in post #2 
              
              
                If your metric is stateless (i.e. you don’t want to store arguments or other parameters), then you could just define a method. Otherwise, a custom class derived from nn.Module could store some arguments e.g. reductions as an internal attribute. 
Also, have a look at this post I’ve written some time …