Repository navigation
feat(DI): add value_gradient_and_hvp and deprecate gradient_and_hvp - #1086
Merged
Merged
Conversation
Add `value_gradient_and_hvp(!)`, which returns `(y, grad, tg)` so that every second-order operator with a value returns the primal value. The deprecated `gradient_and_hvp(!)` now forward to the new operators. Backends that compute the value for free return it (reverse-over-forward, Mooncake, Symbolics, FastDifferentiation, GTPSA, Zygote, HyperHessians); forward-over-anything and reverse-over-reverse use one extra primal call. The legacy DIT engine now tests `value_gradient_and_hvp(!)`, including the primal value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gdalle
reviewed
Nov 6, 2026
gdalle
marked this pull request as ready for review
November 6, 2026 13:59
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1086 +/- ##
=======================================
Coverage 98.18% 98.18%
=======================================
Files 143 144 +1
Lines 8246 8265 +19
=======================================
+ Hits 8096 8115 +19
Misses 150 150
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Important
This PR was generated by a coding agent, please disregard it until @gdalle has reviewed it.
Summary
value_gradient_and_hvp(f, [prep,] backend, x, tx, [contexts...]) -> (y, grad, tg)andvalue_gradient_and_hvp!, so that every second-order operator with a value also returns the primal value (likevalue_gradient_and_hessianandvalue_derivative_and_second_derivative).gradient_and_hvp(!)are deprecated and forward to the new operators, with aBase.depwarn.value_and_gradient), Mooncake (value_and_hvp!!), Symbolics and FastDifferentiation (gradient preparation), GTPSA (value_gradient_and_hessian!), Zygote (forwards to ForwardDiff-over-Zygote), HyperHessians (hvp_gradient_value). Forward-over-anything and reverse-over-reverse use one extra primal call.value_gradient_and_hvp(!)instead of the deprecated functions, including the primal value. This keeps DIT's JET tests clear of the deprecation warning, and tests the new operator on every backend.This is also a prerequisite for an upcoming revamp of DIT scenarios, where every second-order operator with a value then returns the same orders
(y, grad, second-order).Tests
DifferentiationInterface/test/Core/Internals/deprecations.jl: the deprecated functions return the same results as the new ones and are flagged by@test_deprecated.-O1): 57266 tests.🤖 Generated with Claude Code
Model used: Claude Opus 5.5