TuringLang / docs

Documentation and tutorials for the Turing language
https://turinglang.org/docs/
MIT License
231 stars 99 forks source link

BNN Variational Inference Error #59

Open cpfiffer opened 4 years ago

cpfiffer commented 4 years ago

@torfjelde the BNN tutorial is failing because

update(q, (μ, exp.(ω)))

doesn't seem to work anymore, because update doesn't seem to be exported anymore. I tried calling

Variational.update(q, (μ, exp.(ω)))

but there's a new error:

MethodError: no method matching update(::DistributionsAD.TuringDiagMvNormal{Array{Float64,1},Array{Float64,1}}, ::Tuple{Array{Float64,1},Array{Float64,1}})
Closest candidates are:
  update(::DistributionsAD.TuringDiagMvNormal, ::Any, !Matched::Any) at /home/cameron/.julia/packages/Turing/cReBm/src/variational/advi.jl:8
  update(!Matched::TransformedDistribution, ::Any...) at /home/cameron/.julia/packages/Turing/cReBm/src/variational/advi.jl:9

Stacktrace:
 [1] update(::TransformedDistribution{DistributionsAD.TuringDiagMvNormal{Array{Float64,1},Array{Float64,1}},Stacked{Tuple{Identity{1}},1},Multivariate}, ::Tuple{Array{Float64,1},Array{Float64,1}}) at /home/cameron/.julia/packages/Turing/cReBm/src/variational/advi.jl:9
 [2] top-level scope at In[28]:10

What's the fix here?

torfjelde commented 4 years ago

Isn't it supposed to be Variational.update(q, μ, exp.(ω))? At least that's what's suggested by Closest candidates are:

cpfiffer commented 4 years ago

Strange, doesn't seem to be yielding good inference:

image

cpfiffer commented 4 years ago

And I am now getting this:

MethodError: Cannot `convert` an object of type Array{Float64,1} to an object of type SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T<:AbstractArray at abstractarray.jl:14
  convert(::Type{T}, !Matched::LinearAlgebra.Factorization) where T<:AbstractArray at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/LinearAlgebra/src/factorization.jl:55
  convert(::Type{T}, !Matched::Intervals.Interval{T}) where T at /home/cameron/.julia/packages/Intervals/wasuB/src/interval.jl:122
  ...

Stacktrace:
 [1] setproperty!(::Tracker.Tracked{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}}, ::Symbol, ::Array{Float64,1}) at ./Base.jl:34
 [2] back(::Tracker.Tracked{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}}, ::Array{Float64,1}, ::Bool) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:53
 [3] (::Tracker.var"#13#14"{Bool})(::Tracker.Tracked{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}}, ::Array{Float64,1}) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:38
 [4] foreach(::Function, ::Tuple{Tracker.Tracked{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}},Nothing,Nothing}, ::Tuple{Array{Float64,1},Array{Float64,1},Array{Float64,1}}) at ./abstractarray.jl:1920
 [5] back_(::Tracker.Call{Tracker.var"#back#550"{3,Base.Broadcast.var"#2#4"{Base.Broadcast.var"#8#10"{Base.Broadcast.var"#1#3",Base.Broadcast.var"#8#10"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"},Base.Broadcast.var"#5#6"{Base.Broadcast.var"#5#6"{Base.Broadcast.var"#7#9"}},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(-)},Base.Broadcast.var"#11#12"{Base.Broadcast.var"#11#12"{Base.Broadcast.var"#13#14"}},Base.Broadcast.var"#15#16"{Base.Broadcast.var"#15#16"{Base.Broadcast.var"#17#18"}},typeof(/)},typeof(abs2)},Tuple{TrackedArray{…,SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}},Array{Float64,1},Array{Float64,1}}},Tuple{Tracker.Tracked{SubArray{Float64,1,Array{Float64,1},Tuple{UnitRange{Int64}},true}},Nothing,Nothing}}, ::Array{Float64,1}, ::Bool) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:38
 [6] back(::Tracker.Tracked{Array{Float64,1}}, ::Array{Float64,1}, ::Bool) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:58
 [7] #13 at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:38 [inlined]
 [8] foreach at ./abstractarray.jl:1920 [inlined]
 ... (the last 4 lines are repeated 97 more times)
 [397] back_(::Tracker.Call{Tracker.var"#201#202",Tuple{Tracker.Tracked{Float64}}}, ::Float64, ::Bool) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:38
 [398] back(::Tracker.Tracked{Float64}, ::Float64, ::Bool) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:58
 [399] #back!#15 at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:77 [inlined]
 [400] back!(::Tracker.TrackedReal{Float64}, ::Float64) at /home/cameron/.julia/packages/Tracker/cpxco/src/back.jl:75
 . . .
torfjelde commented 4 years ago

Strange, doesn't seem to be yielding good inference:

What parameters are you using? What optimizer? Etc.

And I am now getting this:

This might be something related to https://github.com/TuringLang/Turing.jl/pull/1128

cpfiffer commented 4 years ago

All this is in here: https://github.com/TuringLang/TuringTutorials/blob/master/3_BayesNN.ipynb

No tutorial has been successfully served on the site with the VI code in it. Is it worth fixing or should I just remove it for now?