Most Machine Learning Models will change at some point, and when they do, you want to make your retrained model available quickly and efficiently.
On Algorithmia, model files are pulled from file storage whenever a new instance of an Algorithm is warmed up. If your predictive code has not changed, and the new model file is backward-compatible, you can choose to simply replace the file. Newly warmed-up copies of your Algorithm will automatically utilize the new model file, returning new predictive values.
However, this does not force old copies of your Algorithm to unload… so, for a time, some predictions might use your old model, while others use the new one.
There are two ways to resolve this problem, depending on whether you want to force a version-number change on your Algorithm.
Option 1: Changing your Algorithm Version Number while Updating your Model
One of the benefits of versioning your Algorithm while updating your model is that users can choose which version to call, and won’t be surprised by a sudden change in result values.
1. Upload your new model file with a new name, preferably one indicating a date or revision, e.g. “mymodel-201902”.
2. Change your Algorithm’s code to use this new filename.
Either edit your Algorithm in the Web IDE, or push the modified code to your Algorithm’s git repo.
3. Republish your Algorithm (which causes the version number of the Algorithm to change).
Option 2: Updating your Model immediately, without changing Version Numbers
If you’ll be updating your model very often (e.g. via an automated process that retrains the model hourly from a live data feed), versioning your Algorithm on every single model change can be impractical. In this case, you may want to add automatic model reloading into your Algorithm. This requires writing some custom code.
For example, consider a simple scikit-learn Algorithm which loads a model file from Hosted Data, accepts some text as input, and returns a number:
We need to alter this code so that instead of only loading the model file once on warm-up, it reloads the model periodically.
We do so by adding a function to reload the model. We’ll call this function once, in the outer scope, to make sure it gets loaded at warm-up:
Next, we need a way to periodically call reload_model(). Since the algorithm only runs code when it is actively called, we’ll attach this to the apply() function, checking against a last_reload_time:
Alternative: use CI/CD for model redeployments
If you wish to set up Continuous Integration/Deployment in a system such as Jenkins, see Deploying Models via CI/CD.