import torch


def normalize(x: torch.Tensor) -> torch.Tensor:
    """ Normalizes tensor for surface normals

   Shape:
        - X: :math:`(N, *)` where N is the batch size and * means, any number of additional dimensions ≥1
        - Output: :math:`(N, *)`, same size as the input

    """
    l2_norm = torch.clamp(torch.norm(x, dim=1, keepdim=True), min=1e-5)
    x = x / l2_norm
    return x