-
Notifications
You must be signed in to change notification settings - Fork 64
Description
convert{::Type{B}, d::Tangent{P, B}} where {P, B} = backing(d) is current provided.
I don't think it is very useful as is. Using backing directly is more clear and is general in the way we mostly want.
Alternatively we might want convert{::Type{A}, d::Tangent} where A = convert(A, backing(d))
to actually do a convert based on the backing.
Which could be useful for pushing into vectors etc which might come up dealing with Zygotes's use of NamedTuples.
But the fact that we don't seem to use that suggest it isn't needed.
Zygote does right now use the current convert after first doing other steps to convert the content in different ways.
This could just as well be done with backing if we exported that.
https://github.com/FluxML/Zygote.jl/blob/7c66eff0a9200b1095f1c94ac6faec9f16b740fe/src/compiler/chainrules.jl#L52
If we got rid of the convert it would remove all the invalidations from the package.
I am not sure how significant these ones are.
julia> invalidation_trees(invalidations)
2-element Vector{SnoopCompile.MethodInvalidations}:
inserting convert(::Type{<:Tuple}, comp::Tangent{<:Any, <:Tuple}) in ChainRulesCore at /Users/oxinabox/JuliaEnvs/ChainRulesWorld/ChainRulesCore.jl/src/differentials/composite.jl:68 invalidated:
mt_backedges: 1: signature Tuple{typeof(convert), Type{Tuple{DataType, DataType, DataType}}, Any} triggered MethodInstance for Pair{DataType, Tuple{DataType, DataType, DataType}}(::Any, ::Any) (0 children)
2: signature Tuple{typeof(convert), Type{NTuple{8, DataType}}, Any} triggered MethodInstance for Pair{DataType, NTuple{8, DataType}}(::Any, ::Any) (0 children)
3: signature Tuple{typeof(convert), Type{NTuple{7, DataType}}, Any} triggered MethodInstance for Pair{DataType, NTuple{7, DataType}}(::Any, ::Any) (0 children)
4: signature Tuple{typeof(convert), Type{Tuple{Symbol, Any, Symbol, Symbol}}, Any} triggered MethodInstance for setindex!(::Vector{Tuple{Symbol, Any, Symbol, Symbol}}, ::Any, ::Int64) (0 children)
5: signature Tuple{typeof(convert), Type{Tuple{Any, String}}, Any} triggered MethodInstance for setindex!(::Vector{Tuple{Any, String}}, ::Any, ::Int64) (0 children)
inserting convert(::Type{<:Dict}, comp::Tangent{<:Dict, <:Dict}) in ChainRulesCore at /Users/oxinabox/JuliaEnvs/ChainRulesWorld/ChainRulesCore.jl/src/differentials/composite.jl:69 invalidated:
mt_backedges: 1: signature Tuple{typeof(convert), Type{Dict{String, Any}}, Any} triggered MethodInstance for setindex!(::Dict{Base.BinaryPlatforms.AbstractPlatform, Dict{String, Any}}, ::Any, ::Base.BinaryPlatforms.Platform) (0 children)
2: signature Tuple{typeof(convert), Type{Dict{Symbol, Any}}, Any} triggered MethodInstance for setindex!(::IdDict{Function, Dict{Symbol, Any}}, ::Any, ::Any) (8 children)
3: signature Tuple{typeof(convert), Type{Dict{Char, Any}}, Any} triggered MethodInstance for REPL.LineEdit.Prompt(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any) (18 children)