- Newest
- Most votes
- Most comments
Testing with the below, I can get this to work. Key here is that you want to obtain the repacked model when creating the MultiModel object as this will contain both the contents of model_data
and source_dir
. I did notice that there are some issues within service.py
which should be addressed before model can be deployed to an Endpoint.
I have updated the below code to set enable_network_isolation
to False
so that a source_dir.tar.gz
can be generated that is independent of our model.tar.gz
since model.tar.gz
will not be unpacked during startup for MultiModel Endpoints. I did notice that there are some issues within service.py
which should be addressed before model can be deployed to an Endpoint.
All testing was done using sagemaker version 2.240.0
Traceback (most recent call last): File "/miniconda3/lib/python3.9/site-packages/sagemaker_containers/_functions.py", line 93, in wrapper return fn(*args, **kwargs) File "/opt/ml/code/inference.py", line 9, in model_fn return serve.model_loading(model_dir, 'classification') File "/opt/ml/code/shared/serving.py", line 57, in model_loading model_prefix = mc.CLASSIFICATION_OUTCOME NameError: name 'mc' is not defined
import sagemaker from sagemaker.multidatamodel import MultiDataModel from sagemaker.xgboost.model import XGBoostModel session = sagemaker.Session() write_bucket = session.default_bucket() write_prefix = "sagemaker_mme_bug/MME/house-price-model" model_data_prefix = f"s3://{write_bucket}/{write_prefix}/" role = sagemaker.get_execution_role() xgboost_model = XGBoostModel( name="xgboost-model", role=role, model_data=model_data_prefix, # vpc_config=vpc_config, sagemaker_session=session, enable_network_isolation=False, # Needs to be set to False to decouple code from model. entry_point="inference.py", framework_version="1.7-1", source_dir="./code", # Upload to a S3 bucket ) session.upload_data(path='model.tar.gz', bucket=write_bucket, key_prefix=write_prefix) mme = MultiDataModel( name='house-price-model-mme', model_data_prefix=model_data_prefix, sagemaker_session=session, model=xgboost_model ) print(list(mme.list_models())) predictor = mme.deploy( initial_instance_count=1, instance_type="ml.c5.xlarge", )
Your folder structure looks to be correct. Please share the whole repo so that I replicate this
https://github.com/mimiga1234/sagemaker_mme_bug Thanks in advance.
One thing to note that if I directly deploy using single endpoint, everything works xgboost_model.deploy( initial_instance_count=1, instance_type="ml.c5.xlarge", )
Relevant content
- AWS OFFICIALUpdated a month ago
Update: Upon further testing with real SM Endpoints the above will not work as expected. You need to ensure that
source_dir
and our model data are decoupled (i.e they do not get repacked together by the SageMaker SDK) and for this you need to ensure the network isolation is disabled so that the contents ofsource_dir
can be uploaded to s3 and subsequently downloaded by the container during startup.