{"id":4859,"date":"2022-04-26T11:23:20","date_gmt":"2022-04-26T11:23:20","guid":{"rendered":"https:\/\/petabytz.com\/?p=4859"},"modified":"2026-02-19T11:19:48","modified_gmt":"2026-02-19T11:19:48","slug":"deploy-machine-learning-models-on-aws-sagemaker","status":"publish","type":"post","link":"https:\/\/petabytz.com\/blogs\/deploy-machine-learning-models-on-aws-sagemaker\/","title":{"rendered":"Deploy machine learning models on AWS Sagemaker."},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4859\" class=\"elementor elementor-4859\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-291864a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"291864a\" data-element_type=\"section\" data-e-type=\"section\" data-settings=\"{&quot;ekit_has_onepagescroll_dot&quot;:&quot;yes&quot;}\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-82d0ae3\" data-id=\"82d0ae3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-51512a2 elementor-widget elementor-widget-heading\" data-id=\"51512a2\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h1 class=\"elementor-heading-title elementor-size-default\">Deploy machine learning models on AWS Sagemaker.<\/h1>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-ae1810c elementor-widget elementor-widget-image\" data-id=\"ae1810c\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" data-src=\"https:\/\/petabytz.com\/wp-content\/uploads\/2022\/04\/15.png\" title=\"\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1b62fcf elementor-widget elementor-widget-text-editor\" data-id=\"1b62fcf\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"922a\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\"><em class=\"ke\">What is Sagemaker..?<\/em><\/strong><\/p><p id=\"6f3e\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Amazon SageMaker provides every developer and data scientist with the ability to build, train, and deploy machine learning models quickly. Amazon SageMaker is a fully-managed service that covers the entire machine learning workflow to label and prepare your data, choose an algorithm, train the model, tune and optimize it for deployment, make predictions, and take action. Your models get to production faster with much less effort and lower cost.<\/p><p id=\"0a46\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\"><em class=\"ke\">What is the need of Sagemaker..!<\/em><\/strong><\/p><p id=\"ee83\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">SageMaker is a managed service offering from AWS with the intent of simplifying the process of building, training, and deploying machine learning models. Typically, developers have to spend a lot of time and effort during various stages of incorporating machine learning in their applications. They have to first find the right sources to collate the training data and then find the best algorithm as per their need. They will also set up training environments and start training the model mostly through trial and error. And finally, they will deploy the model on production. But the peril does not end here; the team also has to scale and manage the production environment.<\/p><p id=\"07e9\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Three major steps in creating a successful machine learning model:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6679aaf elementor-widget elementor-widget-image\" data-id=\"6679aaf\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" data-src=\"https:\/\/petabytz.com\/wp-content\/uploads\/2022\/04\/0_p8_8vNdeuxBFUnV7.png\" title=\"\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-69543bc elementor-widget elementor-widget-text-editor\" data-id=\"69543bc\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"19ab\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\">Build<\/strong>:A good machine learning model requires large volumes of data \u2014 which is hard to collate \u2014 and a manual labeling process, which may take several weeks to complete. AWS offers SageMaker GroundTruth, which uses machine learning to automatically label data and results in considerable time savings. GroundTruth can also work hand-in-hand with manual labeling. This actually makes GroundTruth even better in labeling over a period of time. Where GroundTruth has high confidence is in the results it obtained previously. There, it will apply labels automatically on similar raw data, else it will forward the data for manual intervention.<\/p><p id=\"d3f0\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\">Train:<\/strong>Training in SageMaker is very easy. Simply specify the S3 location containing data, choose the number and types of instances where the computing will be done, and launch the training by clicking a button in the AWS Console. SageMaker applies the algorithm you chose, builds the cluster of auto-scaling instances, and applies the chosen algorithm.<\/p><p id=\"0c18\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Automatic Model Tuning is another salient feature of SageMaker. Typically, to train data, you need to provide a variety of data to the model and provide the hyperparameters. SageMaker helps you with the first part by applying machine learning to ascertain the kind and variety of data to apply. It learns the effect that a particular type of data has on the tuning of the model and then subsequently applies that learning on the data.<\/p><p id=\"4b60\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\">Deploy<\/strong>:Deployment of your model using SageMaker gives you all the benefits of a Cloud provider \u2014 it is here that you truly utilize the Cloud power. Using the AWS Console, you deploy the model on a cluster of highly available compute instances that auto-scale as needed. Just like other AWS Compute services, SageMaker also takes care of monitoring the health of instances, ensures security by applying patches, and takes care of their maintenance. SageMaker integrates with CloudWatch where suitable metrics can be set up and alarms can be triggered so that timely action can be taken. It also connects with CloudWatch Logs, where you can see and debug your model\u2019s execution.<\/p><p id=\"ef31\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\"><em class=\"ke\">Do we really need a platform?<\/em><\/strong><\/p><p id=\"cfeb\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">The most effective way to solve large ML problems is by aiding a data scientist with the necessary software skills in neat abstract yet effective way to deliver an ML solution as a highly scalable web-service (API). The software development team can integrate the API into the required software systems and abstract the ML service as just another service wrapped around an API. (Software engineers love APIs). Therefore, we need a platform that can enable a data scientist with the necessary tools to independently execute a machine learning project in a truly end-to-end way.<\/p><p id=\"45b1\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\"><strong class=\"jr kd\"><em class=\"ke\">HOW can a platform solve this problem?<\/em><\/strong><\/p><p id=\"cd76\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">We can solve the problems discussed above if we have a platform that supplements the required remainder skills in each of these phases with neat abstractions while still being highly effective and flexible for a data scientist to deliver results.<\/p><p id=\"916b\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Thus, we need a platform where the data scientist will be able to leverage his existing skills to engineer and study data, train and tune ML models and finally deploy the model as a web-service by dynamically provisioning the required hardware, orchestrating the entire flow and transition for execution with simple abstraction and provide a robust solution that can scale and meet demands elastically.<\/p><h2 id=\"8fe3\" class=\"kh ki bm bc bb fx kj kk kl km kn ko kp kq kr ks kt\" data-selectable-paragraph=\"\">How to Write the image in Sagemaker:<\/h2><p id=\"b263\" class=\"jp jq bm bc jr b js ku ju kv jw kw jy kx ka ky kc\" data-selectable-paragraph=\"\">Since SageMaker machine learning training jobs are managed using Docker image, the first step to running the job is building the container.<\/p><p id=\"f6fa\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">When SageMaker launches a training image it injects a handful of files and environment variables from the estimator definition. The full list of resources injected is provided\u00a0<a class=\"ci ce kz la lb lc\" href=\"https:\/\/docs.aws.amazon.com\/sagemaker\/latest\/dg\/your-algorithms-training-algo.html?shortFooter=true#your-algorithms-training-algo-dockerfile\" target=\"_blank\" rel=\"noopener noreferrer\">in the documentation<\/a>. AWS uses these context clues to configure pre-built algorithm runs, but it doesn\u2019t require that custom training jobs do the same, so you can ignore these until you actually need them.<\/p><p id=\"dc4b\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">SageMaker also in turn it expects the image to write outputs to specific places inside the container:<\/p><ul class=\"\"><li id=\"ede8\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc ld le lf\" data-selectable-paragraph=\"\"><code class=\"jj lg lh li lj b\">\/opt\/ml\/output\/failure<\/code>. If the training job fails, AWS SageMaker recommends writing the reason why to this file, however this is completely optional.<\/li><li id=\"c85f\" class=\"jp jq bm bc jr b js lk ju ll jw lm jy ln ka lo kc ld le lf\" data-selectable-paragraph=\"\"><code class=\"jj lg lh li lj b\">\/opt\/ml\/model<\/code>, This directory is expected to contain a list of model artifacts created by the training job. AWS SageMaker will automatically harvest the files in this folder at the end of the training run,\u00a0<code class=\"jj lg lh li lj b\">tar<\/code>\u00a0them, and upload them to S3.<\/li><\/ul><p id=\"db01\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">With that in mind, let\u2019s examine an example Docker image that\u2019s SageMaker compatible. Starting with the\u00a0<code class=\"jj lg lh li lj b\">Dockerfile<\/code>:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8318203 elementor-widget elementor-widget-image\" data-id=\"8318203\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" data-src=\"https:\/\/petabytz.com\/wp-content\/uploads\/2022\/04\/1_k0eZKm3JfxGDdJmxNlzxQQ.png\" title=\"\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/>\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2c51733 elementor-widget elementor-widget-text-editor\" data-id=\"2c51733\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;ekit_we_effect_on&quot;:&quot;none&quot;}\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p id=\"f149\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">The SageMaker job runner requires that your container image define an\u00a0<code class=\"jj lg lh li lj b\">ENTRYPOINT<\/code>\u00a0using the exec syntax (e.g.\u00a0<code class=\"jj lg lh li lj b\">ENTRYPOINT [\"some\", \"commands\"]<\/code>), not the shell syntax (e.g.\u00a0<code class=\"jj lg lh li lj b\">ENTRYPOINT some command<\/code>), as it needs to be able to send\u00a0<code class=\"jj lg lh li lj b\">SIGTERM<\/code>\u00a0and\u00a0<code class=\"jj lg lh li lj b\">SIGKILL<\/code>\u00a0signals to the container.<\/p><p id=\"f433\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Additionally, when executing the container the SageMaker job runner will pass a run-time argument. If it is running the container in training model this will be\u00a0<code class=\"jj lg lh li lj b\">train<\/code>; if the image is being deployed to an endpoint this will be\u00a0<code class=\"jj lg lh li lj b\">deploy<\/code>. If you use the same image for both training your model and for deploying it, you will need to parse this argument to check which mode the container is executing in.<\/p><p id=\"cf7e\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">That\u2019s it \u2014 that\u2019s the full list of restrictions SageMaker places on your image configuration!<\/p><p id=\"4c11\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">Conclusion:<\/p><p id=\"4f73\" class=\"jp jq bm bc jr b js jt ju jv jw jx jy jz ka kb kc\" data-selectable-paragraph=\"\">AWS Sagemaker has been a great deal for most data scientists who would want to accomplish a truly end-to-end ML solution. It takes care of abstracting a ton of software development skills necessary to accomplish the task while still being highly effective and flexible and cost-effective. Most importantly, it helps you focus on the core ML experiments and supplements the remainder necessary skills with easy abstracted tools similar to our existing workflow.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Deploy machine learning models on AWS Sagemaker. What is Sagemaker..? Amazon SageMaker provides every developer and data scientist with the ability to build, train, and deploy machine learning models quickly. Amazon SageMaker is a fully-managed service that covers the entire machine learning workflow to label and prepare your data, choose an algorithm, train the model, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,28],"tags":[],"class_list":["post-4859","post","type-post","status-publish","format-standard","hentry","category-blogs","category-cloud"],"acf":[],"_links":{"self":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/comments?post=4859"}],"version-history":[{"count":3,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4859\/revisions"}],"predecessor-version":[{"id":14762,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/posts\/4859\/revisions\/14762"}],"wp:attachment":[{"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/media?parent=4859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/categories?post=4859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/petabytz.com\/blogs\/wp-json\/wp\/v2\/tags?post=4859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}