Fix switch_optimizer callback#608
Merged
Merged
Conversation
GiovanniCanali
marked this pull request as ready for review
July 23, 2025 15:57
| if trainer.current_epoch == self._epoch_switch: | ||
| optims = [] | ||
|
|
||
| # Hook the new optimizers to the model parameters |
Collaborator
There was a problem hiding this comment.
Good catch! Maybe we could do a setter in the solver class? This way we will not forget in the future
Collaborator
Author
There was a problem hiding this comment.
Hi @dario-coscia,
Adding a setter in the solver class feels a bit redundant with configure_optimizers, in my opinion. It’s definitely a useful idea, but it might require more invasive changes.
Since we’re already planning to refactor the solver logic, we could revisit this at that time instead.
If that sounds good to you, I’d go ahead and merge this PR for now.
GiovanniCanali
force-pushed
the
fix_switch_optimizer
branch
from
July 25, 2025 11:39
e52bf88 to
adc9e2e
Compare
GiovanniCanali
force-pushed
the
fix_switch_optimizer
branch
from
July 25, 2025 11:56
adc9e2e to
9d4b051
Compare
dario-coscia
approved these changes
Jul 25, 2025
ndem0
approved these changes
Jul 25, 2025
Collaborator
|
@GiovanniCanali I think you can rebase and merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes #607
Issue summary, for reference: While
solver.optimizerwas successfully updated,trainer.strategy.optimizerswas not. As a result, PyTorch Lightning continued using the original optimizer during training, effectively ignoring the switch.Checklist