aws / sagemaker-python-sdk

A library for training and deploying machine learning models on Amazon SageMaker
https://sagemaker.readthedocs.io/
Apache License 2.0
2.1k stars 1.14k forks source link

Can't override SKLearnModel properties #1429

Open thomelane opened 4 years ago

thomelane commented 4 years ago

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:

Additional context Add any other context about the problem here.

laurenyu commented 4 years ago

sorry for the slow response here as well.

for the three attributes you mentioned: