# How to save a bart model and load it without retraining？

**URL:** <https://discourse.pymc.io/t/how-to-save-a-bart-model-and-load-it-without-retraining/14938>\
**Category:** v5\
**Tags:** arviz, prediction, bart\
**Created:** [August 19, 2024, 5:34am UTC](https://discourse.pymc.io/t/how-to-save-a-bart-model-and-load-it-without-retraining/14938 "2024-08-19T05:34:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JJ\_Py](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jj_py/32/8183_2.png) [@JJ\_Py](https://discourse.pymc.io/u/JJ_Py)\
**Post date:** [August 19, 2024, 5:34am UTC](https://discourse.pymc.io/t/how-to-save-a-bart-model-and-load-it-without-retraining/14938/1 "2024-08-19T05:34:38Z")

</div>

Hi, I have build a bart model for regression task. And I plan to deploy the model to a web platform. But I found a problem is that the Pymc can only save trace data (az.to\_netcdf). After reloading the trace data (az.from\_netcdf), the model still needs to be retrained. Due to the large amount of training data, it takes more than 10 minutes to train the model each time. This obviously cannot be configured on the web platform for practical application.

I have also try this solution method(“[Save and Load a BART model](https://discourse.pymc.io/t/save-and-load-a-bart-model/13135)”). But it does not work.

So I want to ask if there is a general way to call the pymc model without retraining the model. Thank you very much, looking forward to your reply.

My bart code is as follows:

```auto
# build model
with pm.Model() as E_ulti:
    X = pm.MutableData("X", X_train)
    Y = pm.MutableData("Y", Y_train)
    α = pm.Exponential("α", 1)
    μ = pmb.BART("μ", X, np.log(Y_train),m=200,split_rules=split_rules)
    y = pm.Normal("y", mu=pm.math.exp(μ), sigma=α, observed=Y, shape=μ.shape)
    idata_ulti = pm.sample(random_seed=RANDOM_SEED)
# save trace
az.to_netcdf(idata_ulti, 'trace_c.nc')
# load trace
trace_c = az.from_netcdf('trace_c.nc')
# sample predictive
with Em_ulti:
    X.set_value(xtest_pd)
    posterior_predictive_xtest = pm.sample_posterior_predictive(trace=trace_c, random_seed=RANDOM_SEED)
# check result
az.summary(posterior_predictive_xtest, var_names="y", kind="stats", round_to=4)

```

---

<div class="post-metadata">

**Author:** ![JJ\_Py](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/jj_py/32/8183_2.png) [@JJ\_Py](https://discourse.pymc.io/u/JJ_Py)\
**Post date:** [August 24, 2024, 12:57pm UTC](https://discourse.pymc.io/t/how-to-save-a-bart-model-and-load-it-without-retraining/14938/3 "2024-08-24T12:57:22Z")

</div>

The above question can be solved in follow topic temporarily. Therefore, this question can be deleted in pymc discourse.  
Thank you very much.  
[bart model load](https://discourse.pymc.io/t/save-and-load-a-bart-model/13135)
