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

For multiple optimizers, model.toggle_optimizer() is setting the requires_grad=True for all the params. #5292

Closed
jain-anshul opened this issue Dec 29, 2020 · 3 comments · Fixed by #5574 or #5775
Assignees
Labels
priority: 1 Medium priority task
Milestone

Comments

@jain-anshul
Copy link

https://github.com/PyTorchLightning/pytorch-lightning/blob/dabfeca92e0702e55f09ac53e9412672cd258cd3/pytorch_lightning/core/lightning.py#L1152-L1170

Setup :
pytorch-lightning 1.1.2
pytorch 1.7.1

When using multiple optimizers, in the toggle_optimizers(..) function, the requires_grad property is set to true for all the params belonging to the param_groups of the optimizer. This is incorrect as in case the user has explicitly disabled the requires_grad property for some parameters permanently, the function would enable requires_grad for those parameters also.

Proposed fix:
The requires_grad value for all the parameters should be stored beforehand in an object variable self.params_dict of lightning object. In the toggle_optimizer() function, instead of setting params.requires_grad=True, set params.requires_grad = self.params_dict[params].This would set the correct value for the params of the concerned optimizer.

@github-actions
Copy link
Contributor

Hi! thanks for your contribution!, great first issue!

@jain-anshul
Copy link
Author

@williamFalcon @Borda Could you please look at this issue and help me in fixing it

@tchaton
Copy link
Contributor

tchaton commented Jan 19, 2021

Hey @jain-anshul,

It looks like an important bug. I will help you to solve it.

Best,
T.C

@tchaton tchaton self-assigned this Jan 19, 2021
@tchaton tchaton added the priority: 1 Medium priority task label Jan 19, 2021
@tchaton tchaton added this to the 1.1.x milestone Jan 19, 2021
@ananthsub ananthsub mentioned this issue Feb 4, 2021
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment