Skip to content
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

Loss and Backprop Details #23

Open
Malik7115 opened this issue Aug 11, 2022 · 3 comments
Open

Loss and Backprop Details #23

Malik7115 opened this issue Aug 11, 2022 · 3 comments

Comments

@Malik7115
Copy link

Hi,

During training the vqvae backprops on multiple losses. While inputting feature maps to the model, we are given a loss, shoud I manually backpropagate and update weights through (the good ol' loss.backward() and optimizer.step()) this or is it handled implicitly?

@lucidrains
Copy link
Owner

lucidrains commented Aug 11, 2022

@Malik7115 you have to sum that loss to your final loss (it is usually called an auxiliary loss, as it is auxiliary to the main objective), and then you call backwards on that

however, there are many papers that show you don't even need the auxiliary commitment loss for convergence. you can just set commitment_weight to 0 and it should learn just fine with the exponential moving average

@hassaanmuzammil
Copy link

so basically we put our image thru an encoder, pass it to the vq model and further pass the quantized to the decoder. At the end we calculate the reconstruction loss wrt input and output of decoder, add this loss to the loss given by the vq and call loss.backward()

in summary:

enc_out = encoder(images)
quantized, indices, loss = net(enc_out)
x_hat = decoder(quantized)
reconstruction_loss = mse(x_hat, images)
loss = loss + reconstruction_loss
loss.backward()

Do i understand this correctly?

@lucidrains
Copy link
Owner

@hassaanmuzammil yup, that is correct

you can check out a working example here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants