# Seed dependence of log\_prob when using spline couplings

**URL:** <https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79>\
**Category:** General\
**Created:** [March 7, 2024, 11:34am UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79 "2024-03-07T11:34:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![guttley](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@guttley](https://discuss.bayesflow.org/u/guttley)\
**Post date:** [March 7, 2024, 11:34am UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79/1 "2024-03-07T11:34:51Z")

</div>

Hi all,

I have been having some issues getting repeatable log\_prob outputs for the same input datasets when using models with spline couplings. The issue goes away when setting tensorflow global seeds just before getting the log\_prob. However, I am unsure of any reason why this calculation should be seed dependent?

The differences seem to come when calling the DenseCouplingNet in the coupling layer. The only reason I can thing of is I am loading in the model with self.inference\_net.load\_weights (not using a summary network) from a saved model weights file and perhaps this isn’t sufficient and so adds some variability in the model?

Thanks in advance for your help.

Cheers  
George

---

<div class="post-metadata">

**Author:** ![LarsKue](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/larskue/32/100_2.png) [@LarsKue](https://discuss.bayesflow.org/u/LarsKue)\
**Post date:** [March 8, 2024, 12:51pm UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79/2 "2024-03-08T12:51:25Z")

</div>

Does this also apply if you use `tf.config.experimental.enable_op_determinism()` before calling `log_prob` without a set seed?

---

<div class="post-metadata">

**Author:** ![guttley](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@guttley](https://discuss.bayesflow.org/u/guttley)\
**Post date:** [March 8, 2024, 3:02pm UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79/3 "2024-03-08T15:02:55Z")

</div>

> [@LarsKue](#):
>
> tf.config.experimental.enable\_op\_determinism()

Hi,

Yes I have tried this. To show you an example of this in practice I have quickly put together the following google colab notebook:

> **[Google Colab](https://colab.research.google.com/drive/1Yo_Wy2qhg_Sek5I1C6Dt5jrp844fFkgj?usp=sharing)**

I doubt it will run for you as you need to mount my google drive with the model file in, but should give a clear understanding of what I am doing. If you wish to replicate I can email you the .h5 file.

Cheers,  
George

---

<div class="post-metadata">

**Author:** ![LarsKue](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/larskue/32/100_2.png) [@LarsKue](https://discuss.bayesflow.org/u/LarsKue)\
**Post date:** [March 8, 2024, 4:45pm UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79/4 "2024-03-08T16:45:46Z")

</div>

Looks like dropout is causing the randomness. As far as I know, using `mc_dropout=True` enables dropout at evaluation time, so this would be the intended behaviour. Can you try a model that uses `mc_dropout=False`?

---

<div class="post-metadata">

**Author:** ![guttley](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@guttley](https://discuss.bayesflow.org/u/guttley)\
**Post date:** [March 11, 2024, 9:35am UTC](https://discuss.bayesflow.org/t/seed-dependence-of-log-prob-when-using-spline-couplings/79/5 "2024-03-11T09:35:24Z")

</div>

Thanks, this fixes it.
