Possible to quasi-automatically implement within-chain parallelization in cmdrstan with brms?

One of the appeals of using brms is that it automates the chunking of data and code conversion to map reduce equivalents for cmdstanr to implement within-chain parallelization for at least some parts of models supported by brms.

Is there some way to get code from brms that I can pass to cmdrstanr to fit the same model with the same processing approach - i.e. replicate exactly what brms does albeit with maybe differently-structured output because we’re working with cmdrstanr objects?

My motivation in asking this is that sometimes I use cmdstanr to fit models brms cannot fit but manually setting up multithreading (and writing according code) in cmdstanr can be tedious. Accordingly, I’m interested in passing simpler model to brms so that it can automate/optimize that simpler model, then I can tweak it to implement my actual model of interest. I know brms::make_stancode() exists, but it doesn’t seem to capture everything needed for multithreading.

Have you read Running brms models with within-chain parallelization? You can just add threads argument
to brm( ) as brm(backend = "cmdstanr", threads = threading(...), ... Does this help you to do what you want to do?

I already know how to (a) parallelize my cmdstanr processing and (b) use the cmdstanr backend with the threads argument. My question was about using brms code as a shortcut to accomplish (a) with the cmdstanr front-end.

Just a clarification: Have you tried both make_stancode(threads = threading(...), ...) and make_standata((threads = threading(...), ...) before you fit models using cmdstanr?

2 Likes