2

If I instantiate a SageMaker PyTorchModel object like this:

from sagemaker.pytorch import PyTorchModel

model = PyTorchModel(name=name_from_base('model-name'),
                     model_data=model_data,
                     role=role,
                     framework_version='1.0.0',
                     entry_point='serve.py',
                     source_dir='src',
                     sagemaker_session=sagemaker_session,
                     predictor_cls=ImagePredictor)

#model.create_without_deploying??

Is there a way that I can create this model using the sagemaker python SDK so that the model shows up in the SageMaker console, but without actually deploying it to an endpoint?

1 Answer 1

1

I don't think it is possible to do so using the high-level SageMaker Pyhton SDK. However, you should be able to do it by calling the CreateModel API using the low-level boto3 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker.html#SageMaker.Client.create_model. For your reference, below is an example snippet code on how to do it.

%%time
import boto3
import time

sage = boto3.Session().client(service_name='sagemaker')

image_uri = '520713654638.dkr.ecr.us-east-1.amazonaws.com/sagemaker-pytorch:1.0.0-cpu-py3'
model_data ='s3://<bucket>/<prefix>/output/model.tar.gz'
source = 's3://<bucket>/<prefix>/sourcedir.tar.gz'
role = 'arn:aws:iam::xxxxxxxx:role/service-role/AmazonSageMaker-ExecutionRole-xxxxxx'

timestamp = time.strftime('-%Y-%m-%d-%H-%M-%S', time.gmtime())
model_name = 'my-pytorch-model' + timestamp

response = sage.create_model(
    ModelName=model_name,
    PrimaryContainer={
        'Image': image_uri,
        'ModelDataUrl': model_data,
        'Environment': { 'SAGEMAKER_CONTAINER_LOG_LEVEL':'20', 'SAGEMAKER_ENABLE_CLOUDWATCH_METRICS': 'False', 
                   'SAGEMAKER_PROGRAM': 'generate.py','SAGEMAKER_REGION': 'us-east-1','SAGEMAKER_SUBMIT_DIRECTORY': source}
         },
         ExecutionRoleArn=role
}
print(response)

If you get no error message, then the model will shows up in the SageMaker console

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.