controlled-text-generation icon indicating copy to clipboard operation
controlled-text-generation copied to clipboard

Is the gradient for Encoder doubled?

Open Clement25 opened this issue 4 years ago • 2 comments

I notice there are two backpropagations for the generator and encoder.

https://github.com/wiseodd/controlled-text-generation/blob/master/train_discriminator.py#L120-L122 https://github.com/wiseodd/controlled-text-generation/blob/master/train_discriminator.py#L130-L132

After the back-propagation of loss G, it runs zero_grad to clear all the grads of the generator in the auto-encoder. However, the encoder is also in the forward path, and its gradient preserves. Then it computes the encoder loss and back-propagate again. So the gradient of VAE loss is accumulated twice and the final value is doubled. Is my understanding correct here?

Clement25 avatar Nov 17 '20 14:11 Clement25

Hello ! Have you solved this problem?

Sry2016 avatar Feb 25 '21 12:02 Sry2016

You are right. So I think we should add """trainer_E.zero_grad()“”“ here but without trainer_E.step().

Sry2016 avatar Feb 25 '21 13:02 Sry2016