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

Bug in rrule(*) #247

Closed
dpsanders opened this issue Aug 19, 2020 · 6 comments · Fixed by #249
Closed

Bug in rrule(*) #247

dpsanders opened this issue Aug 19, 2020 · 6 comments · Fixed by #249

Comments

@dpsanders
Copy link

dpsanders commented Aug 19, 2020

If I understand correctly, the following MWE should return numbers from the pullback:

julia> using ChainRules

julia> y = 3.0

julia> a, a_pullback = rrule(*, 2, y);

julia> a_pullback(1.0)
(Zero(), Thunk(ChainRules.var"#115#159"{Float64,Float64}(1.0, 3.0))
, Thunk(ChainRules.var"#116#160"{Float64,Int64}(1.0, 2))
)
@ettersi
Copy link
Contributor

ettersi commented Aug 19, 2020

Why do you think these should be numbers? If you have a fancy number type where multiplication is expensive, not easily elidible and you only want one of the two pullbacks, then you need thunks to avoid unnecessary computations.

@dpsanders
Copy link
Author

dpsanders commented Aug 20, 2020

For the following reasons:

  1. By analogy with other arithmetic operations:
julia> a, a_pullback = rrule(+, 1, 2);

julia> a_pullback(1)
(Zero(), 1, 1)
  1. I do not want to have to special-case my generic code.

  2. Julia knows which types I'm using and that they are not fancy.

  3. Any fancy behaviour should be opt-in and controlled by a trait.

  4. I didn't see anything in the docs warning that * was special and showing how to use it. (Although I didn't read all the docs.)

@dpsanders
Copy link
Author

Apparently I just need to add unthunk(...) to the things returned from calling a pullback.
This should be added to the docs somewhere on the front page.

@ettersi
Copy link
Contributor

ettersi commented Aug 20, 2020

Yes, unthunk() should be called on return values from frule and rrule.

I agree that the documentation could be better. My (by no means expert!) understanding is that this package is still somewhat in the prototyping stage, hence there has not been much of a push yet to really polish the documentation.

@willtebbutt willtebbutt linked a pull request Aug 20, 2020 that will close this issue
@oxinabox
Copy link
Member

oxinabox commented Aug 20, 2020

I agree that the documentation could be better. My (by no means expert!) understanding is that this package is still somewhat in the prototyping stage, hence there has not been much of a push yet to really polish the documentation.

We are trying really hard with the documentation.
Most of what we have is fairly polished,
but there are random gaps that are just absent,
and explaining thunks properly is one of them

This should be added to the docs somewhere on the front page.

There are many things that need to be added prominantly.
Its a hard take to balance.
Particularly since you want simple example early,
and adding mention of thunking too soon just complciates matters.
But I agree we could definately do better on this.

@nickrobinson251
Copy link
Contributor

nickrobinson251 commented Aug 20, 2020

regarding docs for Thunk in general, it'd be good to have specific proposals for improvements :)
currently

I'm sure we can improve things, but the more concrete the suggestion the better :)

I just need to add unthunk(...) to the things returned from calling a pullback. This should be added to the docs somewhere

yeah, that's a good suggestion. It looks like i made an issue for this (JuliaDiff/ChainRulesCore.jl#154) but it's not yet addressed (and since then the example has changed so we no longer show this, nevermind comment on it)

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

Successfully merging a pull request may close this issue.

4 participants