Destructuring/iterating a `Tangent` does not unthunk fields, unlike `getindex`/`getproperty`
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 28/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- Active
- Domaine
- devtools
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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]).
- Langage dominant
- Julia
- Étoiles
- 267
- Forks
- 66
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 9
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de JuliaDiff/ChainRulesCore.jl
-
variable scope of `@thunk`Peut-être pris @chengchingwen l’a pris il y a 624 jours. Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 32/100
JuliaDiff/ChainRulesCore.jl#684 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue Structural Tangent
Difficulté 2/5 1-3 heures Accessibilité débutants 55/100
JuliaDiff/ChainRulesCore.jl#669 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
JuliaDiff/ChainRulesCore.jl#668 · 6 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
breaking
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
JuliaDiff/ChainRulesCore.jl#665 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
JuliaDiff/ChainRulesCore.jl#664 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de JuliaDiff/ChainRulesCore.jl
Issues similaires
-
Pin the porting environmentOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
FluxML/Metalhead.jl#407 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
Les mainteneurs répondent en général sous 1 jour
-
lux
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
JuliaGraphs/GraphNeuralNetworks.jl#732 ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
erfinv(::Float16) and erfcinv(::Float16) are wrong for abs(x) <= 0.75 (erfinv(Float16(0)) == 0.2201)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
JuliaMath/SpecialFunctions.jl#571 ·