How do you pass an S3 path as a parameter in an asynchronous inference call to a model in SageMaker?

0

I have the endpoint of an asynchronous model in SageMaker, I want to configure the call to the endpoint and in this pass it an s3 route, where I want the model output to be saved.

1 Answer
1

To pass an S3 path as a parameter for the output location in an asynchronous inference call to a SageMaker model, you need to configure the AsyncInferenceConfig object when creating your endpoint configuration. This object allows you to specify where the results of your asynchronous inference will be stored.

When invoking the asynchronous endpoint, you'll use the InvokeEndpointAsync API. Here's how you can set it up:

  1. First, create an AsyncInferenceConfig object. In this object, you'll specify the S3 output path where you want the model's output to be saved. For example:

AsyncInferenceConfig={ "OutputConfig": { "S3OutputPath": "s3://your-bucket-name/your-output-prefix" } }

  1. Use this AsyncInferenceConfig when creating your endpoint configuration.

  2. When you're ready to invoke the endpoint, you'll use the InvokeEndpointAsync API. In this call, you don't directly pass the S3 output path as a parameter. Instead, SageMaker uses the output location you specified in the AsyncInferenceConfig when you created the endpoint.

  3. The InvokeEndpointAsync call will return a response object. This response includes an 'OutputLocation' field, which contains the S3 URI where the output will be stored.

Here's a basic example of how you might invoke the endpoint:

response = sagemaker_runtime.invoke_endpoint_async( EndpointName='your-endpoint-name', InputLocation='s3://input-bucket/input-file', InferenceId=str(uuid.uuid4()), ContentType='your-content-type' )

output_location = response['OutputLocation']

Remember, the actual output will be stored in the S3 location you specified when creating the endpoint, not in the location returned by this call. The OutputLocation in the response just confirms where SageMaker will place the results.

By following these steps, you can ensure that your asynchronous inference results are saved to the S3 path you specified when setting up the endpoint.
Sources
Run computer vision inference on large videos with Amazon SageMaker asynchronous endpoints | AWS Machine Learning Blog
Asynchronous inference - Amazon SageMaker AI
Check prediction results - Amazon SageMaker AI

profile picture
answered 24 days ago
profile picture
EXPERT
reviewed 24 days ago
  • I need to make different calls, and for each call, I need to specify a different path to save the model results.

    Is this possible?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions