Disable Generated Quantities for Warmup?

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).

1 Like

This is a known issue: 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.

Thanks for the advice.

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.