-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AutoSparse should only support Jacobians and Hessians (#277)
* AutoSparse only does Jacobians and Hessians * Use dense backend explicitly * Re-export checks * Typo * Fix scenarios * Fix tests * Type stab * Types * Zygote on GPU * Sparsity on 1.6 * Typo * Typo * Doc
- Loading branch information
Showing
25 changed files
with
271 additions
and
240 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,5 @@ | ||
## Traits | ||
|
||
for trait in ( | ||
:check_available, | ||
:twoarg_support, | ||
:pushforward_performance, | ||
:pullback_performance, | ||
:hvp_mode, | ||
) | ||
@eval $trait(backend::AutoSparse) = $trait(dense_ad(backend)) | ||
end | ||
|
||
## Operators | ||
|
||
for op in (:pushforward, :pullback, :hvp) | ||
op! = Symbol(op, "!") | ||
valop = Symbol("value_and_", op) | ||
valop! = Symbol("value_and_", op, "!") | ||
prep = Symbol("prepare_", op) | ||
prepsame = Symbol("prepare_", op, "_same_point") | ||
E = if op == :pushforward | ||
:PushforwardExtras | ||
elseif op == :pullback | ||
:PullbackExtras | ||
elseif op == :hvp | ||
:HVPExtras | ||
end | ||
|
||
## One argument | ||
@eval begin | ||
$prep(f::F, ba::AutoSparse, x, v) where {F} = $prep(f, dense_ad(ba), x, v) | ||
$prepsame(f::F, ba::AutoSparse, x, v) where {F} = $prepsame(f, dense_ad(ba), x, v) | ||
$prepsame(f::F, ba::AutoSparse, x, v, ex::$E) where {F} = | ||
$prepsame(f, dense_ad(ba), x, v, ex) | ||
$op(f::F, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = | ||
$op(f, dense_ad(ba), x, v, ex) | ||
$valop(f::F, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = | ||
$valop(f, dense_ad(ba), x, v, ex) | ||
$op!(f::F, res, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = | ||
$op!(f, res, dense_ad(ba), x, v, ex) | ||
$valop!(f::F, res, ba::AutoSparse, x, v, ex::$E=$prep(f, ba, x, v)) where {F} = | ||
$valop!(f, res, dense_ad(ba), x, v, ex) | ||
end | ||
|
||
## Two arguments | ||
@eval begin | ||
$prep(f!::F, y, ba::AutoSparse, x, v) where {F} = $prep(f!, y, dense_ad(ba), x, v) | ||
$prepsame(f!::F, y, ba::AutoSparse, x, v) where {F} = | ||
$prepsame(f!, y, dense_ad(ba), x, v) | ||
$prepsame(f!::F, y, ba::AutoSparse, x, v, ex::$E) where {F} = | ||
$prepsame(f!, y, dense_ad(ba), x, v, ex) | ||
$op(f!::F, y, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = | ||
$op(f!, y, dense_ad(ba), x, v, ex) | ||
$valop(f!::F, y, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = | ||
$valop(f!, y, dense_ad(ba), x, v, ex) | ||
$op!(f!::F, y, res, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v)) where {F} = | ||
$op!(f!, y, res, dense_ad(ba), x, v, ex) | ||
$valop!( | ||
f!::F, y, res, ba::AutoSparse, x, v, ex::$E=$prep(f!, y, ba, x, v) | ||
) where {F} = $valop!(f!, y, res, dense_ad(ba), x, v, ex) | ||
end | ||
end | ||
|
||
for op in (:derivative, :gradient, :second_derivative) | ||
op! = Symbol(op, "!") | ||
valop = Symbol("value_and_", op) | ||
valop! = Symbol("value_and_", op, "!") | ||
prep = Symbol("prepare_", op) | ||
E = if op == :derivative | ||
:DerivativeExtras | ||
elseif op == :gradient | ||
:GradientExtras | ||
elseif op == :second_derivative | ||
:SecondDerivativeExtras | ||
end | ||
|
||
## One argument | ||
@eval begin | ||
$prep(f::F, ba::AutoSparse, x) where {F} = $prep(f, dense_ad(ba), x) | ||
$op(f::F, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = | ||
$op(f, dense_ad(ba), x, ex) | ||
$valop(f::F, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = | ||
$valop(f, dense_ad(ba), x, ex) | ||
$op!(f::F, res, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = | ||
$op!(f, res, dense_ad(ba), x, ex) | ||
$valop!(f::F, res, ba::AutoSparse, x, ex::$E=$prep(f, ba, x)) where {F} = | ||
$valop!(f, res, dense_ad(ba), x, ex) | ||
end | ||
|
||
## Two arguments | ||
if op in (:derivative,) | ||
@eval begin | ||
$prep(f!::F, y, ba::AutoSparse, x) where {F} = $prep(f!, y, dense_ad(ba), x) | ||
$op(f!::F, y, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = | ||
$op(f!, y, dense_ad(ba), x, ex) | ||
$valop(f!::F, y, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = | ||
$valop(f!, y, dense_ad(ba), x, ex) | ||
$op!(f!::F, y, res, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x)) where {F} = | ||
$op!(f!, y, res, dense_ad(ba), x, ex) | ||
$valop!( | ||
f!::F, y, res, ba::AutoSparse, x, ex::$E=$prep(f!, y, ba, x) | ||
) where {F} = $valop!(f!, y, res, dense_ad(ba), x, ex) | ||
end | ||
end | ||
end | ||
check_available(backend::AutoSparse) = check_available(dense_ad(backend)) | ||
twoarg_support(backend::AutoSparse) = twoarg_support(dense_ad(backend)) | ||
pushforward_performance(backend::AutoSparse) = pushforward_performance(dense_ad(backend)) | ||
pullback_performance(backend::AutoSparse) = pullback_performance(dense_ad(backend)) | ||
hvp_mode(backend::AutoSparse{<:SecondOrder}) = hvp_mode(dense_ad(backend)) |
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
Oops, something went wrong.