# Disable Generated Quantities for Warmup?

**URL:** <https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699>\
**Category:** General\
**Created:** [July 12, 2019, 6:17pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699 "2019-07-12T18:17:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmh530](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmh530/32/4579_2.png) [@jmh530](https://discourse.mc-stan.org/u/jmh530)\
**Post date:** [July 12, 2019, 6:17pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/1 "2019-07-12T18:17:42Z")

</div>

Someone can feel free to correct me if I’m wrong, but as far as I can tell the Generated Quantities block runs regardless of whether Stan is in the Warmup or Sampling phase. I could imagine that someone might want to view the Warmup Generated Quantities. However, I have also run into a case where running the Generated Quantities block for the Warmup frequently causes errors\*. I have since re-written my code so that this doesn’t happen, but I would think that there should be a way to disable Generated Quantities for the Warmup. Is that possible?

\*Basically what happens is that the Warmup parameters induce a non-stationarity in the model I am fitting. This causes the mean to explode to infinity or negative infinity, which causes an error in simulating from the normal distribution. I adjusted the code so that it creates an NA when this occurs instead and I get some warnings, but no error messages and the sampled data does not have any NAs in them (which is why I think the Generated Quantities block is running on the Warmup as well).

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [July 15, 2019, 8:55am UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/2 "2019-07-15T08:55:12Z")

</div>

This is a known issue: [https://github.com/stan-dev/stan/issues/2459](https://github.com/stan-dev/stan/issues/2459) - you should be able to get around this with `save_warmup = FALSE` - this will mean you are not saving the parameters for warmup either, but the interface doesn’t support having different output for warmup and the main phase.

---

<div class="post-metadata">

**Author:** ![jmh530](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/jmh530/32/4579_2.png) [@jmh530](https://discourse.mc-stan.org/u/jmh530)\
**Post date:** [July 15, 2019, 6:41pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/3 "2019-07-15T18:41:01Z")

</div>

Thanks for the advice.

---

<div class="post-metadata">

**Author:** ![YidaZhang0628](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yidazhang0628/32/10105_2.png) [@YidaZhang0628](https://discourse.mc-stan.org/u/YidaZhang0628)\
**Post date:** [November 19, 2021, 11:15pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/4 "2021-11-19T23:15:15Z")

</div>

Sorry to bring this old topic back. I have experienced similar situations but I am using `vb` instead of `stan` to fit the model. Based on my limited understanding, there is no sampling in variational inference so there is no “warmup” either. How should I avoid extreme large values during the Generated Quantities block in this case? I know that a mis-specified model could also cause this issue but I tried to fit the model without the Generated Quantities block and manually take the estimated values of parameters to generate data myself. However, I don’t see any extremely large value.

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [November 29, 2021, 4:50pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/5 "2021-11-29T16:50:03Z")

</div>

In ADVI, there is warmup, but there is the initial optimization phase, which could also have some large values. I however don’t think you can switch the gen quants off for this phase.

---

<div class="post-metadata">

**Author:** ![YidaZhang0628](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yidazhang0628/32/10105_2.png) [@YidaZhang0628](https://discourse.mc-stan.org/u/YidaZhang0628)\
**Post date:** [November 30, 2021, 3:42pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/6 "2021-11-30T15:42:19Z")

</div>

I see. In that case, I guess all I can try to improve is to come up with a better model that can avoid generating extremely large values?

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [November 30, 2021, 4:24pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/7 "2021-11-30T16:24:21Z")

</div>

You can always introduce some hard boundaries on values, e.g. instead of:

```stan
my_value = poisson_log_rng(possibly_large_value);

```

you could write

```stan
//Some threshold that should never be reached for pluasible parameters
if(possibly_large_value > 100) { 
  my_value = -1;
else {
  my_value = poisson_log_rng(possibly_large_value);
}

```

which should let you get rid of any actual errors.

---

<div class="post-metadata">

**Author:** ![YidaZhang0628](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yidazhang0628/32/10105_2.png) [@YidaZhang0628](https://discourse.mc-stan.org/u/YidaZhang0628)\
**Post date:** [December 1, 2021, 7:31pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/8 "2021-12-01T19:31:14Z")

</div>

Thanks! Just curious, how big of a problem it is to have extremely large values during data generation?

---

<div class="post-metadata">

**Author:** ![wds15](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wds15/32/908_2.png) [@wds15](https://discourse.mc-stan.org/u/wds15)\
**Post date:** [December 2, 2021, 9:06am UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/9 "2021-12-02T09:06:47Z")

</div>

The - to me - most obvious answer here would be to run the model first without the generated quantities and then run the generated quantities facility of cmdstan in a second step while providing an input file only containing the sampled parameters. A bit tedious, but gets the trick done.

---

<div class="post-metadata">

**Author:** ![martinmodrak](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/martinmodrak/32/133_2.png) [@martinmodrak](https://discourse.mc-stan.org/u/martinmodrak)\
**Post date:** [December 6, 2021, 5:10pm UTC](https://discourse.mc-stan.org/t/disable-generated-quantities-for-warmup/9699/10 "2021-12-06T17:10:39Z")

</div>

The only big issue is that in some cases it may result in errors thrown in the `generated quantities` block (e.g. when sampling from a distribution with infinite mean). This in turn prevent the sampling run from finishing. Large numbers that don’t result in an error are usually not a problem.
