amazon-sagemaker-examples icon indicating copy to clipboard operation
amazon-sagemaker-examples copied to clipboard

Issue with deploying Mxnet Model using Cloudformation

Open SudheerBondada opened this issue 8 years ago • 17 comments

Hi, We are trying to deploy a mxnet model on sagemaker endpoint through cloudformation. The error we see is 'The primary container for production variant AllTraffic did not pass the ping health check. Please check CloudWatch logs for this endpoint.' There's not much information in the Cloudwatch logs.

Here the details: Location of inference code image: 520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-mxnet:1.2-cpu-py3 Region: us-west-2 Location of Model artifacts: https://s3-us-west-2.amazonaws.com/mxnet-temp/model.tar.gz CF template: https://s3-us-west-2.amazonaws.com/mxnet-temp/endpoint_check.json

To add more context, we only have issues with this algorithm, we were able to deploy models on endpoints successfully using sagemaker built-in algorithms. Could you help us in debugging the issue?

SudheerBondada avatar Aug 22 '18 22:08 SudheerBondada

Hi @SudheerBondada - Creating an AWS Support Case is likely to help you resolve your problem quickest. They'll be able to investigate in more depth based on the information you've provided above. Thanks!

djarpin avatar Aug 22 '18 22:08 djarpin

Hi @djarpin - Thanks for the quick response. We already raised a support request for the same issue with another endpoint. Here is the response from support team, looks like they see the same error as I mentioned above: The Sagemaker service team was able to dig through the backend logs and find the following error message. {EndpointName: Retail-RelevanceToCustomer22,EndpointArn: arn:aws:sagemaker:eu-west-1:167270772459:endpoint/retail-relevancetocustomer22,EndpointConfigName: Retail-RelevanceToCustomer22,EndpointStatus: Failed,FailureReason: The primary container for production variant AllTraffic did not pass the ping health check. Please check CloudWatch logs for this endpoint.,CreationTime: Fri Jul 27 21:43:08 UTC 2018,LastModifiedTime: Fri Jul 27 21:55:22 UTC 2018} Could you please check if there are any meaningful CloudWatch logs for the endpoint? Due to security and privacy reasons, we are unable to access your CloudWatch logs. If you wish to share the logs with us for further support, please refer to the following link for how to export the logs. If not, then please recreate the CloudFormation stack with Rollback on Failure disabled and we can go from there

SudheerBondada avatar Aug 22 '18 22:08 SudheerBondada

Thanks @SudheerBondada - I think sharing the CloudWatch logs would be the way to go here. Sometimes the actual error is just a single line in CloudWatch that gets overwhelmed by the "/ping" lines.

djarpin avatar Aug 22 '18 22:08 djarpin

Hi @djarpin - Here are the complete cloudwatch logs:

2018-08-22 22:04:24,963 INFO - root - running container entrypoint
2018-08-22 22:04:24,964 INFO - root - starting serve task
2018-08-22 22:04:24,964 INFO - container_support.serving - reading config
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:25,094 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTP connection (1): 169.254.170.2
2018-08-22 22:04:25,200 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:25,844 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:26,598 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:27,761 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:29,708 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:33,270 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:40,032 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:04:53,236 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:05:19,279 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:06:10,904 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:07:11,346 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:08:11,856 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com
Downloading s3://sagemaker-us-west-2-558967440381/Mxnetmodel/source/sourcedir.tar.gz to /tmp/script.tar.gz
2018-08-22 22:09:12,269 INFO - botocore.vendored.requests.packages.urllib3.connectionpool - Starting new HTTPS connection (1): sagemaker-us-west-2-558967440381.s3.amazonaws.com

SudheerBondada avatar Aug 22 '18 23:08 SudheerBondada

hi @SudheerBondada, have you tried using a larger instance type? It seems possible the instance is just running out of memory.

I'll try to reproduce on my end later, but I was having issues downloading the model tar you linked to.

laurenyu avatar Aug 23 '18 17:08 laurenyu

Thanks @laurenyu. We did use ml.m4.xlarge ..but that's not huge memory increase from ml.t2.medium. Let me try with a larger instance.

SudheerBondada avatar Aug 23 '18 17:08 SudheerBondada

Hi @laurenyu..We tried ml.m5.12x.large and it failed with the same error as above..let us know when you reproduce this issue at your convenience. If the s3 public link for model artifacts has access issues, please use this: https://drive.google.com/file/d/1kjEUthc-qJ0apadJmTcX_I5zMC5IdVSZ/view?usp=sharing

SudheerBondada avatar Aug 23 '18 18:08 SudheerBondada

hi @SudheerBondada, cool, I was able to download it from Google Drive. Can you also provide your entry script (or something similar but simplified if you need to conceal anything private)?

laurenyu avatar Aug 23 '18 23:08 laurenyu

Hi @laurenyu , Here are all the scripts: Jupyter Notebook : Notebook.zip

CF template: https://s3-us-west-2.amazonaws.com/mxnet-temp/endpoint_check.json

SudheerBondada avatar Aug 24 '18 00:08 SudheerBondada

@SudheerBondada does the notebook succeed for you? It looks like from the output that the endpoint was successfully created.

I was able to create an endpoint locally with what you provided. One thing I noticed in the CF template was that the entry point is an S3 URL - is there a way you can provide that locally instead? I'll try to play around with CF when I next get a chance.

laurenyu avatar Aug 24 '18 18:08 laurenyu

@laurenyu Yes..The model and endpoint are being successfully created from the Notebook. We have issues when we are trying to do the same with CF..Now when you say 'locally' I am not aware if there is a way to pass a local script to CF which deploys a model in PROD..for me S3 url seems to be the only way. Please let me know if I am missing something. FYI - Not only through CF even if I try to create the endpoint from existing model artifacts we get the same error.

SudheerBondada avatar Aug 24 '18 19:08 SudheerBondada

@SudheerBondada I'm less familiar with CF but yeah, I think S3 is the way to go. Sorry, I think what I was thinking is we should find a way to provide a relative path, like with how the Estimator allows for a source_dir that can be S3, and then just a relative path for the entry point. What happens if you change the value for SAGEMAKER_PROGRAM to just "recommender.py" in the CF template?

fwiw, I was able to create an endpoint from the existing model artifacts with

from sagemaker.mxnet import MXNetModel

m = MXNetModel('s3://<bucket>/model.tar.gz', 'SageMakerRole', 'recommender.py')
m.deploy(1, 'ml.m4.xlarge')

laurenyu avatar Aug 24 '18 20:08 laurenyu

Thanks @laurenyu, What happens if you change the value for SAGEMAKER_PROGRAM to just "recommender.py" in the CF template? I believe this would throw an error because CF cannot pick the location..Please let us know if this particular model and endpoint can be deployed through CF instead of code.

SudheerBondada avatar Aug 24 '18 21:08 SudheerBondada

@SudheerBondada sorry I wasn't clear. I was suggesting to set SAGEMAKER_PROGRAM to just "recommender.py" while keeping SAGEMAKER_SUBMIT_DIRECTORY as "s3:///Mxnetmodel/source/sourcedir.tar.gz" - SageMaker will look for the file in the uncompressed source dir.

There's not a good way to do this with the MXNetModel class in the Python SDK, but I was able to do it through the generic Model class after uploading the script to S3 separately:

from sagemaker.model import Model

env = {
    'SAGEMAKER_CONTAINER_LOG_LEVEL': '20',
    'SAGEMAKER_ENABLE_CLOUDWATCH_METRICS': 'false',
    'SAGEMAKER_PROGRAM': 'recommender.py',
    'SAGEMAKER_REGION': 'us-west-2',
    'SAGEMAKER_SUBMIT_DIRECTORY': 's3://<bucket>/sourcedir.tar.gz',
}

m = Model('s3://<bucket>/model.tar.gz',
          '520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-mxnet:1.2-cpu-py3',
          'SageMakerRole',
          env=env)

m.deploy(1, 'ml.m4.xlarge')

This did succeed in creating an endpoint for me. My sourcedir.tar.gz simply contained the recommender.py file (not in any directory).

laurenyu avatar Aug 24 '18 23:08 laurenyu

@laurenyu Based on your suggestion I modified the template as below, it still failed with the same error. CF template: https://s3-us-west-2.amazonaws.com/mxnet-temp/endpoint_check.json Model artifacts: https://s3-us-west-2.amazonaws.com/mxnet-temp/model.tar.gz Sagemaker submit directory: https://s3-us-west-2.amazonaws.com/mxnet-temp/sourcedir.tar.gz (contains recommender.py) All the above links are public, could you try to launch the CF template on your end?

SudheerBondada avatar Aug 25 '18 00:08 SudheerBondada

@SudheerBondada I was able to launch an endpoint through CF with the following template:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Endpoint creation",
    "Parameters": {
    },
    "Mappings": {
        "RegionMap": {
            "us-west-2": {
                "MXnetTest": "520713654638.dkr.ecr.us-west-2.amazonaws.com/sagemaker-mxnet:1.2-cpu-py3"
          }
        }
    },
    "Resources": {
        "MxnetModel":{
            "Type" : "AWS::SageMaker::Model",
            "Properties" : {
                "ExecutionRoleArn" : "arn:aws:iam::<account>:role/SageMakerRole",
                "PrimaryContainer" :
                {
                    "ContainerHostname" : "MxnetContainer",
                    "Environment" : {"SAGEMAKER_CONTAINER_LOG_LEVEL": "20",
                                     "SAGEMAKER_ENABLE_CLOUDWATCH_METRICS": false,
                                     "SAGEMAKER_PROGRAM": "recommender.py",
                                     "SAGEMAKER_REGION": {"Ref": "AWS::Region"},
                                     "SAGEMAKER_SUBMIT_DIRECTORY": "s3://<bucket>/sourcedir.tar.gz"},
                    "ModelDataUrl" : "s3://<bucket>/model.tar.gz",
                    "Image": { "Fn::FindInMap" : ["RegionMap",{"Ref": "AWS::Region"}, "MXnetTest"] }
                },
                "ModelName" : "Mxnetmodel"
            }
        },
        "MxnetEndpointConfiguration":{
            "Type" : "AWS::SageMaker::EndpointConfig",
            "DependsOn": "MxnetModel",
            "Properties" : {
                "ProductionVariants": [
                    {
                        "ModelName" : {"Fn::GetAtt":["MxnetModel","ModelName"]},
                        "VariantName": "AllTraffic",
                        "InitialInstanceCount" : 1,
                        "InstanceType" : "ml.m4.xlarge",
                        "InitialVariantWeight" : 1
                    }
                ],
                "EndpointConfigName" : "MxnetEndpointConfig"
            }
        },
        "RetailRelevanceToCustomerEndpoint26": {
            "Type": "AWS::SageMaker::Endpoint",
            "DependsOn": "MxnetEndpointConfiguration",
            "Properties": {
                "EndpointName": "MxnetEndpoint",
                "EndpointConfigName": { "Fn::GetAtt" : ["MxnetEndpointConfiguration", "EndpointConfigName" ] }
            }
        },
        "Handle": {
            "Type": "AWS::CloudFormation::WaitConditionHandle"
        }
    },
    "Outputs": {
    }
}

where I downloaded recommender.py and model.tar.gz from your links, and tar-ed up recommender.py on its own into sourcedir.tar.gz

laurenyu avatar Aug 27 '18 17:08 laurenyu

Thanks for the help @laurenyu..this works for me as well. Fixed some issues with tar utilities on my local while packing source.dir.tar.gz.

SudheerBondada avatar Aug 27 '18 18:08 SudheerBondada