sagemaker-python-sdk
sagemaker-python-sdk copied to clipboard
Can't override SKLearnModel properties
Describe the bug
I'm trying to deploy a trained estimator to two different endpoints, each with their own model (each with their own entry_point). Since I can't override the entry point the deploying the model, I need to create two models. Ideally I'd like to use the create a SKLearnModel directly from the estimator but override a few properties. Unfortunately, this doesn't work as there are hard set arguments used. See entry_point as an example: https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/sklearn/estimator.py#L186.
Expected behavior
Should be able to set entry_point, name and predictor_cls as follows.
explainer_model = estimator.create_model(
entry_point='explainer_entry_point.py',
name='{}-explainer'.format(estimator.latest_training_job.name),
predictor_cls=CustomJsonPredictor
)
Unfortunately you currently have to do something like:
estimator.entry_point = 'explainer_entry_point.py'
estimator._current_job_name = '{}-explainer'.format(estimator.latest_training_job.name)
explainer_model = estimator.create_model(
predictor_cls=CustomJsonPredictor
)
Which uses a private property (_current_job_name) or be verbose and create a model from scratch:
explainer_model = sagemaker.sklearn.SKLearnModel(
model_data=estimator.model_data,
role=config.SAGEMAKER_IAM_ROLE,
entry_point='explainer_entry_point.py',
source_dir=str(Path(current_folder, 'src').resolve()), # estimator._model_source_dir()
name='{}-explainer'.format(estimator.latest_training_job.name),
code_location='s3://' + str(Path(config.S3_BUCKET, config.OUTPUTS_S3_PREFIX)),
image=str(custom_image),
sagemaker_session=session,
predictor_cls=CustomJsonPredictor
)
Screenshots or logs If applicable, add screenshots or logs to help explain your problem.
System information A description of your system. Please provide:
- SageMaker Python SDK version: 1.55.3
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): SKLearn
- Framework version: 0.20.0-cpu-py3
- Python version: Python 3
- CPU or GPU: CPU
- Custom Docker image (Y/N): Y (but extends SKLearn container from SM)
Additional context Add any other context about the problem here.
sorry for the slow response here as well.
for the three attributes you mentioned:
entry_pointis covered in #1427, sincedeploy()just callscreate_model()nameshould be working now (code). The change was made in this recent commit, which was released in v1.55.4predictor_clsalready can be overridden throughcreate_model()