Skip to content

OptimizationGradientError #2537

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

Closed
wants to merge 3 commits into from

Conversation

jduerholt
Copy link
Collaborator

Motivation

I am currently experimenting with some custom kernels, which exhibit some numeric instabilities, which lead in some situations during optimization to NaNs in the gradient. To better examine these situations, I thought it could be nice if the error which is thrown in this situation also contains the current x which leads to the NaNs in the gradient. For this purpose, I implemented an OptimizationGradientError like the OptimizationTimeoutError which holds the current x.

Im also thinking about catching the error in timeout.py as the OptimizationTimeoutError, throwing a warning and returning a result of the optimization. What do you think about this? I think this could be a useful and elegant way of dealing with it.

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

Unit tests.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Sep 14, 2024
Copy link
Contributor

@Balandat Balandat 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 putting this up - this makes sense to me.

Im also thinking about catching the error in timeout.py as the OptimizationTimeoutError, throwing a warning and returning a result of the optimization. What do you think about this? I think this could be a useful and elegant way of dealing with it.

Yeah I think this generally make sense. One issue with warnings is that they're often overlooked or ignored - so I wouldn't want to change the default behavior that something that would previously throw an error would now just return a result. But maybe it could be gated by some raise_on_nan flag?

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.98%. Comparing base (c895a8d) to head (81fbc3a).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2537   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files         193      193           
  Lines       17000    17005    +5     
=======================================
+ Hits        16998    17003    +5     
  Misses          2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@facebook-github-bot
Copy link
Contributor

@Balandat has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Member

@esantorella esantorella left a comment

Choose a reason for hiding this comment

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

Thanks! I'm all for making it easier to debug optimization errors :)

@jduerholt
Copy link
Collaborator Author

I think it is also fine as it is now, advanced users can now catch the error and see which is the x that creates the NaNs and further inspect them. From my side, no urgent need to further catch in minimize_with_timeout, based on an argument to the function. Maybe, I add this in a seperate PR, but from my side, this is good to go now. Thanks for the quick review!

@facebook-github-bot
Copy link
Contributor

@Balandat merged this pull request in 974fa26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants