Giter Club home page Giter Club logo

Comments (6)

piever avatar piever commented on August 26, 2024 1

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.

oxinabox avatar oxinabox commented on August 26, 2024 1

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

function _make_jvp_call(fdm, f, y, xs, ẋs, ignores)

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.

rick2047 avatar rick2047 commented on August 26, 2024

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.

oxinabox avatar oxinabox commented on August 26, 2024

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.

rick2047 avatar rick2047 commented on August 26, 2024

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.

rick2047 avatar rick2047 commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.