Solved by mario98 in post #2 
              
              
                Ah, I’m stupid. torch.max has an overload that does exactly this. In pytorch, both max and cmax are united in a single function.