-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support second order for Enzyme, take 2 (#285)
* Add nested mechanism * Mode * Typo * Tests passing * Remove additional tests FD+Enzyme * Add printing * Remove printing * More code coverage * Fix Heisenbug * Fix Heisenbug * Debump
- Loading branch information
Showing
23 changed files
with
332 additions
and
181 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
27 changes: 17 additions & 10 deletions
27
DifferentiationInterface/ext/DifferentiationInterfaceEnzymeExt/forward_twoarg.jl
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
## Pushforward | ||
|
||
DI.prepare_pushforward(f!, y, ::AutoForwardOrNothingEnzyme, x, dx) = NoPushforwardExtras() | ||
function DI.prepare_pushforward(f!, y, ::AnyAutoEnzyme{<:Union{ForwardMode,Nothing}}, x, dx) | ||
return NoPushforwardExtras() | ||
end | ||
|
||
function DI.value_and_pushforward( | ||
f!, y, backend::AutoForwardOrNothingEnzyme, x, dx, ::NoPushforwardExtras | ||
f!, | ||
y, | ||
backend::AnyAutoEnzyme{<:Union{ForwardMode,Nothing}}, | ||
x, | ||
dx, | ||
::NoPushforwardExtras, | ||
) | ||
dx_sametype = convert(typeof(x), dx) | ||
dy_sametype = zero(y) | ||
autodiff( | ||
forward_mode(backend), | ||
Const(f!), | ||
Const, | ||
Duplicated(y, dy_sametype), | ||
Duplicated(x, dx_sametype), | ||
) | ||
dy_sametype = make_zero(y) | ||
y_and_dy = Duplicated(y, dy_sametype) | ||
x_and_dx = Duplicated(x, dx_sametype) | ||
if backend isa AutoDeferredEnzyme | ||
autodiff_deferred(forward_mode(backend), f!, Const, y_and_dy, x_and_dx) | ||
else | ||
autodiff(forward_mode(backend), Const(f!), Const, y_and_dy, x_and_dx) | ||
end | ||
return y, dy_sametype | ||
end |
Oops, something went wrong.