# Speed up model in Turing

**URL:** <https://discourse.julialang.org/t/speed-up-model-in-turing/50555>\
**Category:** Probabilistic Programming\
**Tags:** question, performance, turing\
**Created:** [November 21, 2020, 8:28pm UTC](https://discourse.julialang.org/t/speed-up-model-in-turing/50555 "2020-11-21T20:28:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohmsweetohm1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ohmsweetohm1/32/49126_2.png) [@ohmsweetohm1](https://discourse.julialang.org/u/ohmsweetohm1)\
**Post date:** [November 21, 2020, 8:28pm UTC](https://discourse.julialang.org/t/speed-up-model-in-turing/50555/1 "2020-11-21T20:28:12Z")

</div>

Note that I am new to Turing as well as to Bayesian inference.  
I have to following simple Bayesian linear regression model. (This is pretty much the tutorial example)

```julia
    Turing.@model function linear_regression(x, y)
        s ~ Distributions.truncated(Distributions.Normal(0, 10), 0, Inf)
        b ~ Distributions.MvNormal(zeros(size(x, 2)), 1)
        y ~ Distributions.MvNormal(x * b, s)
    end

    model = linear_regression(X_train_norm, y_train_norm)
    chain = Turing.sample(model, Turing.NUTS(0.65), 1000)

```

where `X_train_norm` and `y_train_norm` have been both normalized.  
The size of `X` is `5760x74`

The model works for smaller sample sizes and less predictors (`360x20` @ 20s) but with the data size from above from above it takes such a long time that I simply stopped it.

Is there something wrong? Are other samplers better for this job? Is there something obvious that I can do to speed it up?

My goal is to make a Markov switching model where in each regime the model is a linear regression.

---

<div class="post-metadata">

**Author:** ![cpfiffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cpfiffer/32/208747_2.png) [@cpfiffer](https://discourse.julialang.org/u/cpfiffer)\
**Post date:** [November 21, 2020, 10:46pm UTC](https://discourse.julialang.org/t/speed-up-model-in-turing/50555/2 "2020-11-21T22:46:30Z")

</div>

I mean, that’s a lot of data, so it’s not surprising that it’s taking you a long time. The only fix I would suggest is using ReverseDiff, with

```julia
Turing.setadbackend(:reversediff)

```

at the top of your script, after you import Turing.
