# Numerical errors in logit normal model using Turing.jl

**URL:** <https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602>\
**Category:** Probabilistic Programming\
**Tags:** question, turing\
**Created:** [November 1, 2019, 7:01pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602 "2019-11-01T19:01:50Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 9, 2019, 2:33pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/21 "2019-11-09T14:33:51Z")

</div>

How long did it take to run on your system? After running about 2%, the ETA is around 11.5 hours.

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [November 9, 2019, 3:08pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/22 "2019-11-09T15:08:15Z")

</div>

It took a few minutes. Hours sounds strange.

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [November 9, 2019, 3:30pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/23 "2019-11-09T15:30:32Z")

</div>

Could you please post your setup? Are you at master?

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 9, 2019, 4:01pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/24 "2019-11-09T16:01:17Z")

</div>

I am using Turing v0.7.1 because Zygote is still causing problems for me.

```julia

(v1.2) pkg> st Turing
    Status `~/.julia/environments/v1.2/Project.toml`
  [0bf59076] AdvancedHMC v0.2.7
  [31c24e10] Distributions v0.21.6
  [c7f686f2] MCMCChains v0.3.14
  [276daf66] SpecialFunctions v0.8.0
  [4c63d2b9] StatsFuns v0.9.0
  [fce5fe82] Turing v0.7.1
  [e88e6eb3] Zygote v0.4.1

```

---

<div class="post-metadata">

**Author:** ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Post date:** [November 9, 2019, 4:46pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/25 "2019-11-09T16:46:02Z")

</div>

I was able to switch to master without encountering a problem with Zygote and the model did run in about one minute. I’m guessing that this is still much slower than Stan, but much better than 11.5 hours. What would cause a nearly 700 fold improvement?

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [November 9, 2019, 6:23pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/26 "2019-11-09T18:23:39Z")

</div>

I’m not 100% sure, but it sounds like the gradient computation falls back to compute each gradient independently instead of vectorising the computation. But this should actually not happen anymore.

---

<div class="post-metadata">

**Author:** ![trappmartin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trappmartin/32/1165_2.png) [@trappmartin](https://discourse.julialang.org/u/trappmartin)\
**Post date:** [November 9, 2019, 6:24pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/27 "2019-11-09T18:24:51Z")

</div>

There should be a new patch release afai that fixes the version issue of Zygote and IRTools.

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [November 9, 2019, 10:06pm UTC](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602/28 "2019-11-09T22:06:05Z")

</div>

> [@trappmartin](#):
>
> @mohamed82008 I think this should work with `FillArrays` too? Not sure why this is problematic.

It seems that `FillArrays` is interacting badly with `Tracker` and `Distributions`. `fill` of a `TrackedReal` returns a `TrackedArray` because it was defined this way in `Tracker`. And `MvNormal` supports a `TrackedArray` mean vector and is tested for it. We don’t properly test or overload any method for `FillArrays` of a `TrackedReal` so it’s falling back on some wrong methods. Please open an issue to investigate further.

[Previous page](https://discourse.julialang.org/t/numerical-errors-in-logit-normal-model-using-turing-jl/30602.md?page=1)
