-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about the KL divergence loss #849
Comments
I found this material that does also have the loss on the form that is used here: https://pyimagesearch.com/2023/10/02/a-deep-dive-into-variational-autoencoders-with-pytorch/ My confusion just happen because most papers write: (From Bishops Deep learning) And the original implementation of VAE: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
I hope someone can help me understand why the KL is calculated as:
0.5 * torch.sum(torch.pow(self.mean, 2) + self.var - 1.0 - self.logvar, dim=[1, 2, 3])
In the DiagonalGaussianDistribution listed here:
stable-diffusion/ldm/modules/distributions/distributions.py
Line 44 in 21f890f
I am asking, because most loss functions for the VAE I can find use (-1 times this calculations) like this: 0.5 * torch.sum(-torch.pow(self.mean, 2) - self.var + 1.0 + self.logvar, dim=[1, 2, 3])
And I cannot see that we multiply by -1 in the contperceptual loss for instance:
https://github.com/CompVis/stable-diffusion/blob/21f890f9da3cfbeaba8e2ac3c425ee9e998d5229/ldm/modules/losses/contperceptual.py#L83C57-L83C65
Thank you very much in advance :)
The text was updated successfully, but these errors were encountered: