-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Non-deterministic inference results? #50735
Comments
Perhaps related to the issue I ran into w/ quinnj/JSONBase.jl#2, which @aviatesk helped diagnose as an issue in inference w/ |
Can you try with #50696? There appears to be several things in here that are expected to trigger undefined behavior (such as __anyeltypedual), but it looks like it might just be hitting unnecessarily restrictions on recursive THTTs. |
Same behavior. |
Slightly boiled down MWE: const DUALCHECK_RECURSION_MAX = 10
promote_dual(A, B) = A
diffeqmapreduce(f::F, op::OP, x::Tuple) where {F, OP} = reduce(op, map(f, x))
function anyeltypedual(x, counter = 0)
diffeqmapreduce(DualEltypeChecker(x, counter), promote_dual,
map(Val, propertynames(x)))
end
function __anyeltypedual(::Type{T}) where {T}
hasproperty(T, :parameters) ?
mapreduce(anyeltypedual, promote_dual, T.parameters; init = Any) : T
end
anyeltypedual(::Type{T}, counter = 0) where {T} = __anyeltypedual(T)
anyeltypedual(x::Number, counter = 0) = anyeltypedual(typeof(x))
promote_u0(u0, p, t0) = anyeltypedual(p)
struct DualEltypeChecker{T}
x::T
counter::Int
DualEltypeChecker(x::T, counter::Int) where {T} = new{T}(x, counter + 1)
end
function (dec::DualEltypeChecker)(::Val{Y}) where {Y}
isdefined(dec.x, Y) || return Any
dec.counter >= DUALCHECK_RECURSION_MAX && return Any
anyeltypedual(getproperty(dec.x, Y), dec.counter)
end
struct Thing
a::Float64
end
struct Wrapper1{T}
thing::T
end
struct Wrapper2{T}
thing::T
end
thing = Thing(1.0)
x = 1.0 promote_u0(x, Wrapper1(thing), (0.0, 1.0))
@code_warntype promote_u0(x, Wrapper1(thing), (0.0, 1.0))
MethodInstance for promote_u0(::Float64, ::Wrapper1{Thing}, ::Tuple{Float64, Float64})
from promote_u0(u0, p, t0) @ Main ~/Developer/jl-forward-diff/mwe-chris.jl:19
Arguments
#self#::Core.Const(promote_u0)
u0::Float64
p::Wrapper1{Thing}
t0::Tuple{Float64, Float64}
Body::Any
1 ─ %1 = Main.anyeltypedual(p)::Any
└── return %1 promote_u0(x, Wrapper2(thing), (0.0, 1.0))
@code_warntype promote_u0(x, Wrapper2(thing), (0.0, 1.0))
MethodInstance for promote_u0(::Float64, ::Wrapper2{Thing}, ::Tuple{Float64, Float64})
from promote_u0(u0, p, t0) @ Main ~/Developer/jl-forward-diff/mwe-chris.jl:19
Arguments
#self#::Core.Const(promote_u0)
u0::Float64
p::Wrapper2{Thing}
t0::Tuple{Float64, Float64}
Body::Type{Any}
1 ─ %1 = Main.anyeltypedual(p)::Core.Const(Any)
└── return %1 Weirdly however, calling directly @code_warntype anyeltypedual(Wrapper1(thing))
MethodInstance for anyeltypedual(::Wrapper1{Thing})
from anyeltypedual(x) @ Main ~/Developer/jl-forward-diff/mwe-chris.jl:9
Arguments
#self#::Core.Const(anyeltypedual)
x::Wrapper1{Thing}
Body::Type{Any}
1 ─ %1 = (#self#)(x, 0)::Core.Const(Any)
└── return %1 and similar for |
MWE, here's the setup code isolated to just ForwardDiff:
Now the checks:
First reported as SciML/DiffEqBase.jl#918
The text was updated successfully, but these errors were encountered: