Within-Chain parallelization & Seed

Hi everyone,

I’m using the within chain parallelization (with the function reduce-sum and partial-sum), and I was wondering if we could specify a seed to obtain the same results from a run to another run of the same model, please ?

Indeed, I’m able to specify a seed in the r part and the stan part of my model, leading to the same results from a run to another run of the same model when I don’t use the within chain parallelization.

However, when I use the within chain parallelization with a seed in the r part and the stan part, I don’t obtain the same results from a run to another run of the same exact model (with the same exact data also). So I was wondering If there is a way to specify a seed for stan to perform the same within chain parallelization each time?

Thank you !

Using threading makes things not easily reproducible in an exact way. You may get exact reproducibility if you use the static version of reduce_sum. This version chunks the large sum always in the same packets…and hence the choice of the grainsize is more important to choose well for good performance.

Thank you for the reply!

How could I tell stan that I want to use the static version of reduce sum?

For now, I was using a grainsize of 1, which seemed to be the one with the best performance.

Please have a look at the Stan functions manual.

I’m guessing that @wds15 means the version without threading. To do that, you need to change the compiler flags to not use threading I believe. But I don’t know how to do that. @WardBrian or @stevebronder should know.

I believe he meant the reduce_sum_static function

Yes, that’s what I meant.

Thanks—I didn’t even know there was such a function. Sorry for confusing matters!