-
Notifications
You must be signed in to change notification settings - Fork 63
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
WIP+RFC add chunked mode #570
base: main
Are you sure you want to change the base?
Changes from all commits
1f2a3a3
6c606c0
8a09e38
5e579e2
2739a66
beda204
3846220
9b888a6
24f1a57
6a81e52
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,6 +78,33 @@ function (::typeof(frule_kwfunc))(kws::Any, ::typeof(frule), ::RuleConfig, args. | |||||||||||
return frule_kwfunc(kws, frule, args...) | ||||||||||||
end | ||||||||||||
|
||||||||||||
struct ProductTangent{P} | ||||||||||||
partials::P | ||||||||||||
end | ||||||||||||
Comment on lines
+81
to
+83
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. How much is gained from this kind of chunking? I mean storing several partials in some tuple. For reverse mode, nothing, I think. For forward mode, maybe The big gain seems to be from making a solid matrix to represent many vectors, and e.g. getting matrix multiplication. So I think the initial design ought to make that work. 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. This design does this (I think). 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. Ok, I guess a vector of vectors can have the same meaning as an |
||||||||||||
|
||||||||||||
function frule(::RuleConfig{>:HasChunkedMode}, (Δf, Δx...), f, args...) | ||||||||||||
return frule((Δf, Δx...), f, args...) | ||||||||||||
end | ||||||||||||
|
||||||||||||
function frule(::RuleConfig{>:HasChunkedMode}, | ||||||||||||
(Δf, Δx)::Tuple{Any,ProductTangent}, f, args...) | ||||||||||||
Comment on lines
+89
to
+90
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. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
||||||||||||
fx = frule((Δf, first(Δx)), args...)[1] | ||||||||||||
dfx = ProductTangent(map(Δrow -> frule((Δf, Δrow), f, args...)[2], Δx)) | ||||||||||||
return (fx, dfx) | ||||||||||||
mcabbott marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||
end | ||||||||||||
|
||||||||||||
function rrule(::RuleConfig{>:HasChunkedMode}, args...) | ||||||||||||
y, back = rrule(args...) | ||||||||||||
return y, ApplyBack(back) | ||||||||||||
end | ||||||||||||
Comment on lines
+96
to
+99
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 know I suggested this I think it might be cleanest to have a new function, whose fallback is Not sure how that intersects with 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. yeah. We might need it to be separate. It feels clunky, but this method also doesn't seem great. 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. Hmm ideally we want to hit the version with this particular trait dropped, and other traits preserved (like HasReverseMode etc) |
||||||||||||
|
||||||||||||
struct ApplyBack{F} | ||||||||||||
back::F | ||||||||||||
end | ||||||||||||
|
||||||||||||
(a::ApplyBack)(dy) = a.back(dy) | ||||||||||||
(a::ApplyBack)(dy::ProductTangent) = ProductTangent(map(a.back, dy.partials)) # or some Tangent recursion? | ||||||||||||
|
||||||||||||
""" | ||||||||||||
rrule([::RuleConfig,] f, x...) | ||||||||||||
|
||||||||||||
|
@@ -149,7 +176,7 @@ const NO_RRULE_DOC = """ | |||||||||||
This is an piece of infastructure supporting opting out of [`rrule`](@ref). | ||||||||||||
It follows the signature for `rrule` exactly. | ||||||||||||
A collection of type-tuples is stored in its method-table. | ||||||||||||
If something has this defined, it means that it must having a must also have a `rrule`, | ||||||||||||
If something has this defined, it means that it must having a must also have a `rrule`, | ||||||||||||
defined that returns `nothing`. | ||||||||||||
|
||||||||||||
!!! warning "Do not overload no_rrule directly" | ||||||||||||
|
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.
[JuliaFormatter] reported by reviewdog 🐶