max_norm_perturbation kwarg#1173
Merged
Merged
Conversation
Collaborator
|
thanks, I'll take a look today |
sunxd3
reviewed
May 15, 2026
Member
Author
|
thanks for the reviews @sunxd3! I have tried addressing all of them. |
sunxd3
reviewed
May 15, 2026
sunxd3
reviewed
May 18, 2026
Collaborator
sunxd3
left a comment
There was a problem hiding this comment.
for test_frule_correctness now x is normalized, which I think is still correct, but a behavior change, could you write about this change in the PR description?
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- max_fd_step::Union{Nothing,Float64} -> Union{Nothing,Real}
- docstring spells out per-argument normalisation and the 1e-6 effective floor
- ArgumentError now names the floor explicitly
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.
closes #765
This PR adds a
max_fd_stepkeyword argument to test_rule,test_frule_correctness, andtest_rrule_correctness. When provided, only finite-difference step sizesε ≤ max_fd_stepare used. This is useful for functions defined on a restricted domain (e.g.log,sqrt,cholesky) where large perturbations would step outside it.Behaviour change: tangent normalisation in
test_frule_correctnesstest_frule_correctnessnow normalises the tangent direction before running finite differences:ẋ = map(normalize_tangent ∘ tangent, x_ẋ)Previously the raw tangent from x_ẋ was used directly. With normalisation, ẋ has unit norm, so
max_fd_stepdirectly controls the step size in input space (rather than a step scaled by the tangent magnitude). The correctness check is unaffected, theFDestimate and theADresult are both linear inẋ, so scalingẋscales both by the same factor.test_rrule_correctnessalready normalised its tangent direction; this makestest_frule_correctnessconsistent with it.CI Summary — GitHub Actions
Documentation Preview
Mooncake.jl documentation for PR #1173 is available at:
https://chalk-lab.github.io/Mooncake.jl/previews/PR1173/
Performance
Performance Ratio:
Ratio of time to compute gradient and time to compute function.
Warning: results are very approximate! See here for more context.