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

FIX Makes sure score is passed to ReduceLROnPlateau #738

Merged
merged 7 commits into from
Feb 7, 2021

Conversation

thomasjpfan
Copy link
Member

Closes #363

Copy link
Collaborator

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this. PR LGTM, just two minor comments.

CHANGES.md Outdated
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CLI helper function now also supports normal (i.e. non-skorch) sklearn estimators
- Disabling all callbacks is now supported (which allows reducing overhead,
which is especially relevant for small models).
- `LRScheduler` now currently passes the score/loss in the history to `ReduceLROnPlateau`. (#738)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I understand this sentence correctly, maybe change the wording?

score = np.inf
else:
score = net.history[-1, self.monitor]
score = net.history[-1, self.monitor]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think: We could catch the KeyError and augment the error message by telling the user that they may possibly need to change the order of callbacks if they reference a metric that was not yet computed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its a good idea. I updated the PR to include this nicer error message.

f"'{self.monitor}' was not found in history. A "
f"PassthroughScoring callback with name='{self.monitor}' "
"should be placed before the LRScheduler callback"
) from e

self.lr_scheduler_.step(score)
# ReduceLROnPlateau does not expose the current lr so it can't be recorded
Copy link

@jiajiexiao jiajiexiao Feb 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix in this PR, which I found while troubleshooting the same unexpected behavior as mentioned in the issue #363.

I noticed this comment but I guess how the learning rate was updated should be tracked in net.history even for ReduceLROnPlateau. As being discussed in https://discuss.pytorch.org/t/how-to-retrieve-learning-rate-from-reducelronplateau-scheduler/54234/3 and pytorch/pytorch#2829, I would suggest replacing the comment line 162 with the following:

            if self.event_name is not None:
                net.history.record(self.event_name, self.lr_scheduler_._last_lr[0])  # type: ignore

or

           if self.event_name is not None:
                net.history.record(self.event_name, self.lr_scheduler_.optimizer.param_groups[0]["lr"])  # type: ignore

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss this in another PR since this is a feature unrelated to the bug fix.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue (#739) so that we don't forget. @jiajiexiao does that reflect what you meant?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenjaminBossan BenjaminBossan merged commit aa99dbc into skorch-dev:master Feb 7, 2021
sthagen added a commit to sthagen/skorch-dev-skorch that referenced this pull request Feb 15, 2021
FIX Makes sure score is passed to ReduceLROnPlateau (skorch-dev#738)
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

Successfully merging this pull request may close these issues.

ReduceLRonPlateau does not work as expected
3 participants