Redefines value_and_pullback_function to return a value and a pullback function#35
Redefines value_and_pullback_function to return a value and a pullback function#35sethaxen wants to merge 5 commits intoJuliaDiff:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #35 +/- ##
==========================================
- Coverage 80.05% 79.04% -1.01%
==========================================
Files 2 2
Lines 396 377 -19
==========================================
- Hits 317 298 -19
Misses 79 79
Continue to review full report at Codecov.
|
|
@mohamed82008 in #36 (comment)
I'm not sure I understand what you mean. julia> using ForwardDiff, AbstractDifferentiation
julia> struct ForwardDiffBackend1 <: AD.AbstractForwardMode end
julia> AD.primal_value(::ForwardDiffBackend1, ::Any, f, xs) = ForwardDiff.value.(f(xs...))
julia> AD.@primitive function jacobian(ab::ForwardDiffBackend1, f, xs)
if xs isa Number
return (ForwardDiff.derivative(f, xs),)
elseif xs isa AbstractArray
out = f(xs)
if out isa Number
return (adjoint(ForwardDiff.gradient(f, xs)),)
else
return (ForwardDiff.jacobian(f, xs),)
end
elseif xs isa Tuple
error(typeof(xs))
else
error(typeof(xs))
end
end
julia> ba = ForwardDiffBackend1();
julia> val, back = AD.value_and_pullback_function(ba, identity, randn(10))
([0.05771077577524417, -0.6046897384683757, -0.43893636554383, 1.008345527744184, -1.3448119234793194, 0.0541982394477022, 0.2593213719269091, 1.6426658474014317, 0.651265342373578, -0.795563384561261], AbstractDifferentiation.var"#21#23"{ForwardDiffBackend1, typeof(identity), Tuple{Vector{Float64}}}(ForwardDiffBackend1(), identity, ([0.05771077577524417, -0.6046897384683757, -0.43893636554383, 1.008345527744184, -1.3448119234793194, 0.0541982394477022, 0.2593213719269091, 1.6426658474014317, 0.651265342373578, -0.795563384561261],)))
julia> back(randn(10))
([-1.2729554614899294, 0.1378713003865544, 0.2690893343964529, 0.9206297829092358, -1.3913076264330144, 0.4862468894828594, -1.1728445800434935, 0.6753224021990761, 0.14583421961218776, 0.732158895744132],) |
|
This change would be very helpful for other PRs such as #93: #93 (comment) |
|
@devmotion should we close this one? |
|
Probably. We can always re-open if it is preferred over #93. |
* Define value_and_pullback_function as returning value * Update definition of Jacobian * Update tests * Update API definition * Increment minor version number * Make value_and_oullback_function the primitive * Define pullback_function in terms of value_and_pullback_function * Define value_and_pullback_function in tests * Increment version number * Use value_and_pb_function in CRC and Tracker extensions * Fix bug in Tracker backend * More updates * Fix end * Handle `nothing` * Fix test failures * Use named functions --------- Co-authored-by: Seth Axen <seth.axen@gmail.com> Co-authored-by: Guillaume Dalle <22795598+gdalle@users.noreply.github.com>
Fixes part of #4. It's a breaking change, but the version number is given a
-DEVsuffix, since we should also handle #34 before releasing. (EDIT: Ref #36)