Aws SageMaker in a nutshell

Nifesimi Ademoye
7 min readApr 22, 2020

In this article, We are going to be covering Amazon SageMaker, and we will start this by mainly answering three questions:

What is SageMaker?
Why use SageMaker?
How does SageMaker work?

What is SageMaker?
AWS (or Amazon) SageMaker is a fully managed service that provides the ability to quickly build, train, tune, deploy, and manage large-scale machine learning (ML) models. SageMaker is a combination of two valuable tools. The first tool is a managed jupyter notebook instance(yes, the same Jupyter notebook you probably have locally installed on your system) except instead of running in a workspace or on your personal computer. Instead, it runs on a virtual machine hosted by Amazon, while the second tool is an API, which simplifies some of the more computationally difficult tasks that we might need to perform, like when we want to train and deploy a machine learning model.

Why Use SageMaker?
The simple answer is that it makes a lot of the machine learning tasks we need to perform much easier For instance, in a machine learning workflow like below:

The notebook can be used to explore and process the data in the highlighted box below:

while the API can help simplify the modeling and deploying steps as highlighted:

How does SageMaker work?
Working in a managed notebook has the added advantage of having access to the SageMaker API. The SageMaker API itself can be thought of as a collection of tools dealing with the training and inference processes. The training process is where the computational task is constructed. Generally, this task is meant to fit a machine learning model to some data, then this task is executed on a virtual machine. The resulting model, such as the tree is constructed in a random tree model or the layers in a neural network, is then saved to a file, and this saved data is called the model artifacts.

The inference process is similar to the training process. First, a computational task is constructed to perform inference, then this task is executed on a virtual machine. In this case, however, the virtual machine waits for us to send it some data. When we do, it takes that data, along with the model artifacts created during the training process, and performs inference, returning the results.

So, in essence, Amazon Sagemaker provides the following tools:
Ground Truth — To label the jobs, datasets, and workforces
Notebook — To create Jupyter notebook instances, configure the lifecycle of the notebooks, and attache Git repositories
Training — To choose an ML algorithm, define the training jobs, and tune the hyperparameter
Inference — To compile and configure the trained models, and endpoints for deployments

The snapshot of the Sagemaker Dashboard below shows the tools mentioned above.

Notice: The AWS UI shown above is subject to change regularly. We advise students to refer to AWS documentation for the above processes.

What makes Amazon SageMaker a “fully managed” service?
SageMaker helps to reduce the complexity of building, training and deploying your ML models by offering all these steps on a single platform. In addition, SageMaker supports building the ML models with modularity, which means you can reuse a model you have already built earlier in other projects.

SageMaker Instances
SageMaker instances are the dedicated VMs optimized to fit different machine learning (ML) use cases. An instance type is characterized by CPU, memory, GPU, GPU memory, and networking capacity. As a result, the supported instance types, names, and pricing in SageMaker are different than that of EC2.

How To set up an Amazon SageMaker

How to Setup Your AWS Account

1. You can create an account by the Amazon Web Services portal and click “Sign in to the Console”. From there you can sign in using an existing Amazon account or create a new account.

2. You will need to provide your details as well as a valid credit card that Amazon can charge. The process is a lot quicker if you are already an Amazon customer and have your credit card on file.

SageMaker Sessions & Execution Roles

SageMaker has some unique objects and terminology that will become more familiar over time. There are a few objects that you’ll see come up, over and over again:

  • Session — A session is a special object that allows you to do things like manage data in S3 and create and train any machine learning models; you can read more about the functions that can be called on a session, at this documentation. The upload_data function should be close to the top of the list! You'll also see functions like train, tune, and create_model all of which we'll go over in more detail, later.
  • Role — Sometimes called the execution role, this is the IAM role that you created when you created your notebook instance. The role basically defines how data that your notebook uses/creates will be stored. You can even try printing out the role with print(role) to see the details of this creation.

Uploading to an S3 Bucket

Another SageMaker detail that is new is the method of data storage. In these instances, we’ll be using S3 buckets for data storage.

S3 is a virtual storage solution that is mostly meant for data to be written to few times and read from many times. This is, in some sense, the main workhorse for data storage and transfer when using Amazon services. These are similar to file folders that contain data and metadata about that data, such as the data size, date of upload, author, and so on.

S3 stands for Simple Storage Service (S3).

The way SageMaker trains and deploy models is the following : a virtual machine will be created and it will have all the properties we want it to have, for example it might come equipped with a GPU or it might have some amount of Ram or some specific amount of processors, whatever we need for the particular task. Then the virtual machine will load an image typically this image is in form of a docker container and in our case we will be using the provided docker container which contains the training and inference code to use XGBoost. In order for the virtual machine to execute the trainin code successfully. it need to access our training data and Sagemaker assumes that this data is available on S3 which is amazon Data storage service. so we need to make sure we upload our data there. In order to upload our data to S3 , we save it locally into a file and upload it.

After you upload data to a session, you should see that an S3 bucket is created, as indicated by an output like the following:

INFO: sagemaker: Created S3 bucket: <message specific to your locale, ex. sagemaker-us-west-1-#>

Note : The return value of this method is a URI which points to that Data on S3.

How to Setup Amazon SageMaker Notebook

  1. You can create an account by the Amazon Web Services portal and click “Sign in to the Console”. From there you can sign in using an existing Amazon account or create a new account.
  2. After signing in, You go to All services, scroll down to Machine Learning under which you click on Amazon SageMaker. This opens up the Sagemaker Dashboard.

3. Then you Create a Notebook Instance by selecting Notebook Instances and click on Create notebook instance, Then choose a notebook instance type appropriate for the task you will be doing Next, under IAM role select Create a new role. You should get a pop-up window that looks like the one below. The only change that needs to be made is to select None under S3 buckets you specify, as is shown in the image below.

4. Once you are done following the instructions, your notebook should look like the notebook below have finished setting up the role for your notebook, your notebook instance settings should look something like the image below.

Note: Your notebook name may be different than the one displayed and the IAM role that appears will be different.

Once your notebook instance has started and is accessible, click on open to get to the Jupyter notebook main page.

This has been AWS SageMaker in a nutshell, and I hope this aided your understanding and answered any question you had about SageMaker.

Originally published at https://dev.to on April 22, 2020.

--

--