-
Notifications
You must be signed in to change notification settings - Fork 31
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
Use rrule of KwFunc for Core.kwcall #270
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -225,6 +225,25 @@ function (::∂⃖{N})(f::T, args...) where {T, N} | |||||
end | ||||||
end | ||||||
end | ||||||
function (::∂⃖{N})(::typeof(Core.kwcall), kwargs, f::T, args...) where {T, N} | ||||||
if N == 1 | ||||||
# Base case (inlined to avoid ambiguities with manually specified | ||||||
# higher order rules) | ||||||
z = rrule(DiffractorRuleConfig(), KwFunc(f), kwargs, f, args...) | ||||||
if z === nothing | ||||||
return ∂⃖recurse{1}()(f, args..., kwargs...) | ||||||
end | ||||||
return z | ||||||
else | ||||||
∂⃖p = ∂⃖{N-1}() | ||||||
@destruct z, z̄ = ∂⃖p(rrule, f, args...; kwargs...) | ||||||
if z === nothing | ||||||
return ∂⃖recurse{N}()(f, args...; kwargs...) | ||||||
else | ||||||
return ∂⃖rrule{N}()(z, z̄) | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
function ChainRulesCore.rrule_via_ad(::DiffractorRuleConfig, f::T, args...) where {T} | ||||||
Tuple{Any, Any}(∂⃖{1}()(f, args...)) | ||||||
|
@@ -244,6 +263,10 @@ struct KwFunc{T,S} | |||||
end | ||||||
(kw::KwFunc)(args...) = kw.kwf(args...) | ||||||
|
||||||
function ChainRulesCore.rrule(::typeof(Core.kwcall), kwargs, f, args...) | ||||||
rrule(KwFunc(f), kwargs, f, args...) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why isn't this
Suggested change
is that the same, or is it different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because (I think) we want to hit this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not exactly sure why the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the function ChainRulesCore.rrule(::typeof(Core.kwcall), kwargs, f, args...)
r = Core.kwfunc(rrule)(kwargs, rrule, f, args...)
if r === nothing
return nothing
end
x, back = r
x, Δ->begin
(NoTangent(), NoTangent(), back(Δ)...)
end
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this might be the thing that is there to avoid ADing through so much of the kwarg machinery in the nested AD case |
||||||
end | ||||||
|
||||||
function ChainRulesCore.rrule(::typeof(Core.kwfunc), f) | ||||||
KwFunc(f), Δ->(NoTangent(), Δ) | ||||||
end | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its basically a copy of the non-kw version of the function, but that is what we want in order to avoid ADing through the kw machinery, if there are no kws if I understand correctly?