Make moment_match work natively with cmdstanr
Currently, brms switches to rstan backend to make moment matching happen in loo(). However, with log_prob and friends now being available in cmdstanr too, models fit with cmdstanr no longer have to be recompiled in rstan. This is particularily relevant as moment matching regularily crashes the R session when using rstan 2.26 or 2.32.
FYI (if you didn't already know) as of cmdstanr 0.6.0 moment-matching is available in the $loo() method (i.e., fit$loo(moment_match = TRUE)), with example usage in the tests
Thank you! I didn't know but I am sure this will be very helpful!
A solution to this could also help with what @topipa and I are trying to do with iwmm, see topipa/iwmm/issues/4
We've been thinking about the best way to handle moment matched brmsfit objects (e.g. how to store weights, replacement of draws with moment matched draws) and there is a work in progress moment_match.brmsfit method assuming rstan backend (this is for generic moment matching, not just loo).
I don't think I will be able to implement this feature in brms 2.21. More like in 3.0. The reason is that using moment matching with cmdstanr requires the cmdstanr objects, which are currently not stored but converted to rstan objects. In brms 3.0 we should change this policy by always storing the object provided by the backend used to fit the model. This comes with quite a few other necessary changes so I don't think I can make this possible now.