-
Notifications
You must be signed in to change notification settings - Fork 62
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
Invalidations from ChainRulesCore Tangent overload on Tail #576
Comments
Hmm is this a weird kind of invalidation not because we are defining a more specific method, I think it would probably be fine for us to error in this case too. |
This one has a lot of children and will hit a lot of packages, so it would be nice to fix it if possible. @oxinabox are you suggesting deleting the method? |
…}}})` This fixes many invalidations when loading ChainRulesCore.jl. Fixes JuliaDiff#576.
Current version: julia> import Pkg; Pkg.activate(temp=true); Pkg.add("ChainRulesCore")
julia> using SnoopCompileCore; invalidations = @snoopr(using ChainRulesCore); using SnoopCompile
julia> trees = invalidation_trees(invalidations);
julia> length(uinvalidated(invalidations))
267
julia> trees
3-element Vector{SnoopCompile.MethodInvalidations}:
inserting *(::Any, ::ZeroTangent) in ChainRulesCore at /home/hendrik/.julia/packages/ChainRulesCore/6Sl9y/src/tangent_arithmetic.jl:105 invalidated:
mt_backedges: 1: signature Tuple{typeof(*), String, Any} triggered MethodInstance for (::Test.var"#7#9")(::Any) (0 children)
2: signature Tuple{typeof(*), String, Any} triggered MethodInstance for (::Test.var"#8#10")(::Any) (0 children)
inserting convert(::Type{<:Number}, x::ChainRulesCore.NotImplemented) in ChainRulesCore at /home/hendrik/.julia/packages/ChainRulesCore/6Sl9y/src/tangent_types/notimplemented.jl:63 invalidated:
backedges: 1: superseding convert(::Type{Union{}}, x) in Base at essentials.jl:213 with MethodInstance for convert(::Core.TypeofBottom, ::Any) (13 children)
inserting tail(t::Tangent{<:NamedTuple{<:Any, <:Tuple{}}}) in ChainRulesCore at /home/hendrik/.julia/packages/ChainRulesCore/6Sl9y/src/tangent_types/tangent.jl:110 invalidated:
mt_backedges: 1: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base._cshp(::Int64, ::Tuple{Bool}, ::Tuple{Int64}, ::Any) (0 children)
2: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base._cshp(::Int64, ::Tuple{Bool}, ::Tuple{Any, Vararg{Any}}, ::Any) (0 children)
3: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_isdone(::Tuple, ::Any) (0 children)
4: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Missing, Vararg{Any}}, ::Missing) (0 children)
5: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Any, Vararg{Any}}, ::Missing) (0 children)
6: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Bool, Vararg{Any}}, ::Bool) (0 children)
7: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Any, Vararg{Any}}, ::Bool) (0 children)
8: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for iterate(::Base.Iterators.Enumerate{Vector{VersionNumber}}, ::Any) (0 children)
9: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.tail(::NamedTuple{names}) where names (335 children)
24 mt_cache Removing https://github.com/JuliaDiff/ChainRulesCore.jl/blob/main/src/tangent_types/tangent.jl#L110: julia> import Pkg; Pkg.activate(temp=true); Pkg.develop("ChainRulesCore")
julia> using SnoopCompileCore; invalidations = @snoopr(using ChainRulesCore); using SnoopCompile
julia> trees = invalidation_trees(invalidations);
julia> length(uinvalidated(invalidations))
271
julia> trees
3-element Vector{SnoopCompile.MethodInvalidations}:
inserting *(::Any, ::ZeroTangent) in ChainRulesCore at /home/hendrik/.julia/dev/ChainRulesCore/src/tangent_arithmetic.jl:105 invalidated:
mt_backedges: 1: signature Tuple{typeof(*), String, Any} triggered MethodInstance for (::Test.var"#7#9")(::Any) (0 children)
2: signature Tuple{typeof(*), String, Any} triggered MethodInstance for (::Test.var"#8#10")(::Any) (0 children)
18 mt_cache
inserting convert(::Type{<:Number}, x::ChainRulesCore.NotImplemented) in ChainRulesCore at /home/hendrik/.julia/dev/ChainRulesCore/src/tangent_types/notimplemented.jl:63 invalidated:
backedges: 1: superseding convert(::Type{Union{}}, x) in Base at essentials.jl:213 with MethodInstance for convert(::Core.TypeofBottom, ::Any) (168 children)
9 mt_cache
inserting tail(t::Tangent{<:NamedTuple{<:Any, <:Tuple{Any}}}) in ChainRulesCore at /home/hendrik/.julia/dev/ChainRulesCore/src/tangent_types/tangent.jl:109 invalidated:
mt_backedges: 1: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base._cshp(::Int64, ::Tuple{Bool}, ::Tuple{Int64}, ::Any) (0 children)
2: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base._cshp(::Int64, ::Tuple{Bool}, ::Tuple{Any, Vararg{Any}}, ::Any) (0 children)
3: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_isdone(::Tuple, ::Any) (0 children)
4: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Missing, Vararg{Any}}, ::Missing) (0 children)
5: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Any, Vararg{Any}}, ::Missing) (0 children)
6: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Bool, Vararg{Any}}, ::Bool) (0 children)
7: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.Iterators._zip_iterate_some(::Tuple, ::Any, ::Tuple{Any, Vararg{Any}}, ::Bool) (0 children)
8: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for iterate(::Base.Iterators.Enumerate{Vector{VersionNumber}}, ::Any) (0 children)
9: signature Tuple{typeof(Base.tail), Any} triggered MethodInstance for Base.tail(::NamedTuple{names}) where names (184 children) So there are still many invalidations left... The code removing https://github.com/JuliaDiff/ChainRulesCore.jl/blob/main/src/tangent_types/tangent.jl#L110 lives in https://github.com/ranocha/ChainRulesCore.jl/tree/hr/fix_invalidations. Shall I make a PR? Or does anybody have time to hunt these invalidations? |
The ones on The one on Re:tail. We should also be able to delete Since |
Base has these methods for
There's no overlap with |
IIRC the rule which uses it is https://github.com/JuliaDiff/ChainRules.jl/blob/39c2d17df672836659493d6adb7d4ad8593250a5/src/rulesets/Base/indexing.jl#L175-L178 , obviously that could be re-written if someone wants to. |
I believe it is a so called "world splitting" optimization. |
Ah ok. So every week the mental model you need grows more complex. I guess this is a strong argument against defining your own types, when you can avoid it. "Your struct is as good as Base's" isn't quite true, it seems. |
Yeah, I miss the days before julia had an optimizer. It used to be easier to reason about. |
I think it can also be totally independent of any of these optimizations. If anything is inferred only as |
No, I don't think so. |
I wonder how much we'd have to change in Base to delete Tangent entirely. Being able to add them is the big virtue, what chance we could get these methods accepted?
|
JuliaLang/julia#46762 helps a bit but does not fix all invalidations. |
Found in SciML/DifferentialEquations.jl#786
The text was updated successfully, but these errors were encountered: