brms
brms copied to clipboard
Support for Model Profiling with cmdstanr backend
Since brms has support for cmdstanr as a backend it may be useful to have support the profiling feature introduced in cmdstan 2.26.0. I'm not sure how much work it would be to add such a feature and its not particularly urgent, but it would be convenient for identifying bottle necks.
It's up to @paul-buerkner to say how hard this is, but one only needs to wrap bits and pieces which need profiling into a block. That sounds like a great suggestion to me as profiling is super informative.
However... one should be able to inject this already now by using the stan model munging features in stan as provided by brms. You can inject code at the end and at the start of a block, which is all you need.
In theory, manual specification in the model block via the stanvars
argument would work, but only in the case of very straightforward models.
Consider the case of a multivariate outcome or a nonlinear model where there tend to be multiple for
loops and only one of them is the source of the bottle neck. I'm currently working with a multilevel multinomial logistic regression model where this is the case.
It's of course simple enough to write the code to a file and add the relevant profiling chucks manually then run it under cmdstanr for a few iterations to find out where things are getting stuck but being able to just set an argument like profiling = TRUE
in the brm
function would be even easier (again, assuming it isn't too much work to implement such a thing in the first place).
I think this suggested features may not make it into brms. When someone needs functionality beyond what stanvars offer, it is easiest to just edit the Stan code directly.