In that case, you should be able to try this!
X = torch.randn(B,3,240,320)
norm = X.pow(2).sum(dim=1).sqrt()
Xnorm = X/norm

The L2-norm (or Euclidean norm) is just the square root of the sum of the squares, i.e. norm = sqrt(x^2 + y^2 + …). In your case, you just need to squared the Tensor (via .pow(2)) then sum along the dimension you wish to normalize (via .sum(dim=1)), then take the square root (via .sqrt() ). That calculates your normalization constant. Then just divide the original Tensor by that value and it should normalize your Tensor along that dimension!