Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules for functions / structs etc #4

Closed
willtebbutt opened this issue May 30, 2019 · 5 comments
Closed

Rules for functions / structs etc #4

willtebbutt opened this issue May 30, 2019 · 5 comments

Comments

@willtebbutt
Copy link
Member

The current design requires that rules have the form

function rrule(::typeof(foo), args...)
    ...
    return (rule_arg_1, rule_arg_2, ...)
end

I would like to propose to extend this to the following:

function rrule(foo::typeof(foo), args...)
    ...
    return (rule_foo, rule_arg_1, rule_arg_2, ...)
end

A lot of the time rule_foo will be a DNE, which is fine. However, if we're looking to implement rules for particular structs, then it may well be important to be able to represent the gradient w.r.t. the fields of the struct.

@oxinabox oxinabox transferred this issue from JuliaDiff/ChainRules.jl Aug 2, 2019
@ChrisRackauckas
Copy link
Member

Won't this be necessary for things like the derivative of Dense?

@oxinabox
Copy link
Member

oxinabox commented Aug 3, 2019

I am pretty sure this is actually closed.
Pretty sure we determined
The derivative of something returing a struct is a named tuple of differentiables, 1 per field.

@willtebbutt ?

@oxinabox
Copy link
Member

oxinabox commented Aug 3, 2019

Won't this be necessary for things like the derivative of Dense?

Not under normal uses no.
Tracker can't work on things returning structs (I do believe Nabla and Zygote can).
the derivative of a Flux model is not for Dense, but rather it is params(::Dense) which is a collection of matrixs.

@willtebbutt
Copy link
Member Author

willtebbutt commented Aug 3, 2019

Won't this be necessary for things like the derivative of Dense?

There are two orthogonal issues here:

  1. If you're using an AD system that can handle adjoints w.r.t. structs (e.g. Zygote) and you wanted to define a custom rrule for Dense as opposed to just running AD then yes, you definitely need this.
  2. Not all AD systems are able to handle rules of this form - as @oxinabox points out Tracker doesn't, and Nabla only kind of does. For these systems you have to write work-arounds that pull the data out of structs first and then pass to a plain function, so it's not so much of a problem.

My feeling is that Zygote has got this 'right', and that we should support this functionality. Unfortunately this change requires some fairly dull work.

@oxinabox oxinabox mentioned this issue Aug 27, 2019
@oxinabox oxinabox added this to the v0.4 milestone Sep 18, 2019
@oxinabox oxinabox removed this from the v0.4 milestone Oct 25, 2019
@oxinabox
Copy link
Member

The only remaining parts of this are covered by #8

oxinabox pushed a commit that referenced this issue Jan 22, 2020
* Add Documentation setup with Documenter

This adds no actual documentation, only the infrastructure needed to
set up and deploy documentation.

* Remove testing on 0.7, add 1.1

In the REQUIRE file, the package declares itself to be compatible only
with Julia 1.0 or higher, but 0.7 was still listed in CI. This removes
0.7 and adds 1.1.

It also updates the coverage setup.

* Add a Project.toml file

These are indispensible for local development, and will soon be required
anyway (for some definition of "soon").

* Add missing dependency on ForwardDiff to REQUIRE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants