Desp
Desp

Reputation: 195

Clienterror: An error occured when calling the CreateModel operation

I want to deploy sklearn model in sagemaker. I created a training script.

scripPath=' sklearn.py'

sklearn=SKLearn(entry_point=scripPath, train_instance_type='ml.m5.xlarge', role=role, output_path='s3://{}/{}/output'.format(bucket,prefix), sagemaker_session=session) sklearn.fit({"train-dir' : train_input})

When I deploy it predictor=sklearn.deploy(initial_count=1,instance_type='ml.m5.xlarge')

It throws, Clienterror: An error occured when calling the CreateModel operation:Could not find model data at s3://tree/sklearn/output/model.tar.gz

Can anyone say how to solve this issue?

Upvotes: 0

Views: 2461

Answers (1)

Olivier Cruchant
Olivier Cruchant

Reputation: 4037

When deploying models, SageMaker looks up S3 to find your trained model artifact. It seems that there is no trained model artifact at s3://tree/sklearn/output/model.tar.gz. Make sure to persist your model artifact in your training script at the appropriate local location in docker which is /opt/ml/model. for example, in your training script this could look like:

joblib.dump(model, /opt/ml/model/mymodel.joblib)

After training, SageMaker will copy the content of /opt/ml/model to s3 at the output_path location.

If you deploy in the same session a model.deploy() will map automatically to the artifact path. If you want to deploy a model that you trained elsewhere, possibly during a different session or in a different hardware, you need to explicitly instantiate a model before deploying

from sagemaker.sklearn.model import SKLearnModel

model = SKLearnModel(
    model_data='s3://...model.tar.gz',  # your artifact
    role=get_execution_role(),
    entry_point='script.py')  # script containing inference functions

model.deploy(
    instance_type='ml.m5.xlarge',
    initial_instance_count=1,
    endpoint_name='your_endpoint_name')

See more about Sklearn in SageMaker here https://sagemaker.readthedocs.io/en/stable/using_sklearn.html

Upvotes: 1

Related Questions