Comments (6)
Current work around (discussed on Slack) is to cheat a bit and define an intermediate function, that is
(f::F)(x) = compute(f, x)
function compute(f::F, x)
# The actual callable struct implementation
end
function ChainRulesCore.rrule(::typeof(compute), f::F, x)
# Compute value and pullback function
end
# Now testing works fine
test_rrule(compute, f, x)
from chainrulestestutils.jl.
Working out exactly what it is to fed to FiniteDIfferences.jl correctly, is kinda the hard part of the PR.
The actual methods we hit in FiniteDifferences.jl are these ones:
https://github.com/JuliaDiff/FiniteDifferences.jl/blob/c31952549df3607c4809d141c533d83d0015e23a/src/grad.jl#L49-L76
Which use to_vec
to deal with types that are not vectors.
That already should support functors just fine
https://github.com/JuliaDiff/FiniteDifferences.jl/blob/c31952549df3607c4809d141c533d83d0015e23a/src/to_vec.jl#L26-L41
but the finite differences method are not prepared to accept functors as their f
arg.
Which does mean something like #117 (comment)
is wanted.
Probably adapting the _wrap_function
in https://github.com/JuliaDiff/ChainRulesTestUtils.jl/blob/master/src/finite_difference_calls.jl to do that is right.
That file is kinda gross as is (which means making it more gross is less of a problem).
That whole thing (and a lot of the FiniteDifferences file) will one day be cleaned up more extensively by JuliaDiff/FiniteDifferences.jl#97
but that is a much bigger project.
And having this work even if a bit ugly is useful for that to inform that future FiniteDifferences.jl rewrite.
The other thing that is need is to workout what (if anything) need to be done to the make_jvp_calls
Mayube that should will change from:
_make_jvp_call(fdm, f, y, xs, ẋs, ignores)
to
_make_jvp_call(fdm, y, xs, ẋs, ignores)
with f
just being the first element of xs
and its derivative the first of ẋs
and similar it having a entry in ignores
.similar for
_make_j′vp_call
.and those changes would need to be propegated upwards to the places that call those.
Basically so that most of the code in this package doesn't treat
f
any different from any of its arguments.from chainrulestestutils.jl.
Why can't we facilitate this work around in the code itself? Work around seems to be simple enough that instead of checking for a functor we can wrap it ourselves?
from chainrulestestutils.jl.
The reason this issue is still open is that it hasn't been done yet.
Because noone has gotten round to making a PR.
Feel encouraged to open one, contributions are welcome. :-)
We don't need the work around in the code itself. when we can fix it properly.
Which is mostly just making sure things are fed to FiniteDifferences.jl correctly and removing the check.
Although, I am not 100% sure that that doesn't actually look a lot like the workaround. It might, it might not.
from chainrulestestutils.jl.
if you provide me a few pointers on what is meant by "fed to FiniteDifferences.jl correctly", I can open a PR. Maybe some documentation?
from chainrulestestutils.jl.
Ok I gave it my best but I can't figure it out. Thanks for the explanation though. Maybe good for the next person.
from chainrulestestutils.jl.
Related Issues (20)
- `test_approx` ambiguities
- Variants of `TestConfig` offering only forward or only reverse
- Cannot test rule for structure where one (non-differentiable) field cannot be vectorized HOT 7
- getting error in `FiniteDifferences.to_vec` when `test_rrule` for structured type HOT 1
- Error with `Diagonal`
- Stacktraces are hidden HOT 1
- Check for repeated unthunking
- test_rrule() fails in iterate()
- `test_rrule` failed when pullback return array buffer allocated in rrule. HOT 1
- Calling `pullback` twice in `test_rrule` HOT 1
- ChainRulesTestUtils crashes with a custom regularization function on a Flux Dense layer HOT 4
- `test_add!!_behaviour` has strong assumptions on fields HOT 2
- `test_rrule` trying to find `Tangent` on `axes` HOT 1
- default test tolerances assume Float64 precision and numbers ~ 1 HOT 1
- `_can_pass_early` with `missing` HOT 3
- Limitations of `FiniteDifferences.to_vec` for `Tangent()` HOT 1
- Allow editing of `testset` name. HOT 2
- Make replace boolean `check_inferred` with something that allows configuable small unions
- 1 test for `test_rrule(sin, rand(Float32))` fails. HOT 1
- Support MutableTangent automatically
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chainrulestestutils.jl.