scikit_bring_your_own: Singleton for model is not working
In predictor.py, whenever cls.get_model() inside ScoringService.predict() is called, it always enters the if cls.model == None: condition and cls.model is newly initialized.
I checked it just by keeping a print statement inside the if cls.model == None: condition, and then whenever I called the /invocations endpoint for new predictions, every time the print statement got executed.
Why is that happening when ScoringService is supposed to be a singleton for holding the model?
That example code should load the model (i.e. enter the if cls.model == None: branch) once per gunicorn worker, not for every request. By default, the number of workers is equal to the number of cpus (vcpus, actually) on the hosting instance, so you should see your print output that number of times. Are you seeing it more than that?
Also, you can control the number of workers by setting the MODEL_SERVER_WORKERS environment variable (the code for this is here). Try setting the it to "1" to test the model loading behavior.
Dear SageMaker Community, In our attempts to provide this repository with a better level of support going forward, we’re closing issues that were opened prior to the v2 release of the SDK. This is because we believe that over time many of the issues posted were solved with the latest release or other recent changes to the repo. This will help us reallocate resources towards issues that are more likely to still be relevant today. Some of the issues experienced now can be resolved by referencing the v2 guide: https://sagemaker.readthedocs.io/en/stable/v2.html In this guide, you can find simple solutions to common notebook errors, like the renaming of parameters and classes. If you believe your issue is still ongoing and you have updated error messaging or other info, please re-open it, and we investigate the issue. Best Regards, AWS SageMaker Team