def get_output_attribute(out, attribute_name, cuda_device, reduction="sum"):
    """
    This function handles processing/reduction of output for both
    DataParallel or non-DataParallel situations.
    For the case of multiple GPUs, This function will
    sum all values for a certain output attribute in various batches
    together.

    Parameters
    ---------------------
    :param out: Dictionary, output of model during forward pass,
    :param attribute_name: str,
    :param cuda_device: list or int
    :param reduction: (string, optional) reduction to apply to the output. Default: 'sum'.
    """
    if isinstance(cuda_device, list):
        if reduction == "sum":
            return out[attribute_name].sum()
        elif reduction == "mean":
            return out[attribute_name].sum() / float(len(out[attribute_name]))
        else:
            raise ValueError("invalid reduction type argument")
    else:
        return out[attribute_name]