how to run an inference in sagemaker pipeline?

0

based on the docs here https://github.com/aws-samples/sagemaker-pipelines-callback-step-for-batch-transform/blob/main/batch_transform_with_callback.ipynb, a separate pipeline is created to perform a batch transform within sagemaker pipeline. the example utilizes a lambda and sqs to achieve this. couldn't the batch transform job can simply be part of the training pipeline? once the model is trained, and added to model registry, one should be able to query the registry and get the latest model and run a batch transformation job on that, without the callback set up in the docs, right? any examples of running a batch transform job directly from a training pipeline?

asked a year ago1374 views
3 Answers
1
Accepted Answer

Hi,

The solution can be various and it depends on what you are trying to achieve. In general, I believe it is a good idea to build a generic pipeline and utilize parameters for different jobs. The image below shows a typical ML pattern with stages.

Enter image description here

You can use condition steps to orchestrate Sagemaker jobs, more information with code examples are below:

https://sagemaker-examples.readthedocs.io/en/latest/sagemaker-pipelines/tabular/abalone_build_train_deploy/sagemaker-pipelines-preprocess-train-evaluate-batch-transform.html

Hope it helps,

AWS
Jady
answered a year ago
  • @Jady - thank you again. I went through both of the docs and it helped. based on your second comment/docs, all of the processing step , training step , model creation, register, transform ... , all are defined and executed as part of a single pipeline. based on my use case, i would like to have separate pipelines for some of these steps, let's say one pipeline for processing and training, then another pipeline for model creation and registering , and another for testing and so forth. is that possible and if yes, how would one tie these pipelines/artifacts from one pipeline to another ? apologize for adding more question, but promise this is the last thing i'm wondering

1

Hi,

To schedule the batch transformation job with the latest approved model, using a Lambda with an EventBridge rule is (as of today) the best way to achieve their use-case - please find the custom project template for batch inference you could leverage here:

https://github.com/aws-samples/sagemaker-custom-project-templates/tree/main/batch-inference

In addition you could also add a Transform Step at the end of their SageMaker Pipelines to automatically rely on BatchTransform to achieve their inference once training is done. Reference is here:

https://docs.aws.amazon.com/sagemaker/latest/dg/build-and-manage-steps.html#step-type-transform

Thanks,

AWS
Jady
answered a year ago
  • @Jady - thanks. I went through the samples you have provided and looks straightforward. looks like adding a transformer and transformer step , in my current notebook should work. also, is there a way i can extend this, meaning if i copy paste this part of the code to my each notebook, it will work. but i also want to be able to reuse this code in different projects/pipeline. so that i don't have to copy this to every notebook. do i set up a different pipeline alltogether , just for this and utilize the parameters that i can set at the runtime for my different experiments , but how do i connect my training pipeline with my batch testing pipeline , in this case. or is there a different way or better way to do this

1

Hi,

I am glad you find the answer is useful.

I have some suggestions which might help, though I I did not connect multiple sagemaker pipelines together.

Please check AWS EventBridge -

  1. The EventBridge event can be configured to trigger a sagemaker pipeline state changes, reference is here: https://docs.aws.amazon.com/sagemaker/latest/dg/automating-sagemaker-with-eventbridge.html#eventbridge-pipeline
  2. EventBridge event can trigger you consequent sagemaker pipeline, reference: https://docs.aws.amazon.com/sagemaker/latest/dg/pipeline-eventbridge.html#pipeline-eventbridge-schedule

Alternatively, you may use a Lambda as last step of pipeline to triggers next pipeline but you will have overhead of managing the lambda.

Thanks,

AWS
Jady
answered a year ago

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