You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sum rules do not match the signatures of the Base methods #868
The sum rules don't match the signatures of the Base methods they cover. If a call matches a rule's positional types but not its keywords, the rule throws a MethodError instead of returning nothing and leaving the call to AD. This is the same kind of bug as #768.
Make every sum/sum! rule accept exactly the arguments and keywords of the Base method it covers. Treat init as non-differentiable (no tangent), as the foldl rrule already does (src/rulesets/Base/mapreduce.jl, "it does not return a gradient for init").
There can't be a rule for generic iterables: the tangent of a Generator, Dict and so on is structural rather than elementwise, so sum(ẋ) would be meaningless. Those inputs should keep falling back to AD (see #768 and #867).
I've reproduced this on current main (30cf1f6) and I'm working on a fix in src/rulesets/Base/mapreduce.jl: adding the init keyword (non-differentiable, no tangent, as in the foldl rule) to all the sum/sum! rules, with tests in test/rulesets/Base/mapreduce.jl. Will open a PR shortly.
Activity
Huyvux12 commentedon Nov 7, 2026
I've reproduced this on current
main(30cf1f6) and I'm working on a fix insrc/rulesets/Base/mapreduce.jl: adding theinitkeyword (non-differentiable, no tangent, as in thefoldlrule) to all thesum/sum!rules, with tests intest/rulesets/Base/mapreduce.jl. Will open a PR shortly.