Support default models on Multi-Model endpoints.
Checklist
- [x] I've prepended issue tag with type of change: [feature]
- [x] (If applicable) I've documented below the DLC image/dockerfile this relates to
- [x] I'm using an existing DLC image listed here: https://docs.aws.amazon.com/deep-learning-containers/latest/devguide/deep-learning-containers-images.html
- [x] I've built my own container based off DLC (and I've attached the code used to build my own image)
DLC image/dockerfile: tensorflow 2.2.0
Hello,
A common scenario I've encountered is the need to combine different models to get a final result. There are two different ways to architect a solution like this:
- Deploying each model to a different endpoint
- Deploying all models to the same endpoint and write custom inference code to combine them.
In some cases, the first approach is not possible because of the added latency when making predictions. For example, when processing billion of records, having to ping-pong from different endpoints becomes cost-prohibitive.
The second scenario, unfortunately, is not straightforward to implement today. Here is a specific example:
I have several models that will be deployed in a Multi-Model endpoint. Each model is trained for a specific animal species. To make a prediction, I need to run the input through a common model (shared across all animals) and then run the result through the specific model corresponding to the species specified in the input data.
To achieve this, I needed to have a default model that's always loaded when the container starts. This default model is the one that's used across all animal species. Then, each species model will be dynamically loaded when requested.
The current version of the inference container doesn't allow this out of the box. It either loads a default model or completely defers loading when the endpoint is marked as multi-model.
I was able to work around this issue by doing the following:
- Packaging the model assets with the container (because for multi-model endpoints, there's no way to specify a single model.tar.gz file)
- Subclassing
ServiceManagerand overwriting thestart()method in the following way:
class CustomServiceManager(ServiceManager):
def start(self):
log.info("Starting custom services...")
self._start_tfs()
super().start()
- Overwriting the
serveshell script so the custom implementation ofServiceManageris called instead of the original one.
This is not a great solution, especially because I need to call directly _start_tfs() which is supposed to be a private method.
I think we could increase the flexibility of the existing containers in one of two ways:
- Support the ability to have both default and on-demand models in a multi-model endpoint.
- Provide a mechanism by which the container can be extended in a straightforward way to allow for this scenario (without resorting to accessing private implementation details.)
The first approach is probably the most cumbersome because there will have to be multiple changes, starting with the ability to specify which model(s) should run by default and have SageMaker automatically download them when starting the endpoint.
The second approach is probably easier to implement in the short term.
I'd be delighted to help in any way with contributions here.
@svpino Thanks for using the DLC and for the feature request !
I am adding my colleagues (@ChuyangDeng , @metrizable ) from the sagemaker toolkits team to discuss this request.
@svpino Have you looked into SageMaker inference pipeline? It sounds like this could fit your use case - https://docs.aws.amazon.com/sagemaker/latest/dg/inference-pipelines.html With this your can mix and match any SageMaker or custom model containers during serving.
I have. Unfortunately, the inference pipeline requires multiple endpoints, and then an HTTP request will be made from one endpoint to another. For speed purposes, I need to avoid going to different endpoints, and instead, processing everything in a single place.
@svpino There will be chained HTTP requests made with inference pipeline but the containers are located in the same ec2 instance behind the same endpoint. The latency should be low as explained in the doc.
Interesting. I didn't know that. I will look at this and see if I can use it. Thanks, @icywang86rui!
A follow-up question if you don't mind (I couldn't find it in their documentation): do Inference Pipelines support multi-model containers?
It definitely supports multi-model. You can use any model. We have some support built into the Python SDK as well. You can reference notebook like this one - https://github.com/awslabs/amazon-sagemaker-examples/blob/master/advanced_functionality/inference_pipeline_sparkml_xgboost_abalone/inference_pipeline_sparkml_xgboost_abalone.ipynb
This is the doc for python SDK support - https://sagemaker.readthedocs.io/en/stable/overview.html#inference-pipelines
Hope this helps.
Hi @svpino - we are closing out this issue for now, but if you have any followup questions or reasons to reopen, please reopen this issue or file a new one. Thanks for bringing this to our attention.