Skip to content

Fix Matern Grads #478

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

Merged
merged 4 commits into from
Oct 3, 2022
Merged

Fix Matern Grads #478

merged 4 commits into from
Oct 3, 2022

Conversation

willtebbutt
Copy link
Member

Summary

We've been seeing test failures for AD with the MaternKernel. This fixes these.

Proposed changes

Modifies the implementation of the kappa function for the MaternKernel to utilise if ... else ... end instead of ifelse. The reason that this fixes the problem is that, if iszero(d), the branch which calls the bessel function etc (rather that the one that just returns 1) has some NaNs and some Infs floating around in it.
The ifelse branch evaluates this branch-with-NaNs, and when Zygote is performing the reverse pass, this NaN somehow gets propagated backwards.
Conversely, if ... else ... end entirely avoids computing any NaNs, thereby avoiding the problem.

This has the potential downside of yielding worse performance under Zygote, the MaternKernel performance was already quite bad, so I don't view this as a problem (it might not even make it much worse tbh).

What alternatives have you considered?

The solution that's defnitely going to work + be performant here would be a custom rule, but I don't have the time, and I don't know that this can be improved without sorting out the besselk rrule anyway.

Breaking changes

Not breaking.

@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Base: 68.87% // Head: 93.72% // Increases project coverage by +24.85% 🎉

Coverage data is based on head (43748e5) compared to base (ba7b37c).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #478       +/-   ##
===========================================
+ Coverage   68.87%   93.72%   +24.85%     
===========================================
  Files          52       52               
  Lines        1346     1354        +8     
===========================================
+ Hits          927     1269      +342     
+ Misses        419       85      -334     
Impacted Files Coverage Δ
src/basekernels/matern.jl 100.00% <100.00%> (+75.00%) ⬆️
src/utils.jl 91.46% <0.00%> (+3.65%) ⬆️
src/kernels/transformedkernel.jl 72.72% <0.00%> (+6.06%) ⬆️
src/chainrules.jl 87.65% <0.00%> (+18.51%) ⬆️
src/basekernels/periodic.jl 100.00% <0.00%> (+44.44%) ⬆️
src/basekernels/exponential.jl 100.00% <0.00%> (+50.00%) ⬆️
src/basekernels/polynomial.jl 100.00% <0.00%> (+57.89%) ⬆️
src/basekernels/fbm.jl 100.00% <0.00%> (+73.33%) ⬆️
src/basekernels/exponentiated.jl 80.00% <0.00%> (+80.00%) ⬆️
... and 8 more

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 at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@willtebbutt
Copy link
Member Author

Codecov is taking a little while to update. This is ready for review.

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Looks good to me, I just think it would be good to add a test for it that fails on the master branch.

@willtebbutt
Copy link
Member Author

Looks good to me, I just think it would be good to add a test for it that fails on the master branch.

Well I implemented this change to fix a test on master, so is it not sufficient that CI now passes?

Copy link
Member

@devmotion devmotion left a comment

Choose a reason for hiding this comment

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

Ah I didn't realize that 😄 Somehow I thought you ran into issues in some external example. If it fixes CI on master that's sufficient, of course 👍

@willtebbutt willtebbutt merged commit d425983 into master Oct 3, 2022
@willtebbutt willtebbutt deleted the wct/fix-matern-grads branch October 3, 2022 13:16
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.

2 participants