Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove convert for structured Tangent? #359

Closed
oxinabox opened this issue May 27, 2021 · 3 comments · Fixed by #397
Closed

Remove convert for structured Tangent? #359

oxinabox opened this issue May 27, 2021 · 3 comments · Fixed by #397
Labels
breaking a breaking change Structural Tangent Related to the `Tangent` type for structured (composite) values
Milestone

Comments

@oxinabox
Copy link
Member

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)
@oxinabox oxinabox added Structural Tangent Related to the `Tangent` type for structured (composite) values breaking a breaking change labels May 27, 2021
@mzgubic
Copy link
Member

mzgubic commented May 27, 2021

If we do convert{::Type{A}, d::Tangent} where A = convert(A, backing(d)) the change isn't breaking, right?

@oxinabox
Copy link
Member Author

If we do convert{::Type{A}, d::Tangent} where A = convert(A, backing(d)) the change isn't breaking, right?

Correct, that isn't breaking.
I just don't know that was want it.
and it doesn't solve the invalidations, infact it makes them much worse I think, but possibly still not bad enough to matter.

@oxinabox
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking a breaking change Structural Tangent Related to the `Tangent` type for structured (composite) values
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants