R Model Training and Deployment on AWS Sagemaker
Problem statement:
Aim was to write model in R and use sagemaker api deploy endpoint.
Working:
Model writing, training and deploy in sagemaker needs following task.
- Write Model code in R- we use reticulate. It embdeds python session within R session. This allows us to use sagemaker estimator. we can use jupyter notebook or RStudio. In this case i used RStudio to create model(wrote the code in R)
- Create Sample R docker container. Refer the link
- Fetching data and do some pre processing work.AWS sagemaker provides PreProcessing job to do this. R Preproceeeing Job SagemakerREEProcess. Python Pre processing Job SagemakerPyPreProcess
- Training Job- Sagemaker provide training Job to train model. SagemakerRCodeTrainingStep
- Deploy Model- Sagemaker Estimator does the deployment of endpoint on sagemaker.
print("===============DEPLOY===============")
model_endpoint <- estimator$deploy(initial_instance_count = 1L,
instance_type = 'ml.t2.medium')
5. Expose the endpoint through API Gateway-Refer Resources section
Design:
This article is based on Bring your own algorithm, as not all AI/ML pipeline can. Data scientists writes code in R , There are very few article about CI/CD using R model on AWS Sage maker(I may be wrong).There are plenty article on Python CI/CD. So i decided to create one and post it for others to use it.
Summary:
This article is aims to create, train and deploy R Model on
- Create Sample R docker container
- Sample R Model code
- Preprocessing Job(Python)
- Train it on AWS Sagemaker using sagemaker training job
- Deploy it using serverless.com
- CI/CD pipeline
Reference:
https://github.com/chrisrana/r-model-sagemaker-api/blob/main/devops/serverless.yml