Solved by albanD in post #2 
              
              
                Yes you can do that. See more details in the doc. 
Be careful: 

You should not instantiate an instance of the Function. You should do loss = MyLoss.apply(output, label). If you prefer to instantiate an instance, you can simply create a new module like:

class MyLossMod(nn.Module):
    def forward(s…