Closed
Description
Right now: (What i will call the Sometimes MultiOutput View)
we interpret a primal function returning a tuple as meaning it has multiple outputs,
and thus that the pullback should have multiple inputs.
The alternative view in this proposal (The Always Single Output View),
is that all julia functions only ever have a single output.
Sometimes that output is a tuple (or other iterables), in which case it is iterated on a,b=f(x)
type assignement.
And thus all pullbacks should only ever accept a single input.
An implication of this is that if the primal returned a Tuple
, the pushforward should return a Composite{Tuple}
of derivatives, rather than a Tuple
.
Sometime Multioutput (current)
Pros:
- Nice to be able talk about multioutput functions having multinput pullbacks. Feels good.
- Easy to write pullback for multiple output functions, as have them all directly
Cons:
- Can lead to very weird things for things that may or may not return tuples.
- E.g. the
identity
primal function only has 1 method, but it needs 2rrules
(https://github.com/JuliaDiff/ChainRules.jl/pull/175/files#diff-61fe5ffefb8f5d33c006125d43a7fcfaR129-R144) map(f, ::Tuple)
is probably another. And one we really don't want to be splatting
- E.g. the
Always Single output (proposed)
Pros
- Nice to stay "Julia only has single output functions"
- Tuples are not special vs other iterables.
- Avoids splatting when the pullback used, which is probably good for performance (depending how the compiler is feeling)
Cons:
- making pushforward return
Composite{Tuple}(a,b,c)
not(a, b, c)
is a bit wordy. - dispatches become harded to write
pullback((a,b,c)::Tuple{A, B, C})
this related to the The Extensibility Problem, for propagator closures #53 and if it even actually exists (if it doesn't this doens't matter).
Metadata
Metadata
Assignees
Labels
No labels