You could simply sort the values:
x = torch.tensor([[1,2,3,4,0],
                  [1,2,3,0,0],
                  [1,2,0,0,0]])

print(x.sort(dim=1, descending=True).values)
> tensor([[4, 3, 2, 1, 0],
        [3, 2, 1, 0, 0],
        [2, 1, 0, 0, 0]])