-
Notifications
You must be signed in to change notification settings - Fork 219
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
Tracker does not work with multilevel model #1549
Comments
The problem is the definition of the LKJ bijector. More specifically, in your example https://github.com/TuringLang/Bijectors.jl/blob/50bb27661d724976c0d6c008cf164d4d35515f9e/src/compat/tracker.jl#L424 creates a mattix of |
The use of |
Generally, it seems inefficient to compute You could make it an additional argument of the models (possibly with a default value of |
Thanks for the quick response and advice about That explains the issue with Tracker. I assume there's not much I can do at my end to keep the LKJ prior and still use Tracker as the backend, correct (at least with the way the model is currently coded)? As for Zygote, it works for the varying intercept model when I move out Unfortunately, Zygote still does not work for the varying slope models. This time I get a message about NamedTuple.
Anything I can do to fix that? So far as I can tell, issues with NamedTuple and Zygote have happened before (see here, for example), but I'm not sure if there's anything I can do from my end with Turing. Apologies if that seems like a newbie issue. I am relatively new at using Julia and still trying to get my head around Julia and Turing. The error messages are generally more interpretable than R, but it's like reading a foreign language :-p |
No, it seems it requires a fix in Bijectors.
It seems the problem is |
Thanks. Using In case someone else has a similar problem and stumbles across this issue, as a second workaround, you can also build your own diagonal matrix, D. I tried it and it works with Zygote as well. Instead of
you can use
So what you get is
It works, albeit a bit slower than using Thanks for the help. I appreciate it. |
I'm back! I have a question for you (it may belong here, maybe under Zygote. I'm not sure). I've tried to run parallel chains using MCMCDistributed. Unfortunately, when I try, I tend to get one chain out four that says
I'm wondering if there is anything I can do to address this? I'd like to be able to run parallel chains. |
Is the error consistently reproducible with parallel sampling but never occurs with standard sampling? In principle, this numerical error should not be related to parallel sampling and be reproducible also with regular sampling. Parallel sampling should completely decouple the model and samplers of different processes (MCMCDistributed) or threads (MCMCThreads), and each chain is sampled independently with a randomly chosen seed. |
Good question! I should have been clearer in my post. When I run a single chain using Zygote as the backend, I still get the same error message once in a while (maybe 10% - 20% of the time. I haven't kept track, to be honest). When running parallel chains, I have yet to run an instance without the error message. I haven't had an issue with the PosDefException using forwarddiff. |
I don't know why you would get numerical errors with Zygote but not with ForwardDiff - this seems weird. |
I agree. I initially thought it might be related to this issue and solution, but it seemed weird it only happened for me with Zygote and not with forwarddiff. Hence why I thought I should ask. If it is the case that it's related to the linked issue, then setting reasonable initial values is probably the solution. |
I am also having problems with sing Turing, DataFrames, Pipe, CSV, HTTP, Zygote, ReverseDiff
using Random:seed!
using Statistics: mean, std
seed!(1)
setprogress!(true)
df = @pipe HTTP.get("https://github.com/selva86/datasets/blob/master/mpg_ggplot2.csv?raw=TRUE").body |>
CSV.read(_, DataFrame)
#### Data Prep ####
idx_map = Dict(key => idx for (idx, key) in enumerate(unique(df.class)))
y = df[:, :hwy]
idx = getindex.(Ref(idx_map), df.class)
X = Matrix(select(df, [:displ, :year])) # the model matrix
### NCP Varying Intercept Model ####
@model varying_intercept_ncp(X, idx, y; n_gr=length(unique(idx)), predictors=size(X, 2)) = begin
# priors
μ ~ Normal(mean(y), 2.5 * std(y)) # population-level intercept
σ ~ Exponential(1 / std(y)) # residual SD
# Coefficients Student-t(ν = 3)
β ~ filldist(TDist(3), predictors)
# Prior for variance of random intercepts. Usually requires thoughtful specification.
σⱼ ~ Truncated(Cauchy(0, 2), 0, Inf)
zⱼ ~ filldist(Normal(0, 1), n_gr) # NCP group-level intercepts
# likelihood
ŷ = μ .+ X * β .+ zⱼ[idx] .* σⱼ
y ~ MvNormal(ŷ, σ)
end
model_ncp = varying_intercept_ncp(X, idx, y)
Turing.setadbackend(:zygote)
chn_zygote = sample(model_ncp, NUTS(1_000, 0.65), 2_000) I get this error:
Seems related with the Truncated Cauchy in the model: σⱼ ~ Truncated(Cauchy(0, 2), 0, Inf) [fce5fe82] Turing v0.15.1
[e88e6eb3] Zygote v0.6.3 |
Zygote does not allow to differentiate through try-catch-blocks, and therefore also not if there are logging statements such as As a general rule, one should use |
Changed to σⱼ ~ truncated(Cauchy(0, 2), 0, Inf) But still getting: julia> @time chn_zygote = sample(model_ncp, NUTS(1_000, 0.65), MCMCThreads(), 2_000, 4)
ERROR: LoadError: TaskFailedException
nested task error: TaskFailedException
Stacktrace:
[1] wait
@ ./task.jl:317 [inlined]
[2] threading_run(func::Function)
@ Base.Threads ./threadingconstructs.jl:34
[3] macro expansion
@ ./threadingconstructs.jl:93 [inlined]
[4] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:271 [inlined]
[5] (::AbstractMCMC.var"#31#44"{Bool, Base.Iterators.Pairs{Symbol, UnionAll, Tuple{Symbol}, NamedTuple{(:chain_type,), Tuple{UnionAll}}}, Int64, Int64, Vector{Any}, Vector{UInt64}, Vector{DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}}, Vector{DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}}, Vector{Random._GLOBAL_RNG}})()
@ AbstractMCMC ./task.jl:406
nested task error: InexactError: Int64(0.008583690987124463)
Stacktrace:
[1] Int64
@ ./float.jl:723 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] _backvar(xs::Vector{Int64}, Δ::Float64, N::Int64, mean::Float64)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/lib/array.jl:315
[4] _backvar
@ ~/.julia/packages/Zygote/KpME9/src/lib/array.jl:314 [inlined]
[5] #627
@ ~/.julia/packages/Zygote/KpME9/src/lib/array.jl:319 [inlined]
[6] (::Zygote.var"#2763#back#629"{Zygote.var"#627#628"{Bool, Colon, Float64, Vector{Int64}, Float64}})(Δ::Float64)
@ Zygote ~/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:59
[7] Pullback
@ ~/Documents/Julia_Scripts/Turing/Turing_hierarchical.jl:47 [inlined]
[8] (::typeof(∂(#17)))(Δ::Nothing)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface2.jl:0
[9] macro expansion
@ ~/.julia/packages/DynamicPPL/wf0dU/src/model.jl:0 [inlined]
[10] Pullback
@ ~/.julia/packages/DynamicPPL/wf0dU/src/model.jl:154 [inlined]
[11] (::typeof(∂(_evaluate)))(Δ::Nothing)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface2.jl:0
[12] Pullback
@ ~/.julia/packages/DynamicPPL/wf0dU/src/model.jl:144 [inlined]
[13] (::typeof(∂(evaluate_threadsafe)))(Δ::Nothing)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface2.jl:0
[14] Pullback
@ ~/.julia/packages/DynamicPPL/wf0dU/src/model.jl:94 [inlined]
[15] (::typeof(∂(λ)))(Δ::Nothing)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface2.jl:0
[16] #151
@ ~/.julia/packages/Zygote/KpME9/src/lib/lib.jl:191 [inlined]
[17] #1682#back
@ ~/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:59 [inlined]
[18] Pullback
@ ~/.julia/packages/DynamicPPL/wf0dU/src/model.jl:98 [inlined]
[19] Pullback
@ ~/.julia/packages/Turing/uAz5c/src/core/ad.jl:165 [inlined]
[20] (::typeof(∂(λ)))(Δ::Int64)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface2.jl:0
[21] (::Zygote.var"#41#42"{typeof(∂(λ))})(Δ::Int64)
@ Zygote ~/.julia/packages/Zygote/KpME9/src/compiler/interface.jl:40
[22] gradient_logp(backend::Turing.Core.ZygoteAD, θ::Vector{Float64}, vi::DynamicPPL.TypedVarInfo{NamedTuple{(:μ, :σ, :β, :σⱼ, :zⱼ), Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:μ, Tuple{}}, Int64}, Vector{Normal{Float64}}, Vector{DynamicPPL.VarName{:μ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σ, Tuple{}}, Int64}, Vector{Exponential{Float64}}, Vector{DynamicPPL.VarName{:σ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:β, Tuple{}}, Int64}, Vector{Product{Continuous, TDist{Float64}, FillArrays.Fill{TDist{Float64}, 1, Tuple{Base.OneTo{Int64}}}}}, Vector{DynamicPPL.VarName{:β, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σⱼ, Tuple{}}, Int64}, Vector{Truncated{Cauchy{Float64}, Continuous, Float64}}, Vector{DynamicPPL.VarName{:σⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:zⱼ, Tuple{}}, Int64}, Vector{DistributionsAD.TuringScalMvNormal{Vector{Float64}, Float64}}, Vector{DynamicPPL.VarName{:zⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, sampler::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, context::DynamicPPL.DefaultContext)
@ Turing.Core ~/.julia/packages/Turing/uAz5c/src/core/ad.jl:171
[23] gradient_logp
@ ~/.julia/packages/Turing/uAz5c/src/core/ad.jl:83 [inlined]
[24] ∂logπ∂θ
@ ~/.julia/packages/Turing/uAz5c/src/inference/hmc.jl:482 [inlined]
[25] ∂H∂θ
@ ~/.julia/packages/AdvancedHMC/MIxdK/src/hamiltonian.jl:31 [inlined]
[26] phasepoint
@ ~/.julia/packages/AdvancedHMC/MIxdK/src/hamiltonian.jl:69 [inlined]
[27] phasepoint(rng::Random._GLOBAL_RNG, θ::Vector{Float64}, h::AdvancedHMC.Hamiltonian{AdvancedHMC.DiagEuclideanMetric{Float64, Vector{Float64}}, Turing.Inference.var"#logπ#52"{DynamicPPL.TypedVarInfo{NamedTuple{(:μ, :σ, :β, :σⱼ, :zⱼ), Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:μ, Tuple{}}, Int64}, Vector{Normal{Float64}}, Vector{DynamicPPL.VarName{:μ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σ, Tuple{}}, Int64}, Vector{Exponential{Float64}}, Vector{DynamicPPL.VarName{:σ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:β, Tuple{}}, Int64}, Vector{Product{Continuous, TDist{Float64}, FillArrays.Fill{TDist{Float64}, 1, Tuple{Base.OneTo{Int64}}}}}, Vector{DynamicPPL.VarName{:β, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σⱼ, Tuple{}}, Int64}, Vector{Truncated{Cauchy{Float64}, Continuous, Float64}}, Vector{DynamicPPL.VarName{:σⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:zⱼ, Tuple{}}, Int64}, Vector{DistributionsAD.TuringScalMvNormal{Vector{Float64}, Float64}}, Vector{DynamicPPL.VarName{:zⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}, DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}}, Turing.Inference.var"#∂logπ∂θ#51"{DynamicPPL.TypedVarInfo{NamedTuple{(:μ, :σ, :β, :σⱼ, :zⱼ), Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:μ, Tuple{}}, Int64}, Vector{Normal{Float64}}, Vector{DynamicPPL.VarName{:μ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σ, Tuple{}}, Int64}, Vector{Exponential{Float64}}, Vector{DynamicPPL.VarName{:σ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:β, Tuple{}}, Int64}, Vector{Product{Continuous, TDist{Float64}, FillArrays.Fill{TDist{Float64}, 1, Tuple{Base.OneTo{Int64}}}}}, Vector{DynamicPPL.VarName{:β, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σⱼ, Tuple{}}, Int64}, Vector{Truncated{Cauchy{Float64}, Continuous, Float64}}, Vector{DynamicPPL.VarName{:σⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:zⱼ, Tuple{}}, Int64}, Vector{DistributionsAD.TuringScalMvNormal{Vector{Float64}, Float64}}, Vector{DynamicPPL.VarName{:zⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}, DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}}})
@ AdvancedHMC ~/.julia/packages/AdvancedHMC/MIxdK/src/hamiltonian.jl:139
[28] initialstep(rng::Random._GLOBAL_RNG, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, spl::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, vi::DynamicPPL.TypedVarInfo{NamedTuple{(:μ, :σ, :β, :σⱼ, :zⱼ), Tuple{DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:μ, Tuple{}}, Int64}, Vector{Normal{Float64}}, Vector{DynamicPPL.VarName{:μ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σ, Tuple{}}, Int64}, Vector{Exponential{Float64}}, Vector{DynamicPPL.VarName{:σ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:β, Tuple{}}, Int64}, Vector{Product{Continuous, TDist{Float64}, FillArrays.Fill{TDist{Float64}, 1, Tuple{Base.OneTo{Int64}}}}}, Vector{DynamicPPL.VarName{:β, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:σⱼ, Tuple{}}, Int64}, Vector{Truncated{Cauchy{Float64}, Continuous, Float64}}, Vector{DynamicPPL.VarName{:σⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{DynamicPPL.VarName{:zⱼ, Tuple{}}, Int64}, Vector{DistributionsAD.TuringScalMvNormal{Vector{Float64}, Float64}}, Vector{DynamicPPL.VarName{:zⱼ, Tuple{}}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}; init_params::Nothing, nadapts::Int64, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Turing.Inference ~/.julia/packages/Turing/uAz5c/src/inference/hmc.jl:174
[29] step(rng::Random._GLOBAL_RNG, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, spl::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}; resume_from::Nothing, kwargs::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:nadapts,), Tuple{Int64}}})
@ DynamicPPL ~/.julia/packages/DynamicPPL/wf0dU/src/sampler.jl:83
[30] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:78 [inlined]
[31] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/logging.jl:15 [inlined]
[32] mcmcsample(rng::Random._GLOBAL_RNG, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, sampler::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, N::Int64; progress::Bool, progressname::String, callback::Nothing, discard_initial::Int64, thinning::Int64, chain_type::Type, kwargs::Base.Iterators.Pairs{Symbol, Int64, Tuple{Symbol}, NamedTuple{(:nadapts,), Tuple{Int64}}})
@ AbstractMCMC ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:76
[33] #sample#40
@ ~/.julia/packages/Turing/uAz5c/src/inference/hmc.jl:140 [inlined]
[34] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:280 [inlined]
[35] (::AbstractMCMC.var"#819#threadsfor_fun#45"{UnitRange{Int64}, Bool, Base.Iterators.Pairs{Symbol, UnionAll, Tuple{Symbol}, NamedTuple{(:chain_type,), Tuple{UnionAll}}}, Int64, Vector{Any}, Vector{UInt64}, Vector{DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}}, Vector{DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}}, Vector{Random._GLOBAL_RNG}})(onethread::Bool)
@ AbstractMCMC ./threadingconstructs.jl:81
[36] (::AbstractMCMC.var"#819#threadsfor_fun#45"{UnitRange{Int64}, Bool, Base.Iterators.Pairs{Symbol, UnionAll, Tuple{Symbol}, NamedTuple{(:chain_type,), Tuple{UnionAll}}}, Int64, Vector{Any}, Vector{UInt64}, Vector{DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}}, Vector{DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}}, Vector{Random._GLOBAL_RNG}})()
@ AbstractMCMC ./threadingconstructs.jl:48
Stacktrace:
[1] sync_end(c::Channel{Any})
@ Base ./task.jl:364
[2] macro expansion
@ ./task.jl:383 [inlined]
[3] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:257 [inlined]
[4] macro expansion
@ ~/.julia/packages/ProgressLogging/6KXlp/src/ProgressLogging.jl:328 [inlined]
[5] macro expansion
@ ~/.julia/packages/AbstractMCMC/Nw3Wn/src/logging.jl:8 [inlined]
[6] mcmcsample(rng::Random._GLOBAL_RNG, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, sampler::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, ::MCMCThreads, N::Int64, nchains::Int64; progress::Bool, progressname::String, kwargs::Base.Iterators.Pairs{Symbol, UnionAll, Tuple{Symbol}, NamedTuple{(:chain_type,), Tuple{UnionAll}}})
@ AbstractMCMC ~/.julia/packages/AbstractMCMC/Nw3Wn/src/sample.jl:251
[7] sample(rng::Random._GLOBAL_RNG, model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, sampler::DynamicPPL.Sampler{NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}}, parallel::MCMCThreads, N::Int64, n_chains::Int64; chain_type::Type, progress::Bool, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ Turing.Inference ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:217
[8] sample
@ ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:217 [inlined]
[9] #sample#6
@ ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:202 [inlined]
[10] sample
@ ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:202 [inlined]
[11] #sample#5
@ ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:189 [inlined]
[12] sample(model::DynamicPPL.Model{var"#17#18", (:X, :idx, :y, :n_gr, :predictors), (:n_gr, :predictors), (), Tuple{Matrix{Float64}, Vector{Int64}, Vector{Int64}, Int64, Int64}, Tuple{Int64, Int64}}, alg::NUTS{Turing.Core.ZygoteAD, (), AdvancedHMC.DiagEuclideanMetric}, parallel::MCMCThreads, N::Int64, n_chains::Int64)
@ Turing.Inference ~/.julia/packages/Turing/uAz5c/src/inference/Inference.jl:189
[13] top-level scope
@ ./timing.jl:206 [inlined]
[14] top-level scope
@ ~/Documents/Julia_Scripts/Turing/Turing_hierarchical.jl:0
in expression starting at /Users/storopoli/Documents/Julia_Scripts/Turing/Turing_hierarchical.jl:68 |
That's a different error though. Seems Zygote tries to differentiate some integer-valued variable(s) which fails due to type errors (floating point number can't be converted to an integer). I can't run your example right now, so it's a bit difficult for me to debug it in more detail - maybe it's related to |
Yes! You are definitely right! The |
Howdy all,
I am trying to get Tracker and/or Zygote to work with a multilevel model, but unfortunately I get an error message when I try. Tracker works fine with a varying intercept model, but not with a varying slope model. Zygote does not seem to work with either.
The code below is a reproducible example (modified slightly to use the sleepstudy dataset). It runs faster using forwarddiff than it does using Tracker, but hopefully it will get my point across.
When I run the code using Tracker for the varying slopes model, I get the following error message:
If I try Zygote with either model, I get the following error:
I'm not sure if it is a bug, my poor coding, or both. Hopefully it's not a bug.
Any advice is welcome.
The text was updated successfully, but these errors were encountered: