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

Always copy the final point found by scipy #2047

Merged
merged 3 commits into from
Mar 12, 2023
Merged

Conversation

khurram-ghani
Copy link
Collaborator

PR type: bugfix

Summary

We have observed some instability during model training, where occasionally the SGPR model loss is unexpectadly very poor. We have tracked the problem down to how the gpflow wrapper calls the scipy optimiser (using BFGS in our case).

The wrapper uses tf.Variables for the model hyperparameters and these are updated on every evaluation of the training loss. On those occasions where the BFGS line-search fails for an iteration, the scipy optimiser returns the previous good point that it found and sets appropriate flags in the OptimizeResult class. However, the model hyperparameters will have the value of the last evaluation of the failed line-search, which can be quite poor. One solution is for the caller to look at the returned result, realise that there was a fail and copy over the final point from OptimizeResult back to the model hyperparameters. However it's perhaps better for the wrapper to always copy the final scipy optimiser point to the model just before returning.

Proposed changes

  • ...
  • ...
  • ...

What alternatives have you considered?

Minimal working example

# Put your example code in here

Release notes

Fully backwards compatible: yes / no

If not, why is it worth breaking backwards compatibility:

PR checklist

  • New features: code is well-documented
    • detailed docstrings (API documentation)
    • notebook examples (usage demonstration)
  • The bug case / new feature is covered by unit tests
  • Code has type annotations
  • Build checks
    • I ran the black isort formatter (make format)
    • I locally tested that the tests pass (make check-all)
  • Release management
    • RELEASE.md updated with entry for this change
    • New contributors: I've added myself to CONTRIBUTORS.md

@awav
Copy link
Member

awav commented Mar 10, 2023

Why is that a draft? Suggestion: remove the option from the minimize. The only meaningful final values for variables is the last successful iteration of the optimizer!

gpflow/optimizers/scipy.py Outdated Show resolved Hide resolved
@awav awav marked this pull request as ready for review March 12, 2023 13:11
@codecov
Copy link

codecov bot commented Mar 12, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (db2b42e) 98.01% compared to head (b3b335c) 98.01%.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #2047    /-   ##
========================================
  Coverage    98.01%   98.01%           
========================================
  Files           96       96           
  Lines         5401     5404     3     
========================================
  Hits          5294     5297     3     
  Misses         107      107           
Impacted Files Coverage Δ
gpflow/optimizers/scipy.py 97.14% <100.00%> ( 0.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@awav awav merged commit 5ea4f5c into develop Mar 12, 2023
@awav awav deleted the khurram/scipy_copy_final_pt branch March 12, 2023 17:58
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.

3 participants