def _l2_regularization(l2, model):
    """Computes the L2 regularization for the given model

    Args:
        l2 (float): L2 parameter
        model (:obj:`torch.nn.Module`): Model to use

    Returns:
        float: L2 loss (i.e. (l2 * l2_norm(params)) / 2)
    """
    l2_loss = sum(param.norm(2) ** 2 for param in model.parameters())
    return l2 / 2 * l2_loss