import torch


def kl_loss(mu, log_var):
    """
        KL-Divergence = 0.5 * sum(1 + log(sigma^2) - mu^2 - sigma^2)
        mu: the mean from the latent vector
        log_var: log variance from the latent vector
    """
    kl_div = -0.5 * torch.sum(1 + log_var - mu.pow(2) - log_var.exp())
    return kl_div