We recently had our package,
chkptstanr, accepted at CRAN !
The basic idea is to start and stop the sampler, as needed.
The package was actually a request from AWS, in that they asked us to make some functionality for using Stan with their so-called “spot instances” (this can reduce the cost considerably).
We followed a suggestion on this forum, in particular, from @Bob_Carpenter:
"You’ll need step size, the mass matrix or metric (making sure to get the inversion right), and the last draw to use as an initialization. Then you need to configure NUTS to run with no warmup and just keep using the step size and mass matrix you provide " (Current state of checkpointing in Stan)
This is now done “under the hood”, so the overall user experience is much like using
brms. In fact, the package is compatible with
brms (and posterior, bayesplot, etc…), in that, internally, the Stan code is generated, then fitted with
cmdstanr, and then the returned object is of class
brmsfit. This was important for us, because now all the other
brms functions can be used seamlessly (e.g.,
There are some caveats we came across when developing the package:
(1) there is quite a bit of overhead for extracting the information, saving, etc… So this can make model fitting take much longer, so need to consider just how many checkpoints are needed.
(2) we found that there must be an initial period that cannot be interrupted. Once past this, at least in our tests, it is very similar to just fitting without stopping.