import torch


def reduce_loss(loss: torch.Tensor, reduction: str = "mean") -> torch.Tensor:
    """
    :param loss: loss tensor
    :param reduction: mean, sum, or none
    """
    if reduction == "mean":
        loss = loss.mean()
    elif reduction == "sum":
        loss = loss.sum()
    elif reduction == "none":
        pass
    else:
        raise NotImplementedError
    return loss