What is the proper way to save a cmdstanpy model after a fit has been complete?

How do I properly save a cmdstanpy model? I have successfully compiled and sampled from the model and have verified the csv’s are saved to the output directory?

After being saved, how do I load the model to sample with new data?

Or are the csv’s the model itself somehow?

@ahartikainen @mitzimorris

1 Like

The compiled model will be saved as a file on disk. Re-running the CmdStanModel(...) block of code should re-create the model without recompiling, unless you’ve edited the model code itself (the .stan file)

The CSV files from a fit of the model can be saved with save_csvfiles and turned back into a CmdStanMCMC(or MLE/VI/GQ) using from_csv

1 Like

A CmdStanModel object just holds onto the location of the Stan source file and/or compiled executable file on disk. If both exist in the same directory, you then instantiate a new CmdStanModel object (or use the existing one, if you’re in the same session). Then you call the sample method with the new data.

Or are the csv’s the model itself somehow

no, the CSV files are just Stan CSV files.