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

BoundsError in Turing test suite on Julia v1.11.1 #315

Open
mhauru opened this issue Oct 25, 2024 · 21 comments
Open

BoundsError in Turing test suite on Julia v1.11.1 #315

mhauru opened this issue Oct 25, 2024 · 21 comments

Comments

@mhauru
Copy link
Contributor

mhauru commented Oct 25, 2024

A Turing CI run fails with the following:

hmcda+gibbs inference: Error During Test at /home/runner/work/Turing.jl/Turing.jl/test/mcmc/hmc.jl:145
  Got exception outside of a @test
  BoundsError: attempt to access MemoryRef{Mooncake.NoTangent} at index [14]
  Stacktrace:
    [1] rrule!!
      @ ~/.julia/packages/Mooncake/LKJK9/src/rrules/memory.jl:291 [inlined]
    [2] ht_keyindex2_shorthash!
      @ ./dict.jl:266 [inlined]
    [3] (::Tuple{Mooncake.Stack{Int32}, Base.RefValue{Tuple{Mooncake.LazyZeroRData{typeof(Base.ht_keyindex2_shorthash!), Nothing}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}, Mooncake.LazyZeroRData{DynamicPPL.Selector, Nothing}}}, Mooncake.RRuleZeroWrapper{Mooncake.LazyDerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, Mooncake.DerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.rehash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{Int64, Mooncake.NoFData}}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}}, Mooncake.RRuleZeroWrapper{Mooncake.LazyDerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, Mooncake.DerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.rehash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{Int64, Mooncake.NoFData}}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}}, Mooncake.LazyDerivedRule{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, Mooncake.DerivedRule{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.ht_keyindex2_shorthash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData}}, Mooncake.CoDual{Tuple{Int64, UInt8}, Mooncake.NoFData}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.RRuleWrapperPb{Mooncake.Pullback{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:maxprobe, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.var"#setfield!_pullback#488"{:maxprobe, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, Int64}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.RRuleWrapperPb{Mooncake.Pullback{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}}, Mooncake.Pullback{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}}}})(none::Mooncake.CoDual{typeof(Base.ht_keyindex2_shorthash!), Mooncake.NoFData}, none::Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, none::Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData})
      @ Base.Experimental ./<missing>:0
    [4] (::MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.ht_keyindex2_shorthash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData}}, Mooncake.CoDual{Tuple{Int64, UInt8}, Mooncake.NoFData}}})(::Mooncake.CoDual{typeof(Base.ht_keyindex2_shorthash!), Mooncake.NoFData}, ::Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, ::Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData})
      @ MistyClosures ~/.julia/packages/MistyClosures/4rFSA/src/MistyClosures.jl:22
    [5] DerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:745 [inlined]
    [6] LazyDerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:1490 [inlined]
    [7] setindex!
      @ ./dict.jl:355 [inlined]
    [8] (::Tuple{Mooncake.Stack{Int32}, Base.RefValue{Tuple{Mooncake.LazyZeroRData{typeof(setindex!), Nothing}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}, Mooncake.LazyZeroRData{Nothing, Nothing}, Mooncake.LazyZeroRData{DynamicPPL.Selector, Nothing}}}, Mooncake.LazyDerivedRule{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, Mooncake.DerivedRule{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.ht_keyindex2_shorthash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData}}, Mooncake.CoDual{Tuple{Int64, UInt8}, Mooncake.NoFData}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}, Mooncake.RRuleZeroWrapper{Mooncake.LazyDerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, Mooncake.DerivedRule{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(Base.rehash!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{Int64, Mooncake.NoFData}}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}}, Mooncake.Stack{Tuple{Mooncake.Pullback{Tuple{typeof(Base.ht_keyindex2_shorthash!), Dict{DynamicPPL.Selector, Nothing}, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:age, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#setfield!_pullback#488"{:age, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, UInt64}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefset_adjoint#526"{Mooncake.CoDual{MemoryRef{DynamicPPL.Selector}, MemoryRef{Mooncake.NoTangent}}, MemoryRef{Mooncake.NoTangent}, Base.RefValue{Tuple{DynamicPPL.Selector, Mooncake.NoTangent}}, Bool, Val{false}, Val{:not_atomic}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:vals, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#isbits_lmemoryrefset!_adjoint#527"{Mooncake.CoDual{MemoryRef{Nothing}, MemoryRef{Mooncake.NoTangent}}, Val{:not_atomic}, Val{false}, Tuple{Nothing, Mooncake.NoTangent}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:ndel, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.NoTangent}, Val{false}, Val{:not_atomic}}, Mooncake.var"#setfield!_pullback#488"{:ndel, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, Int64}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:slots, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#isbits_lmemoryrefset!_adjoint#527"{Mooncake.CoDual{MemoryRef{UInt8}, MemoryRef{Mooncake.NoTangent}}, Val{:not_atomic}, Val{false}, Tuple{UInt8, Mooncake.NoTangent}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#lmemoryrefset_adjoint#526"{Mooncake.CoDual{MemoryRef{DynamicPPL.Selector}, MemoryRef{Mooncake.NoTangent}}, MemoryRef{Mooncake.NoTangent}, Base.RefValue{Tuple{DynamicPPL.Selector, Mooncake.NoTangent}}, Bool, Val{false}, Val{:not_atomic}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:vals, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#isbits_lmemoryrefset!_adjoint#527"{Mooncake.CoDual{MemoryRef{Nothing}, MemoryRef{Mooncake.NoTangent}}, Val{:not_atomic}, Val{false}, Tuple{Nothing, Mooncake.NoTangent}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#setfield!_pullback#488"{:count, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, Int64}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:age, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#setfield!_pullback#488"{:age, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, UInt64}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:idxfloor, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#setfield!_pullback#488"{:idxfloor, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, Mooncake.NoTangent, Int64}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:keys, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.var"#mutable_lgetfield_pb!!#483"{:ndel, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.var"#mutable_lgetfield_pb!!#483"{:count, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.Stack{Tuple{Mooncake.RRuleWrapperPb{Mooncake.Pullback{Tuple{typeof(Base.rehash!), Dict{DynamicPPL.Selector, Nothing}, Int64}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}}}}})(none::Mooncake.CoDual{typeof(setindex!), Mooncake.NoFData}, none::Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, none::Mooncake.CoDual{Nothing, Mooncake.NoFData}, none::Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData})
      @ Base.Experimental ./<missing>:0
    [9] (::MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(setindex!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{Nothing, Mooncake.NoFData}, Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData}}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}})(::Mooncake.CoDual{typeof(setindex!), Mooncake.NoFData}, ::Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, ::Mooncake.CoDual{Nothing, Mooncake.NoFData}, ::Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData})
      @ MistyClosures ~/.julia/packages/MistyClosures/4rFSA/src/MistyClosures.jl:22
   [10] DerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:745 [inlined]
   [11] LazyDerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:1490 [inlined]
   [12] RRuleZeroWrapper
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:253 [inlined]
   [13] tilde_assume
      @ ~/work/Turing.jl/Turing.jl/src/mcmc/gibbs.jl:57 [inlined]
   [14] (::Tuple{Mooncake.Stack{Int32}, Base.RefValue{Tuple{Mooncake.LazyZeroRData{typeof(DynamicPPL.tilde_assume), Nothing}, Mooncake.LazyZeroRData{Random.TaskLocalRNG, Nothing}, Mooncake.LazyZeroRData{Turing.Inference.GibbsContext{OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, DynamicPPL.DefaultContext}, Nothing}, Mooncake.LazyZeroRData{DynamicPPL.Sampler{Turing.Inference.HMCDA{ADTypes.AutoMooncake{Nothing}, (), AdvancedHMC.UnitEuclideanMetric}}, Nothing}, Mooncake.LazyZeroRData{Distributions.Normal{Float64}, Nothing}, Mooncake.LazyZeroRData{AbstractPPL.VarName{:m, typeof(identity)}, Nothing}, Mooncake.LazyZeroRData{DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, Nothing}}}, Mooncake.LazyDerivedRule{Tuple{typeof(DynamicPPL.hasvalue), OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}}, Mooncake.DerivedRule{Tuple{typeof(DynamicPPL.hasvalue), OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(DynamicPPL.hasvalue), Mooncake.NoFData}, Mooncake.CoDual{OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, Mooncake.MutableTangent{@NamedTuple{slots::Vector{Mooncake.NoTangent}, keys::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, ndel::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent, dirty::Mooncake.NoTangent}}}, Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}}, Mooncake.CoDual{Bool, Mooncake.NoFData}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}, Mooncake.LazyDerivedRule{Tuple{typeof(getindex), Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, AbstractPPL.VarName{:m, typeof(identity)}}, Mooncake.DerivedRule{Tuple{typeof(getindex), Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(getindex), Mooncake.NoFData}, Mooncake.CoDual{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}}, Mooncake.CoDual{Int64, Mooncake.NoFData}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}, Mooncake.RRuleZeroWrapper{Mooncake.LazyDerivedRule{Tuple{typeof(setindex!), Dict{DynamicPPL.Selector, Nothing}, Nothing, DynamicPPL.Selector}, Mooncake.DerivedRule{Tuple{typeof(setindex!), Dict{DynamicPPL.Selector, Nothing}, Nothing, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(setindex!), Mooncake.NoFData}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}, Mooncake.CoDual{Nothing, Mooncake.NoFData}, Mooncake.CoDual{DynamicPPL.Selector, Mooncake.NoFData}}, Mooncake.CoDual{Dict{DynamicPPL.Selector, Nothing}, Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, NTuple{4, Mooncake.NoRData}}}, Val{false}, Val{4}}}}, Mooncake.LazyDerivedRule{Tuple{typeof(DynamicPPL.getindex_internal), DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, AbstractPPL.VarName{:m, typeof(identity)}}, Mooncake.DerivedRule{Tuple{typeof(DynamicPPL.getindex_internal), DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(DynamicPPL.getindex_internal), Mooncake.NoFData}, Mooncake.CoDual{DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}}, Mooncake.CoDual{Vector{Float64}, Vector{Float64}}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{3}}}, Mooncake.LazyDerivedRule{Tuple{typeof(DynamicPPL.invlink_with_logpdf), DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}, Distributions.Normal{Float64}, Vector{Float64}}, Mooncake.DerivedRule{Tuple{typeof(DynamicPPL.invlink_with_logpdf), DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}, Distributions.Normal{Float64}, Vector{Float64}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(DynamicPPL.invlink_with_logpdf), Mooncake.NoFData}, Mooncake.CoDual{DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, Mooncake.FData{@NamedTuple{metadata::@NamedTuple{m::Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, logp::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Float64}}}, num_produce::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}}}, Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}, Mooncake.CoDual{Distributions.Normal{Float64}, Mooncake.NoFData}, Mooncake.CoDual{Vector{Float64}, Vector{Float64}}}, Mooncake.CoDual{Tuple{Float64, Float64}, Mooncake.NoFData}}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData, Mooncake.RData{@NamedTuple{μ::Float64, σ::Float64}}, Mooncake.NoRData}}}, Val{false}, Val{5}}}, Mooncake.Stack{Tuple{Mooncake.Pullback{Tuple{typeof(DynamicPPL.hasvalue), OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}}}, Mooncake.Stack{Tuple{Mooncake.Pullback{Tuple{typeof(getindex), Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}}}, Mooncake.Stack{Tuple{Any}}, Mooncake.Stack{Tuple{Mooncake.var"#lmemoryrefget_adjoint#524"{MemoryRef{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, Val{false}, Val{:not_atomic}}}}, Mooncake.Stack{Tuple{Mooncake.RRuleWrapperPb{Mooncake.Pullback{Tuple{typeof(setindex!), Dict{DynamicPPL.Selector, Nothing}, Nothing, DynamicPPL.Selector}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, NTuple{4, Mooncake.NoRData}}}, Val{false}, Val{1}}, Mooncake.LazyZeroRData{Dict{DynamicPPL.Selector, Nothing}, Nothing}}}}, Mooncake.Stack{Tuple{Mooncake.Pullback{Tuple{typeof(DynamicPPL.getindex_internal), DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, AbstractPPL.VarName{:m, typeof(identity)}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.NoRData}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData}}}, Val{false}, Val{1}}, Mooncake.Pullback{Tuple{typeof(DynamicPPL.invlink_with_logpdf), DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, AbstractPPL.VarName{:m, typeof(identity)}, Distributions.Normal{Float64}, Vector{Float64}}, MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Tuple{Float64, Float64}}, Tuple{Mooncake.NoRData, Mooncake.NoRData, Mooncake.NoRData, Mooncake.RData{@NamedTuple{μ::Float64, σ::Float64}}, Mooncake.NoRData}}}, Val{false}, Val{1}}}}})(none::Mooncake.CoDual{typeof(DynamicPPL.tilde_assume), Mooncake.NoFData}, none::Mooncake.CoDual{Random.TaskLocalRNG, Mooncake.NoFData}, none::Mooncake.CoDual{Turing.Inference.GibbsContext{OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, DynamicPPL.DefaultContext}, Mooncake.FData{@NamedTuple{values::Mooncake.MutableTangent{@NamedTuple{slots::Vector{Mooncake.NoTangent}, keys::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, ndel::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent, dirty::Mooncake.NoTangent}}, context::Mooncake.NoFData}}}, none::Mooncake.CoDual{DynamicPPL.Sampler{Turing.Inference.HMCDA{ADTypes.AutoMooncake{Nothing}, (), AdvancedHMC.UnitEuclideanMetric}}, Mooncake.NoFData}, none::Mooncake.CoDual{Distributions.Normal{Float64}, Mooncake.NoFData}, none::Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}, none::Mooncake.CoDual{DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, Mooncake.FData{@NamedTuple{metadata::@NamedTuple{m::Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, logp::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Float64}}}, num_produce::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}}})
      @ Base.Experimental ./<missing>:0
   [15] (::MistyClosures.MistyClosure{Core.OpaqueClosure{Tuple{Mooncake.CoDual{typeof(DynamicPPL.tilde_assume), Mooncake.NoFData}, Mooncake.CoDual{Random.TaskLocalRNG, Mooncake.NoFData}, Mooncake.CoDual{Turing.Inference.GibbsContext{OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, DynamicPPL.DefaultContext}, Mooncake.FData{@NamedTuple{values::Mooncake.MutableTangent{@NamedTuple{slots::Vector{Mooncake.NoTangent}, keys::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, ndel::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent, dirty::Mooncake.NoTangent}}, context::Mooncake.NoFData}}}, Mooncake.CoDual{DynamicPPL.Sampler{Turing.Inference.HMCDA{ADTypes.AutoMooncake{Nothing}, (), AdvancedHMC.UnitEuclideanMetric}}, Mooncake.NoFData}, Mooncake.CoDual{Distributions.Normal{Float64}, Mooncake.NoFData}, Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}, Mooncake.CoDual{DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, Mooncake.FData{@NamedTuple{metadata::@NamedTuple{m::Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, logp::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Float64}}}, num_produce::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}}}}, Mooncake.CoDual{Tuple{Float64, Float64, DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}}, Tuple{Mooncake.NoFData, Mooncake.NoFData, Mooncake.FData{@NamedTuple{metadata::@NamedTuple{m::Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, logp::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Float64}}}, num_produce::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}}}}}})(::Mooncake.CoDual{typeof(DynamicPPL.tilde_assume), Mooncake.NoFData}, ::Mooncake.CoDual{Random.TaskLocalRNG, Mooncake.NoFData}, ::Mooncake.CoDual{Turing.Inference.GibbsContext{OrderedCollections.OrderedDict{AbstractPPL.VarName{:s, typeof(identity)}, Float64}, DynamicPPL.DefaultContext}, Mooncake.FData{@NamedTuple{values::Mooncake.MutableTangent{@NamedTuple{slots::Vector{Mooncake.NoTangent}, keys::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, ndel::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent, dirty::Mooncake.NoTangent}}, context::Mooncake.NoFData}}}, ::Mooncake.CoDual{DynamicPPL.Sampler{Turing.Inference.HMCDA{ADTypes.AutoMooncake{Nothing}, (), AdvancedHMC.UnitEuclideanMetric}}, Mooncake.NoFData}, ::Mooncake.CoDual{Distributions.Normal{Float64}, Mooncake.NoFData}, ::Mooncake.CoDual{AbstractPPL.VarName{:m, typeof(identity)}, Mooncake.NoFData}, ::Mooncake.CoDual{DynamicPPL.TypedVarInfo{@NamedTuple{m::DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:m, typeof(identity)}, Int64}, Vector{Distributions.Normal{Float64}}, Vector{AbstractPPL.VarName}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}}, Float64}, Mooncake.FData{@NamedTuple{metadata::@NamedTuple{m::Mooncake.FData{@NamedTuple{idcs::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}, vns::Vector{Any}, ranges::Vector{Mooncake.NoTangent}, vals::Vector{Float64}, dists::Vector{Mooncake.Tangent{@NamedTuple{μ::Float64, σ::Float64}}}, gids::Vector{Mooncake.Tangent{@NamedTuple{dict::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.NoTangent}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, orders::Vector{Mooncake.NoTangent}, flags::Mooncake.MutableTangent{@NamedTuple{slots::Memory{Mooncake.NoTangent}, keys::Memory{Mooncake.NoTangent}, vals::Memory{Mooncake.MutableTangent{@NamedTuple{chunks::Vector{Mooncake.NoTangent}, len::Mooncake.NoTangent, dims::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}, ndel::Mooncake.NoTangent, count::Mooncake.NoTangent, age::Mooncake.NoTangent, idxfloor::Mooncake.NoTangent, maxprobe::Mooncake.NoTangent}}}}}, logp::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Float64}}}, num_produce::Mooncake.MutableTangent{@NamedTuple{x::Mooncake.PossiblyUninitTangent{Mooncake.NoTangent}}}}}})
      @ MistyClosures ~/.julia/packages/MistyClosures/4rFSA/src/MistyClosures.jl:22
   [16] DerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:745 [inlined]
   [17] LazyDerivedRule
      @ ~/.julia/packages/Mooncake/LKJK9/src/interpreter/s2s_reverse_mode_ad.jl:1490 [inlined]
   [18] gdemo_d
      @ ~/work/Turing.jl/Turing.jl/test/test_utils/models.jl:23 [inlined]

[ETC., THERE'S LOTS MORE]

The test passes for me locally, also on v1.11.1. To save time, I skipped running the preceding tests though, so if this is random seed dependent then that would explain why it worked for me locally.

@willtebbutt willtebbutt added the bug Something isn't working label Oct 25, 2024
@willtebbutt
Copy link
Member

There is something going on with the underlying Memorys here. If you look at the rule in which the error is thrown, you'll see that we've somehow wound up in a situation whereby the primal and fdata Memorys / MemoryRefs are out of sync with one another. I believe that it must be the case that either

  1. the two underlying Memorys are of different lengths, or
  2. the two MemoryRefs point to different locations in their respective Memorys.

Figuring out how this happened should be possible using debug mode, but I might need to update it with some checks for Memory and MemoryRefs.

@mhauru
Copy link
Contributor Author

mhauru commented Oct 25, 2024

Now managing to reproduce locally by checking out the latest commit (6f5b273dfa1d21548758d986e5710c3e72524195) from TuringLang/Turing.jl#2328 and running

module MWE

using Distributions: Normal, sample
import Random
using StableRNGs: StableRNG
import Mooncake
using Turing

@model function gdemo_d()
    s ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s))
    1.5 ~ Normal(m, sqrt(s))
    2.0 ~ Normal(m, sqrt(s))
    return s, m
end

gdemo_default = gdemo_d()

adbackend = Turing.AutoMooncake(; config=nothing)
rng = StableRNG(123)
Random.seed!(12345) # particle samplers do not support user-provided `rng` yet
alg3 = Gibbs(; s=PG(20), m=HMCDA(500, 0.8, 0.25; init_ϵ=0.05, adtype=adbackend))
res3 = sample(rng, gdemo_default, alg3, 3000, discard_initial=1000)

end

with Julia v1.11.1

@willtebbutt
Copy link
Member

This will make debugging vastly easier. Thank you!

@willtebbutt
Copy link
Member

I don't seem to be able to replicate. My Project status is:

(jl_7S59v2) pkg> st
Status `/private/var/folders/8p/znj24dc50hq6dbkbskbfg8680000gs/T/jl_7S59v2/Project.toml`
  [31c24e10] Distributions v0.25.112
  [da2b9cff] Mooncake v0.4.24
  [860ef19b] StableRNGs v1.0.2
  [fce5fe82] Turing v0.36.0 `../../../../../../../Users/wtebbutt/.julia/dev/Turing`
  [9a3f8284] Random v1.11.0

Could you share yours so that we can find the discrepancy?

@yebai
Copy link
Contributor

yebai commented Oct 25, 2024

I suspect this is related to Libtask’s mechanism for deep copying arrays.

@willtebbutt
Copy link
Member

Could you elaborate a bit on this @yebai / could you point me towards the bit of Libtask that you think is a likely candidate for causing these problems?

@mhauru
Copy link
Contributor Author

mhauru commented Oct 25, 2024

Mine is a bit messier, it's the one I run Turing tests in:

(jl_qMot4L) pkg> st
Status `/private/var/folders/wk/zmsrlr9s2cgdpdnqj5d522sw0000gr/T/jl_qMot4L/Project.toml`
  [80f14c24] AbstractMCMC v5.5.0
  [5b7e9947] AdvancedMH v0.8.3
  [576499cb] AdvancedPS v0.6.0
⌃ [b5ca4192] AdvancedVI v0.2.8
  [4c88cf16] Aqua v0.8.9
  [aaaa29a8] Clustering v0.15.7
  [31c24e10] Distributions v0.25.112
  [ced4e74d] DistributionsAD v0.6.57
  [bbc10e6e] DynamicHMC v3.4.7
  [366bfd00] DynamicPPL v0.30.1
  [26cc04aa] FiniteDifferences v0.12.32
  [f6369f11] ForwardDiff v0.10.36
  [09f84164] HypothesisTests v0.11.3
  [6fdf6af0] LogDensityProblems v2.1.2
  [996a588d] LogDensityProblemsAD v1.11.0
  [c7f686f2] MCMCChains v6.0.6
  [da2b9cff] Mooncake v0.4.24
  [86f7a689] NamedArrays v0.10.3
  [429524aa] Optim v1.9.4
  [7f7a1694] Optimization v4.0.3
  [3e6eede4] OptimizationBBO v0.4.0
  [4e6fcdb7] OptimizationNLopt v0.3.1
  [36348300] OptimizationOptimJL v0.4.1
  [90014a1f] PDMats v0.11.31
  [37e2e3b7] ReverseDiff v1.15.3
  [276daf66] SpecialFunctions v2.4.0
  [860ef19b] StableRNGs v1.0.2
  [2913bbd2] StatsBase v0.34.3
  [4c63d2b9] StatsFuns v1.3.2
  [a759f4b9] TimerOutputs v0.5.25
  [fce5fe82] Turing v0.36.0 `~/projects/Turing.jl`
  [e88e6eb3] Zygote v0.6.72
  [37e2e46d] LinearAlgebra v1.11.0
  [44cfe95a] Pkg v1.11.0
  [9a3f8284] Random v1.11.0
  [8dfed614] Test v1.11.0

That all seems in line with yours though. Any help from this?

julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 10 × Apple M1 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

I'm running

mhauru@403-Q4WFPXDFN0:~/projects/Turing.jl (mhauru/change-gibbs-sampler)$ julia  --color=yes --inline=yes --depwarn=yes --check-bounds=yes --threads=1 --project=@. -e "import TestEnv; TestEnv.activate()" -i

Some of the flags seem to be signifcant for this, not sure which.

~/projects/Turing.jl has no edits in the working directory and

mhauru@403-Q4WFPXDFN0:~/projects/Turing.jl (mhauru/change-gibbs-sampler)$ git log -1
commit 6f5b273dfa1d21548758d986e5710c3e72524195 (HEAD -> mhauru/change-gibbs-sampler, origin/mhauru/change-gibbs-sampler)
Merge: 1bd07945 08331c5e
Author: Markus Hauru <[email protected]>
Date:   Thu Oct 24 14:30:35 2024 +0100

    Merge remote-tracking branch 'origin/master' into mhauru/change-gibbs-sampler

@yebai
Copy link
Contributor

yebai commented Oct 25, 2024

I'm referring to the following code. I don't have a lot of evidence here, so the bug could be from other places (instead of Libtask).

https://github.com/TuringLang/Libtask.jl/blob/6264afd33f9441697d2f5ed4a75bbcc37f15feba/src/tapedfunction.jl#L467-L514

@willtebbutt
Copy link
Member

willtebbutt commented Oct 25, 2024

Thanks both.

@mhauru I'll try and again to reproduce locally.
@yebai thanks for the pointer -- I'll keep this in mind as a possibility while I'm debugging.

@mhauru
Copy link
Contributor Author

mhauru commented Oct 31, 2024

Here's a partial minimisation, need to attend to other things now, can continue tomorrow:

module MWE

using Distributions: Normal
using StableRNGs: StableRNG
import Mooncake
import LogDensityProblemsAD
import LogDensityProblems
import Turing
import DynamicPPL

function main()
    function gdemo_d(__model__, __varinfo__, __context__)
        _, __varinfo__ = DynamicPPL.tilde_assume!!(
            __context__, Normal(0, 1), DynamicPPL.@varname(m), __varinfo__
        )
        return nothing, __varinfo__
    end
    model = DynamicPPL.Model(gdemo_d, (;))

    adbackend = Turing.AutoMooncake(; config=nothing)
    rng = StableRNG(123)
    alg_local = Turing.HMCDA(500, 0.8, 0.25; init_ϵ=0.05, adtype=adbackend)

    sampler_local = DynamicPPL.Sampler(alg_local)

    vi_local = DynamicPPL.default_varinfo(rng, model, sampler_local)
    vi_local = DynamicPPL.link(vi_local, sampler_local, model)
    theta = vi_local[sampler_local]
    ℓ = LogDensityProblemsAD.ADgradient(
        Turing.LogDensityFunction(
            vi_local,
            model,
            DynamicPPL.SamplingContext(rng, sampler_local, DynamicPPL.DefaultContext()),
        ),
    )
    f(x) = LogDensityProblems.logdensity_and_gradient(ℓ, x)

    DynamicPPL.evaluate!!(
        model,
        vi_local,
        DynamicPPL.SamplingContext(rng, sampler_local),
    )
    f(theta)
    return nothing
end

main()

end

@willtebbutt
Copy link
Member

Thanks @mhauru -- this is helpful!

@willtebbutt
Copy link
Member

willtebbutt commented Nov 4, 2024

@mhauru could you confirm whether you're generating this error in Mooncake 0.4.32? Sadly, I'm struggling to reliably reproduce your example. It appears to be true that if I fix some specific bits of Mooncake, the problem goes away, but I'm also finding that if I switch between version 0.4.24 and 0.4.32 (neither of which contain said fix), the problem also disappears.

I basically just want to confirm that you're also seeing this somewhat mysterious behaviour.

@mhauru
Copy link
Contributor Author

mhauru commented Nov 4, 2024

Still seeing this on Mooncake v0.4.32. Or more precisely on

(mooncake_mwes) pkg> st
Status `~/projects/mooncake_mwes/Project.toml`
  [80f14c24] AbstractMCMC v5.6.0
  [7a57a42e] AbstractPPL v0.9.0
  [7d9f7c33] Accessors v0.1.38
  [0bf59076] AdvancedHMC v0.6.3
  [31c24e10] Distributions v0.25.112
  [366bfd00] DynamicPPL v0.30.2
  [6fdf6af0] LogDensityProblems v2.1.2
  [996a588d] LogDensityProblemsAD v1.12.0
  [da2b9cff] Mooncake v0.4.32
  [efcf1570] Setfield v1.1.1
  [ce78b400] SimpleUnPack v1.1.0
  [860ef19b] StableRNGs v1.0.2
  [fce5fe82] Turing v0.36.0 `https://github.com/TuringLang/Turing.jl.git#6f5b273`

Let me also get to the bottom of which Julia cmd line arguments are necessary.

@mhauru
Copy link
Contributor Author

mhauru commented Nov 4, 2024

It's the --check-bounds=yes. Without it the MWE passes fine.

@willtebbutt
Copy link
Member

Thanks for this -- I hadn't considered that the check-bounds flag might be necessary.

@willtebbutt
Copy link
Member

willtebbutt commented Nov 5, 2024

Okay, so I think I now understand what's going on here -- the order in which you execute stuff above really matters quite a bit. If you instead run:

module MWE

using Distributions: Normal
using StableRNGs: StableRNG
import Mooncake
import LogDensityProblemsAD
import LogDensityProblems
import Turing
import DynamicPPL

function main()
    function gdemo_d(__model__, __varinfo__, __context__)
        _, __varinfo__ = DynamicPPL.tilde_assume!!(
            __context__, Normal(0, 1), DynamicPPL.@varname(m), __varinfo__
        )
        return nothing, __varinfo__
    end
    model = DynamicPPL.Model(gdemo_d, (;))

    adbackend = Turing.AutoMooncake(; config=nothing)
    rng = StableRNG(123)
    alg_local = Turing.HMCDA(500, 0.8, 0.25; init_ϵ=0.05, adtype=adbackend)

    sampler_local = DynamicPPL.Sampler(alg_local)

    vi_local = DynamicPPL.default_varinfo(rng, model, sampler_local)
    vi_local = DynamicPPL.link(vi_local, sampler_local, model)
    theta = vi_local[sampler_local]

    # Happens before ADgradient is constructed.
    DynamicPPL.evaluate!!(
        model,
        vi_local,
        DynamicPPL.SamplingContext(rng, sampler_local),
    )

    # Happens after evaluate!! is called.= LogDensityProblemsAD.ADgradient(
        Turing.LogDensityFunction(
            vi_local,
            model,
            DynamicPPL.SamplingContext(rng, sampler_local, DynamicPPL.DefaultContext()),
        ),
    )
    f(x) = LogDensityProblems.logdensity_and_gradient(ℓ, x)
    f(theta)
    return nothing
end

main()

end

you'll find that it is error free.

Problem

What's going on in the original example is:

  1. ℓ = LogDensityProblemsAD.ADgradient(... pre-allocates the tangent memory associated to the field of the MooncakeLogDensityProblemsADExt.MooncakeGradientLogDensity object that calling ADgradient constructs. Mooncake relies on this pre-allocated memory remaining consistent with the data in the LogDensityFunction. I'll call this consistency property "primal-tangent consistency".
  2. The metadata fields of vi_local contain a variety of Dicts / Sets, which get mutated when the call to DyamicPPL.evaluate!! is made. This happens in a Mooncake-unaware manner, and breaks primal-tangent consistency.
  3. Finally, when we call f(theta), we see the result of this inconsistency. The particular error we are seeing is to do with some Memorys used internally inside Dicts (which are used to implement the Sets in metadata field of the varinfo) -- when the Sets / Dicts are modified in step 2, one of these Memory fields is replaced with a new (longer) Memory object, while the tangent field in the data pre-allocated in step 1 remains unchanged.

So the problem is that:

  1. Mooncake pre-allocates some state that has some internal state that must always satisfy certain properties.
  2. DynamicPPL.evaluate!! goes in and modifies this internal state in a way that messes up these properties.
  3. We then call Mooncake, and it errors because these properties do not hold.

When we change the ordering, the pre-allocation operations happen after the call to DynamicPPL.evaluate!! plays around with the state of the varinfo, meaning that nothing has perturbed the state of the varinfo before Mooncake is called, and everything runs fine.

Solution

There are a couple of possible solutions:

  1. Change the order in which things happen in this example. I don't know how you would feel about doing that. This doesn't really solve the underlying problem per-se, and we would still have the brittleness, but would definitely resolve this particular case.
  2. Do not pre-allocate memory when calling LogDensityProblemsAD.ADgradient -- always freshly allocate everything when we ask for the gradient. This would properly solve the problem, but would also be slow.
  3. Pre-allocate the memory the first time that we call LogDensityProblemsAD.ADgradient, and never re-allocate it. i.e. assume that, once you've started making calls to LogDensityProblemsAD.ADgradient, all access to the state associated to it is going to happen via Mooncake so there's no risk of the above problem happening.
  4. I could add a function to manually trigger synchronisation of the primal-tangent pair.

Any thoughts on this @mhauru ?

@mhauru
Copy link
Contributor Author

mhauru commented Nov 5, 2024

Just this morning I was hunting down a case in the same PR where this originated from, a case in which ForwardDiff was giving strange zero-division errors. The problem was that I was inadvertently first creating a LogDensityProblem with dimension 0, and then calling it with an argument that had a different dimension. I fixed that problem so that I'm no longer trying to evaluate a 0-dimensional LogDensityProblem with a non-0-dimensional argument, and just noticed that as a side effect the Mooncake error in the same PR had vanished as well. That probably makes sense in light what you write above, although I haven't understood it fully.

So the original PR were this came up is now error free as of a few hours ago. What I still don't fully understand is whether the whole thing was just a very confusing outcome of a mistake I made in the Gibbs sampler, and there's nothing to fix in Mooncake (in which case I'm very sorry to have wasted huge amounts of your time), or if there's some deeper lesson here about caches, or a more helpful error message that could be raised, or some other useful outcome.

@willtebbutt
Copy link
Member

willtebbutt commented Nov 5, 2024

Aha! This is excellent news.

No problem re my time -- none of it has been wasted, it's very helpful to know about this problem.

The conclusion as I understand it is that there doesn't appear to be anything wrong in the internals of Mooncake.jl, but the way that we're currently interfacing with ADgradient.jl is potentially somewhat unsafe.

Moving forwards, now that the ADTypes.jl stuff has been merged in to LogDensityProblemsAD.jl I'm keen to remove the LogDensityProblemsAD.jl extension from Mooncake.jl entirely. I propose the following sequence of actions:

  1. I remove the LogDensityProblemsAD.jl stuff from Mooncake.jl
  2. We take a look at the way that the ADTypes.jl - LogDensityProblemsAD.jl interactions happen, and see whether anything unsafe is going on there.

Sounds reasonable?

@mhauru
Copy link
Contributor Author

mhauru commented Nov 5, 2024

Sure, happy to follow your lead on that. I was thinking for the ForwardDiff case as well whether something better could be done in LogDensityProblemsAD, but I couldn't think of anything other than having an assert on the dimension of the argument at every gradient evaluation, which felt a bit heavy.

@willtebbutt
Copy link
Member

Good question. I'd be happy to help with this -- could you point me to some code?

@mhauru
Copy link
Contributor Author

mhauru commented Nov 5, 2024

With ForwardDiff, what happened was that this line set the chunk size to be the dimension of the log density problem:
https://github.com/tpapp/LogDensityProblemsAD.jl/blob/e3401f21b5a065df0d5de38b37fad0e6650618f3/ext/LogDensityProblemsADForwardDiffExt.jl#L97 and then later on line 116 in that file when it calls ForwardDiff.gradient! that zero chunk size is passed to ForwardDiff, together with a vector of values that is not necessarily 0-dimensional. When the dimension of the input is not the same as the dimension of the chunk ForwardDiff tries to divide the input into chunks of the given size, which hits zero-division here: https://github.com/JuliaDiff/ForwardDiff.jl/blob/7e9d778520a62447a4aed7c295ec508cb971866a/src/gradient.jl#L113

@yebai yebai added upstream: bug and removed bug Something isn't working high priority labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants