Destructuring/iterating a `Tangent` does not unthunk fields, unlike `getindex`/`getproperty`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 28/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- devtools
调研方向
Start in src/tangent_types/structural_tangent.jl, comparing the unthunk calls in getindex and getproperty with the Base.iterate and Base.indexed_iterate forwarding. Reproduce the snippet with collect(t) and first(nt) to see the thunks. Done means the maintainers have chosen between unthunking iteration and documenting indexed access, and the chosen option is implemented or documented with tests. The design choice is still open, so confirm it in the thread before writing code.
由索引模型根据 Issue 内容生成。
描述
Field access on a Tangent unthunks the field, but iteration does not:
julia> using ChainRulesCore
julia> t = Tangent{Tuple{Float64,Vector{Float64}}}(1.0, @thunk([2.0]));
julia> t[2] # Vector{Float64}
julia> _, b = t; b # Thunk
julia> collect(t) # [1.0, Thunk]
julia> nt = Tangent{NamedTuple{(:a,),Tuple{Vector{Float64}}}}(a=@thunk([1.0]));
julia> nt.a # Vector{Float64}
julia> (; a) = nt; a # Vector{Float64}
julia> first(nt) # Thunk
getindex/getproperty call unthunk (src/tangent_types/structural_tangent.jl, since #121), whereas Base.iterate and Base.indexed_iterate forward to the backing without unthunking.
This caused a bug in ChainRules (JuliaDiff/ChainRules.jl#843): the findnz pullbacks did _, _, V̄ = unthunk(Δ). With Zygote, Δ is Tangent{Any}((ZeroTangent(), ZeroTangent(), thunk)), so V̄ was still a thunk and sparse(I, J, V̄, m, n) threw a MethodError.
There are two possible resolutions:
- Make
iterate/indexed_iterateunthunk, for consistency withgetindex/getproperty. This has a downside: positional destructuring would then also compute components the rule discards, e.g. the_in_, _, V̄ = Δ. - Keep the current behaviour, but document that rules should access the fields they need via
getindex/getproperty(or property destructuring(; a) = Δ) and not via positional destructuring or iteration.
Option 2 seems preferable for performance, but the current behaviour is a silent footgun either way. ChainRules.jl#843 now uses indexing (unthunk(Δ)[3]).
- 主要语言
- Julia
- 星标
- 267
- 派生
- 66
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 9
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaDiff/ChainRulesCore.jl 的其他 Issue
-
variable scope of `@thunk`可能已有人在做 @chengchingwen 于 621 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 32/100
JuliaDiff/ChainRulesCore.jl#684 ·
维护者通常 1 天内回复
-
good first issue Structural Tangent
难度 2/5 1-3 小时 新手友好度 55/100
JuliaDiff/ChainRulesCore.jl#669 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
JuliaDiff/ChainRulesCore.jl#668 · 6 条评论 ·
维护者通常 1 天内回复
-
breaking
难度 3/5 1-2 天 新手友好度 35/100
JuliaDiff/ChainRulesCore.jl#665 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
JuliaDiff/ChainRulesCore.jl#664 · 2 条评论 ·
维护者通常 1 天内回复
查看 JuliaDiff/ChainRulesCore.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
JuliaDiff/TaylorSeries.jl#445 ·
-
🕷️ bug
难度 2/5 1-3 小时 新手友好度 78/100
CliMA/ClimaSeaIce.jl#203 ·
维护者通常 3 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 64/100
JuliaPhysics/BeamletOptics.jl#221 ·
维护者通常 1 天内回复
-
release preparation spack
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
30-minutes algorithm any-language codewars dart easy elixir hackerrank hacktoberfest haskell help wanted interview-prep julia leetcode lua open-source r scala students zig
难度 2/5 1-3 小时 新手友好度 68/100
Huerte/algo-solutions-python#163 ·
维护者通常 1 天内回复