I’d like to understand if there are better ways to save model fits other than pickle files in order to use stan models in production. Pickle files often get corrupted and I’m recently getting some pandas errors like:
RecursionError: maximum recursion depth exceeded.
Can model fits get stored in json files with no loss of information?
Also are the save fit files linked somehow to the path were the stan model gets compiled? Can they be used outside the environment where the model was fit?
In this particular situation, you might want to try out using cmdstanpy – the CmdStanModel object can be instantiated directly from a compiled Stan binary.
Since you’re aiming for a production environment, it might make sense in the environment setup to compile the Stan model and have it sit in a predefined location, which you can just reference with cmdstandpy.
Alternatively, if you are using PyStan 3, then models are cached by default after they are first built, so if you were to run the model the same way every time, then it would pick up the cached model without having to recompile.