import torch


def reduction_helper(data: torch.Tensor, reduction: str) -> torch.Tensor:
    """
    Helper to collapse data with different modes

    Args:
        data: data to collapse
        reduction: type of reduction. One of `mean`, `sum`, None

    Returns:
        Tensor: reduced data
    """
    if reduction == 'mean':
        return torch.mean(data)
    if reduction == 'none' or reduction is None:
        return data
    if reduction == 'sum':
        return torch.sum(data)
    raise AttributeError('Reduction parameter unknown.')