sorry, I do not consider the gradients.
>>> import torch
>>> mytensor = torch.tensor([[-11, 0, 101, 0], [0, 5, 50, 0], [-1, -2, 0, 1]])
>>> mask = mytensor.eq(0.)
>>> mytensor_sum = mytensor.sum(1)
>>> mytensor_sum = mytensor_sum.unsqueeze(1)
>>> other = mytensor_sum.repeat(1, 4)
>>> other
tensor([[ 90,  90,  90,  90],
        [ 55,  55,  55,  55],
        [ -2,  -2,  -2,  -2]])
>>> final = torch.where(mask, other, mytensor)
>>> final
tensor([[ -11,   90,  101,   90],
        [  55,    5,   50,   55],
        [  -1,   -2,   -2,    1]])
>>> fianl.max(1)
(tensor([ 101,   55,    1]), tensor([ 2,  0,  3]))
>>> final.min(1)
(tensor([-11,   5,  -2]), tensor([ 0,  1,  1]))

I believe that others will have a simpler approach.