Destructuring/iterating a `Tangent` does not unthunk fields, unlike `getindex`/`getproperty`
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 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時間
- マージ済み PR(30日)
- 9
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaDiff/ChainRulesCore.jl のほかの issue
-
variable scope of `@thunk`対応中かも @chengchingwen が 619 日前に担当しました。 オープン
難易度 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 1週間以上 初心者へのやさしさ 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
-
`ShallowWaterModel` allocates ~9 KiB per grid point per RK3 stage on the CPU対応中かも @ali-ramadhan が今日担当しました。 オープンperformance 🏍️
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
CliMA/Oceananigans.jl#6421 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
JuliaQUBO/QUBOLib.jl#105 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
NCAR/musica#1118 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`AMSGrad` state starts at `epsilon` instead of zero, so zero gradients move parameters and small gradients are damped対応中かも @parth-patel010 が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
FluxML/Optimisers.jl#247 · コメント 1 件 ·
-
README should say that row and column order must match対応中かも @SAUMYARSH が 1 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 84/100