Repository navigation
Closed
Labels
Description
I've seen a number of other issues related to this but I just can't seem to figure out what is wrong.
I have a trained pytorch model (outside sagemaker), which I've successfully been able to load into sagemaker. The bit that loads the model is :
def deploy():
role = sagemaker.get_execution_role()
print("Deploying model")
client = boto3.client('sagemaker')
try:
des = client.describe_endpoint(EndpointName="my-model")
print("Endpoint exists. Deleting.")
client.delete_endpoint(EndpointName="my-model")
client.delete_endpoint_config(EndpointConfigName="my-model")
except ClientError:
pytorch_model = PyTorchModel(
model_data="s3://my-model-bucket/model.tar.gz",
name="my-model",
framework_version='1.5.0',
role=role,
source_dir="project_root/model_source",
entry_point='project_root/model_source/serve.py')
predictor = pytorch_model.deploy(
instance_type="ml.m4.xlarge",
initial_instance_count=1)
predictor.content_type = 'application/json'
predictor.serializer = json_serializer
predictor.deserializer = json_deserializerThe serve.py script contains:
def model_fn(model_dir):
print('\nLoading model ...')
model = load_model(MODEL_DIR, CHECKPOINT, features_dicts)
return model
def predict_fn(input_data, model):
return model(input_data)
def output_fn(prediction, content_type):
return prediction
def input_fn(request_body, request_content_type):
return json.dumps(request_body)Now, I can confirm that the serve.py script contains all the required functions. But for some reason, whenever I invoke my endpoint, I get an error in my cloudwatch logs.
2020-05-07T16:39:14.599+02:00 | java.lang.IllegalArgumentException: reasonPhrase contains one of the following prohibited characters: \r\n:
-- | --
| 2020-05-07T16:39:14.599+02:00 | Please provide a model_fn implementation.
| 2020-05-07T16:39:14.599+02:00 | See documentation for model_fn at https://github.com/aws/sagemaker-python-sdk
Questions:
- What am I doing wrong?
- Should the entrypoint be in the source_dir or outside it?
Expected behavior
I expect the response of the model invocation
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.56.2
- Framework name (eg. PyTorch) or algorithm (eg. KMeans): Pytorch
- Framework version: 1.5.0
- Python version: 3.7
- CPU or GPU: CPU
- Custom Docker image (Y/N): N
Additional context
Add any other context about the problem here.
Activity
nadiaya commentedon May 8, 2020
I believe putting relative path to the entrypoint from the source dir should solve the problem:
Olamyy commentedon May 11, 2020
Thank you @nadiaya. That seems to solve the issue.
My current challenge is this:
I get this error when I try to invoke my endpoint. However, when I go to the attached url, there doesn't seem to be any log in the cloudwatch that points to the error. Where should this error be logged in cloudwatch? Under endpoints or models? I've checked both. There's no log of the error there.
Add optimize to ModelBuilder (aws#1468)
feature: model optimization (#4775)
feature: model optimization (aws#4775)