A = torch.Tensor([ [ [0,0,0,0,0], [0,-0.4,0,-0.9,0], [0,-0.7,0.9,0.2,0], [0,0,0,0,0] ] ])
B = A[A.sum(dim=2) != 0]
tensor([[ 0.0000, -0.4000,  0.0000, -0.9000,  0.0000],
[ 0.0000, -0.7000,  0.9000,  0.2000,  0.0000]])