def mean_flat(tensor):
    """
    Take the mean over all non-batch dimensions.
    """
    return tensor.mean(dim=list(range(1, len(tensor.shape))))
Take the mean over all non-batch dimensions.
modules/diffusion/karras/karras_diffusion.py