Solved by ptrblck in post #2 
              
              
                If I understand the use case correctly, you are looking for a generic “reduction” method, which would take the desired reduction type as an argument? 
If so, then unfortunately PyTorch doesn’t provide this generic method. 
You could pass a reduction argument to the functional calls of some criteria,…