Repository navigation
Refactor optimizer classes and add new scheduler - #551
Draft
felix-e-h-p wants to merge 1 commit into
Draft
felix-e-h-p wants to merge 1 commit into
felix-e-h-p wants to merge 1 commit into
Conversation
Refactor optimizer classes to improve parameter handling and add AdamWReduceLROnPlateau with enhanced learning rate management.
felix-e-h-p
commented
Oct 22, 2026
| params = [] | ||
| for c in children: | ||
| params += find_other_than_submodule_parameters(c, ignore_modules) | ||
| return params |
Contributor
Author
There was a problem hiding this comment.
Replaced with a simple loop over model.modules() further down.
felix-e-h-p
commented
Oct 22, 2026
| def __init__(self, lr: float = 0.0005, **opt_kwargs): | ||
| """Store the learning rate and any extra kwargs passed to the torch optimizer""" | ||
| self.lr = lr # overwritten by the LR finder via PVNetLightningModule | ||
| self.opt_kwargs = opt_kwargs |
Contributor
Author
There was a problem hiding this comment.
Adam and AdamW had identical __init__s, so moved that up here. Added a comment on self.lr because the Lightning module overwrites it when the LR finder runs, which wasn’t mentioned anywhere.
felix-e-h-p
commented
Oct 22, 2026
| def __call__(self, model: nn.Module): | ||
| """Return optimizer""" | ||
| return torch.optim.AdamW(model.parameters(), lr=self.lr, **self.kwargs) | ||
| return torch.optim.AdamW(model.parameters(), lr=self.lr, **self.opt_kwargs) |
Contributor
Author
There was a problem hiding this comment.
Same behaviour as before, they just inherit the init now.
felix-e-h-p
commented
Oct 22, 2026
| "optimizer": opt, | ||
| "lr_scheduler": {"scheduler": sch, "monitor": monitor}, | ||
| } | ||
| return {"optimizer": opt, "lr_scheduler": {"scheduler": sch, "monitor": monitor}} |
Contributor
Author
There was a problem hiding this comment.
The AdamW plus plateau scheduler plus monitor setup used to be copied in three places: once in EmbAdamWReduceLROnPlateau, and twice in this class (single lr and dict of lrs). Now written once here and just uses whatever _param_groups returns.
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.
The optimisers file has a lot of copy paste in it, so I’ve cleaned it up a bit. Gone from about 210 lines to about 110. All the class names and arguments are identical, so existing configs and saved models load as before.