FluxML / Zygote.jl

21st century AD
https://fluxml.ai/Zygote.jl/
Other
1.48k stars 213 forks source link

ChainRules rule for getproperty overwritten by Zygote default #682

Open dsweber2 opened 4 years ago

dsweber2 commented 4 years ago

demonstrative example:

struct foo
  bar
end
function rrule(::typeof(getproperty), F::T, x::Symbol) where T <: foo
  println("using the rrule")
  function gp_sc(Ȳ)
    println("this is being called")
    ∂F = Composite{T}(Ȳ)
    return NO_FIELDS, ∂F, DoesNotExist()
  end
  return getproperty(F, x), gp_sc
end
y,b = rrule(getproperty, foo(randn(10)), :bar)
b(y)
# compare with
y, back = pullback(x->x.bar, foo(randn(10)));
back(y)

paging @oxinabox as per request.

oxinabox commented 4 years ago

I think this realted to zygote working with literal_getproperty which is the compiler special casing it, for optimization reasons.

I think the solution is we should interecept that in Zygote, and redispatch it for the ChainRule for getproperty. Since getproperty is what a non-source to source AD would see, and they must always agree. Alt: chainrules might be able to do the redistpatch