Skip to content

Tape instruction #100

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

Closed
wants to merge 1 commit into from
Closed

Tape instruction #100

wants to merge 1 commit into from

Conversation

KDr2
Copy link
Member

@KDr2 KDr2 commented Dec 15, 2021

Try to implement #99.

@KDr2
Copy link
Member Author

KDr2 commented Dec 15, 2021

I test AdvancedPS against this change: TuringLang/AdvancedPS.jl@9d7debf, it got a numeric error.

UPDATE:
Fixed.

@yebai
Copy link
Member

yebai commented Dec 15, 2021

@KDr2 can you update the Turing PR (TuringLang/Turing.jl#1744), and see whether this works there?

@KDr2
Copy link
Member Author

KDr2 commented Dec 15, 2021

@KDr2 can you update the Turing PR (TuringLang/Turing.jl#1744), and see whether this works there?

I am on it now, it has some deeper issues, I haven't find the root cause yet.

@KDr2
Copy link
Member Author

KDr2 commented Dec 15, 2021

One of them seems to be an issue of IRTools, but I am not very sure yet:

mh inference: Error During Test at /data/zhuoql/Work/julia/Turing.jl/test/test_utils/staging.jl:42
  Got exception outside of a @test
  MethodError: no method matching var"##1226"(::DynamicPPL.Model{typeof(MoGtest), (:D,), (), (), Tuple{Matrix{Float64}}, Tuple{}, DynamicPPL.DefaultContext}, ::Libtask.Box{
DynamicPPL.TypedVarInfo{NamedTuple{(:mu1, :mu2, :z1, :z2, :z3, :z4), Tuple{DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:mu1, Setfield.IdentityLens}, Int64}, Vector{Normal{
Float64}}, Vector{AbstractPPL.VarName{:mu1, Setfield.IdentityLens}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:mu2,
Setfield.IdentityLens}, Int64}, Vector{Normal{Float64}}, Vector{AbstractPPL.VarName{:mu2, Setfield.IdentityLens}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, Dynam
icPPL.Metadata{Dict{AbstractPPL.VarName{:z1, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:z1, Setfield.Identit
yLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z2, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vec
tor{Float64}}}, Vector{AbstractPPL.VarName{:z2, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z3,
 Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:z3, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPP
L.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z4, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:
z4, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}}, ::Libtask.Box{Sampler{PG{(:z1, :z2, :z3, :z4), ResampleWithESSThreshold{typeof(r
esample_systematic), Float64}}}})
  Closest candidates are:
    var"##1226"(::Any, ::Any) at /data/zhuoql/.julia/packages/IRTools/isLV2/src/eval.jl:18
  Stacktrace:
    [1] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
      @ Base ./essentials.jl:716
    [2] invokelatest(::Any, ::Any, ::Vararg{Any})
      @ Base ./essentials.jl:714
    [3] evalir(::Module, ::IRTools.Inner.IR, ::Any, ::Vararg{Any})
      @ IRTools.Inner ~/.julia/packages/IRTools/isLV2/src/eval.jl:25
    [4] evalir(::IRTools.Inner.IR, ::Any, ::Any, ::Vararg{Any})
      @ IRTools.Inner ~/.julia/packages/IRTools/isLV2/src/eval.jl:26
    [5] run_and_record!(::Libtask.Tape, ::Libtask.Box{DynamicPPL.Model{typeof(MoGtest), (:D,), (), (), Tuple{Matrix{Float64}}, Tuple{}, DynamicPPL.DefaultContext}}, ::Libta
sk.Box{DynamicPPL.TypedVarInfo{NamedTuple{(:mu1, :mu2, :z1, :z2, :z3, :z4), Tuple{DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:mu1, Setfield.IdentityLens}, Int64}, Vector{
Normal{Float64}}, Vector{AbstractPPL.VarName{:mu1, Setfield.IdentityLens}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName
{:mu2, Setfield.IdentityLens}, Int64}, Vector{Normal{Float64}}, Vector{AbstractPPL.VarName{:mu2, Setfield.IdentityLens}}, Vector{Float64}, Vector{Set{DynamicPPL.Selector}}}
, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z1, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:z1, Setfield.
IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z2, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float
64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:z2, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarNa
me{:z3, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.VarName{:z3, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{Dy
namicPPL.Selector}}}, DynamicPPL.Metadata{Dict{AbstractPPL.VarName{:z4, Setfield.IdentityLens}, Int64}, Vector{Categorical{Float64, Vector{Float64}}}, Vector{AbstractPPL.Va
rName{:z4, Setfield.IdentityLens}}, Vector{Int64}, Vector{Set{DynamicPPL.Selector}}}}}, Float64}}, ::Vararg{Any})
      @ Libtask ~/Work/julia/Libtask.jl/src/tapedfunction.jl:124
    [6] ##1225
      @ ~/Work/julia/Turing.jl/src/core/container.jl:16 [inlined]
...

@KDr2
Copy link
Member Author

KDr2 commented Dec 16, 2021

Varargs needs some special manipulation, I (hopefully suppose that) had fixed that. But, there're still issues, one of which is dynamic branches, e.g., https://github.com/TuringLang/DynamicPPL.jl/blob/v0.16.2/src/model.jl#L387

@KDr2
Copy link
Member Author

KDr2 commented Dec 16, 2021

There are also some dynamically generated (by macro expanding or other facilities) functions, which we can't trace into.

@KDr2
Copy link
Member Author

KDr2 commented Dec 16, 2021

And, there are too many branches on the way by which we trace down into a deep produce call.
like this, https://github.com/TuringLang/Turing.jl/blob/master/test/test_utils/models.jl#L20.

So maybe we should support braches before we use it in Turing.

@KDr2 KDr2 force-pushed the tape-instruction branch 2 times, most recently from 06477d1 to 9883cc3 Compare December 22, 2021 00:53
yebai added a commit that referenced this pull request Jan 3, 2022
yebai added a commit that referenced this pull request Jan 3, 2022
yebai added a commit that referenced this pull request Jan 4, 2022
* Fix unbox condition function (ref #100)

* Port new produce mechanism from #100.

* Minor bugfixes.

* Fix new produce mechanism.

* Update src/tapedtask.jl

* Update src/tapedtask.jl

* Update src/tapedtask.jl

* Update src/tapedtask.jl
@KDr2 KDr2 force-pushed the tape-instruction branch 3 times, most recently from a63e30d to 09d90e8 Compare January 5, 2022 00:32
@KDr2 KDr2 force-pushed the tape-instruction branch from 09d90e8 to b31d493 Compare January 5, 2022 00:58
@KDr2 KDr2 force-pushed the tape-instruction branch from b31d493 to 6a86ff2 Compare January 7, 2022 03:49
@delete-merged-branch delete-merged-branch bot deleted the branch master January 24, 2022 10:55
@yebai
Copy link
Member

yebai commented Jan 26, 2022

No longer needed after #107 - in the future, we can treat TapedFunction as special instructions with help from #97

@yebai yebai closed this Jan 26, 2022
@yebai yebai deleted the tape-instruction branch January 26, 2022 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants