Repository navigation
Conversation
devmotion
force-pushed
the
dmw/tangent-broadcastable
branch
from
October 29, 2026 22:34
f3c3d59 to
d10dfcf
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #724 +/- ##
==========================================
+ Coverage 93.54% 93.56% +0.01%
==========================================
Files 15 15
Lines 1022 1025 +3
==========================================
+ Hits 956 959 +3
Misses 66 66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Tangent of tuples like their backing tupleTangents like their primal
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devmotion
force-pushed
the
dmw/tangent-broadcastable
branch
from
October 29, 2026 22:53
225ac8f to
a35f1b0
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Whether a structural tangent should broadcast as a container or as a
scalar depends on the broadcast and can't be determined from the tangent
alone (e.g. for `Tangent{Any}`), so throw an `ArgumentError` instead of
guessing. Move the unrelated tuple projector fix to a separate PR.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tangents like their primalThis branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tangentdefines noBroadcast.broadcastable, so broadcasting over one falls back tocollect, which iterates over the backing and produces aVector. That is wrong in different ways depending on the backing:This PR makes broadcasting over a
StructuralTangent(TangentandMutableTangent) throw anArgumentError, like Base does forNamedTuples andDicts:Why not broadcast like the primal?
An earlier version of this PR returned the backing for tuple-backed tangents and
Ref(tangent)otherwise. No such rule is correct in general, because the shape a tangent should broadcast with depends on the broadcast, not on the tangent:Tangent{Any}the primal is unknown, and the constructor accepts any backing.Tangent{SVector}(; data=...)) belongs to a container. Treating it as a scalar made ChainRules' broadcast pullback forx -> x^3silently return[NoTangent(), NoTangent()].Only the code doing the broadcast knows which shape is meant. For example, ChainRules' broadcast rules know the output
ys, so they should unwrap the cotangent there (as_no_tuple_tangentalready does inmapreduce.jl).Compatibility
Broadcasting over a structural tangent used to return a (mostly wrong)
Vector; it now throws. In particular, ChainRules' generic broadcast pullbacks currently rely on this fallback when they get aTangent{Any,<:Tuple}cotangent from Zygote for tuple broadcasts. They need to unwrap it before this is released. The version is therefore bumped to 1.27.0.The unrelated fix for tuple projectors that was part of this PR is now in #725.
🤖 Generated with Claude Code