Nick
Nick

Reputation: 51

AWS sagemaker invokeEndpoint model internal error

I am trying to send a request on a model on sagemaker using .NET. The code I am using is:

var data = File.ReadAllBytes(@"C:\path\file.csv");
var credentials = new Amazon.Runtime.BasicAWSCredentials("","");
var awsClient = new AmazonSageMakerRuntimeClient(credentials, RegionEndpoint.EUCentral1);
var request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest
{
    EndpointName = "EndpointName",
    ContentType = "text/csv",
    Body = new MemoryStream(data),
};

var response = awsClient.InvokeEndpoint(request);
var predictions = Encoding.UTF8.GetString(response.Body.ToArray());

the error that I am getting on awsClient.InvokeEndpoint(request)

is:

Amazon.SageMakerRuntime.Model.ModelErrorException: 'The service returned an error with Error Code ModelError and HTTP Body: {"ErrorCode":"INTERNAL_FAILURE_FROM_MODEL","LogStreamArn":"arn:aws:logs:eu-central-1:xxxxxxxx:log-group:/aws/sagemaker/Endpoints/myEndpoint","Message":"Received server error (500) from model with message \"\". See "https:// url_to_logs_on_amazon" in account xxxxxxxxxxx for more information.","OriginalMessage":"","OriginalStatusCode":500}'

the url that the error message suggests for more information does not help at all.

I believe that it is a data format issue but I was not able to find a solution.

Does anyone has encountered this behavior before?

Upvotes: 3

Views: 6248

Answers (1)

Nick
Nick

Reputation: 51

The problem relied on the data format as suspected. In my case all I had to do is send the data as a json serialized string array and use ContentType = application/json because the python function running on the endpoint which is responsible for sending the data to the predictor was only accepting json strings.

Another way to solve this issues is to modify the python function which is responsible for the input handling to accept all content types and modify the data in a way that the predictor will understand.

example of working code for my case:

        var data = new string[] { "this movie was extremely good .", "the plot was very boring ." };
        var serializedData = JsonConvert.SerializeObject(data);

        var credentials = new Amazon.Runtime.BasicAWSCredentials("","");
        var awsClient = new AmazonSageMakerRuntimeClient(credentials, RegionEndpoint.EUCentral1);
        var request = new Amazon.SageMakerRuntime.Model.InvokeEndpointRequest
        {
            EndpointName = "endpoint",
            ContentType = "application/json",
            Body = new MemoryStream(Encoding.ASCII.GetBytes(serializedData)),
        };

        var response = awsClient.InvokeEndpoint(request);
        var predictions = Encoding.UTF8.GetString(response.Body.ToArray());

Upvotes: 2

Related Questions