amazon-sagemaker-examples icon indicating copy to clipboard operation
amazon-sagemaker-examples copied to clipboard

scikit_bring_your_own: Singleton for model is not working

Open dipsatch opened this issue 8 years ago • 2 comments

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?

dipsatch avatar Aug 06 '18 04:08 dipsatch

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.

jesterhazy avatar Aug 14 '18 15:08 jesterhazy

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

hongshanli23 avatar Jan 27 '21 22:01 hongshanli23