Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #745 +/- ##
===========================================
- Coverage 97.19% 41.27% -55.93%
===========================================
Files 128 118 -10
Lines 6678 7208 +530
===========================================
- Hits 6491 2975 -3516
- Misses 187 4233 +4046
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
MWE for type instability, to run on Julia 1.10 (doesn't appear on 1.11) with the DI version from this branch: using DifferentiationInterface, JET
f(x, c) = exp(x) * c
backend = DifferentiationInterface.AutoZeroReverse()
@report_opt prepare_second_derivative(f, backend, 1.0, Constant(1))DetailsJET report: ═════ 9 possible errors found ═════
┌ second_derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/fallbacks/no_prep.jl:101
│┌ kwcall(::@NamedTuple{…}, ::typeof(prepare_second_derivative), f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/second_order/second_derivative.jl:60
││┌ prepare_second_derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/second_order/second_derivative.jl:68
│││┌ kwcall(::@NamedTuple{…}, ::typeof(prepare_derivative), ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:66
││││┌ prepare_derivative(::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:70
│││││┌ kwcall(::@NamedTuple{…}, ::typeof(prepare_pushforward), ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:93
││││││┌ prepare_pushforward(::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:101
│││││││┌ kwcall(::@NamedTuple{…}, ::typeof(DifferentiationInterface._prepare_pushforward_aux), ::DifferentiationInterface.PushforwardSlow, ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:120
││││││││┌ _prepare_pushforward_aux(::DifferentiationInterface.PushforwardSlow, ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:130
│││││││││┌ shuffled_derivative(x::Float64, f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, rewrap::DifferentiationInterface.Rewrap{…}, unannotated_contexts::Int64) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:210
││││││││││┌ derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{Int64}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/fallbacks/no_prep.jl:48
│││││││││││┌ kwcall(::@NamedTuple{…}, ::typeof(prepare_derivative), f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:66
││││││││││││┌ prepare_derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:70
│││││││││││││┌ kwcall(::NamedTuple, ::typeof(prepare_pushforward), f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, tx::Tuple{…}, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:93
││││││││││││││┌ pairs(nt::NamedTuple) @ Base.Iterators ./iterators.jl:279
│││││││││││││││┌ (Base.Pairs{Symbol})(data::NamedTuple, itr::Tuple{Vararg{Symbol}}) @ Base ./essentials.jl:343
││││││││││││││││┌ eltype(::Type{A} where A<:NamedTuple) @ Base ./namedtuple.jl:233
│││││││││││││││││┌ nteltype(::Type{NamedTuple{names, T}} where names) where T<:Tuple @ Base ./namedtuple.jl:235
││││││││││││││││││┌ eltype(t::Type{<:Tuple{Vararg{E}}}) where E @ Base ./tuple.jl:208
│││││││││││││││││││┌ _compute_eltype(t::Type{<:Tuple{Vararg{E}}} where E) @ Base ./tuple.jl:231
││││││││││││││││││││┌ afoldl(op::Base.var"#54#55", a::Any, bs::Vararg{Any}) @ Base ./operators.jl:544
│││││││││││││││││││││┌ (::Base.var"#54#55")(a::Any, b::Any) @ Base ./tuple.jl:235
││││││││││││││││││││││┌ promote_typejoin(a::Any, b::Any) @ Base ./promotion.jl:172
│││││││││││││││││││││││┌ typejoin(a::Any, b::Any) @ Base ./promotion.jl:127
││││││││││││││││││││││││ runtime dispatch detected: Base.UnionAll(%403::Any, %405::Any)::Any
│││││││││││││││││││││││└────────────────────
││││││││││││││││││││┌ afoldl(op::Base.var"#54#55", a::Any, bs::Vararg{Any}) @ Base ./operators.jl:545
│││││││││││││││││││││┌ (::Base.var"#54#55")(a::Type, b::Any) @ Base ./tuple.jl:235
││││││││││││││││││││││┌ promote_typejoin(a::Type, b::Any) @ Base ./promotion.jl:172
│││││││││││││││││││││││┌ typejoin(a::Type, b::Any) @ Base ./promotion.jl:127
││││││││││││││││││││││││ runtime dispatch detected: Base.UnionAll(%398::Any, %400::Any)::Any
│││││││││││││││││││││││└────────────────────
││││││││││││┌ prepare_derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:66
│││││││││││││ failed to optimize due to recursion: DifferentiationInterface.var"#prepare_derivative#42"(::Val{…}, ::typeof(prepare_derivative), ::typeof(f), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Constant{…})
││││││││││││└────────────────────
│││││││││││┌ kwcall(::@NamedTuple{…}, ::typeof(prepare_derivative), f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:66
││││││││││││ failed to optimize due to recursion: Core.kwcall(::@NamedTuple{…}, ::typeof(prepare_derivative), ::typeof(f), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Constant{…})
│││││││││││└────────────────────
││││││││││┌ derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{Int64}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/fallbacks/no_prep.jl:49
│││││││││││┌ derivative(f::typeof(f), prep::DifferentiationInterface.PushforwardDerivativePrep{…} where E<:DifferentiationInterface.PullbackPushforwardPrep, backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:128
││││││││││││┌ pushforward(f::typeof(f), prep::DifferentiationInterface.PullbackPushforwardPrep, backend::DifferentiationInterface.AutoZeroReverse, x::Float64, tx::Tuple{…}, contexts::Constant{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:258
│││││││││││││┌ ntuple(f::DifferentiationInterface.var"#34#35"{…}, ::Val{…}) @ Base ./ntuple.jl:48
││││││││││││││ runtime dispatch detected: f::DifferentiationInterface.var"#34#35"{typeof(f), DifferentiationInterface.AutoZeroReverse, Float64, Tuple{…}, Tuple{…}}(1)::Float64
│││││││││││││└────────────────────
│││││││││││││┌ ntuple(f::DifferentiationInterface.var"#18#19"{…}, ::Val{…}) @ Base ./ntuple.jl:48
││││││││││││││ runtime dispatch detected: f::DifferentiationInterface.var"#18#19"{…}(1)::Float64
│││││││││││││└────────────────────
││││││││││┌ derivative(f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, x::Float64, contexts::Constant{Int64}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/fallbacks/no_prep.jl:45
│││││││││││ failed to optimize due to recursion: DifferentiationInterface.derivative(::typeof(f), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Constant{…})
││││││││││└────────────────────
│││││││││┌ shuffled_derivative(x::Float64, f::typeof(f), backend::DifferentiationInterface.AutoZeroReverse, rewrap::DifferentiationInterface.Rewrap{…}, unannotated_contexts::Int64) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/derivative.jl:207
││││││││││ failed to optimize due to recursion: DifferentiationInterface.shuffled_derivative(::Float64, ::typeof(f), ::DifferentiationInterface.AutoZeroReverse, ::DifferentiationInterface.Rewrap{…}, ::Int64)
│││││││││└────────────────────
││││││││┌ _prepare_pushforward_aux(::DifferentiationInterface.PushforwardSlow, ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}; strict::Val{…}) @ DifferentiationInterface /Users/guillaumedalle/Documents/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/src/first_order/pushforward.jl:120
│││││││││ failed to optimize due to recursion: DifferentiationInterface.var"#_prepare_pushforward_aux#12"(::Val{…}, ::typeof(DifferentiationInterface._prepare_pushforward_aux), ::DifferentiationInterface.PushforwardSlow, ::typeof(DifferentiationInterface.shuffled_derivative), ::DifferentiationInterface.AutoZeroReverse, ::Float64, ::Tuple{…}, ::DifferentiationInterface.FunctionContext{…}, ::DifferentiationInterface.BackendContext{…}, ::Constant{…}, ::Constant{…}) |
|
@gdalle, in your opinion, should i use It would be non-breaking for me since it would be the first version that uses DI.jl, when I will release it. |
|
Definitely, go for it. I just made it optional because some criminals over in SciML misuse my API, but technically it wouldn't even have been breaking to make it the default right away |
Core
strictto everyprepare_operatorfunction, with default valuestrict=Val(false). This kwarg is then passed as a first argument to a hidden method ofprepare_operator, in order to reduce the depth of the call stack and help the compiler infer types properly.strict=Val(true), store the signatureSIG = typeof((f, backend, x, contexts))inside the type of the preparation result. Otherwise storeSIG = Nothing.SIG !== Nothingrecorded during preparation is consistent with the signature during execution.SIG.Tests and docs
strictkeyword.Other modifications
Warning
Setting
strict=Val(true)is recommended from now on, but can break existing code which happens to work even though it uses preparation incorrectly. That is why the default value will remainstrict=Val(false)until the next breaking release.Lessons learned: