image: thumbnail.jpg
James Blair | Using RStudio on Amazon SageMaker | RStudio
Presented by James Blair
*please note that this meetup will share a new update about our professional product, RStudio Workbench. All are welcome, but just wanted to make sure to share that upfront :)
https://www.rstudio.com/products/workbench/
Agenda:
Presentation & Demo - 40 minutes
Q&A with both RStudio & AWS SageMaker team - 20 minutes
Amazon SageMaker helps data scientists and developers to build, train, and deploy machine learning models quickly by bringing together a broad set of capabilities purpose-built for machine learning. RStudio recently announced the release of RStudio on Amazon SageMaker, developed in collaboration with the SageMaker team. This brings a fully-managed RStudio Workbench IDE into the powerful SageMaker environment.
With this functionality, Data Scientists can quickly get to work, spinning up their favorite development environment on SageMaker, choosing from a wide array of instance types as needed. They can get access to their organization’s data stored on AWS, as well as all of SageMaker’s deep learning capabilities.
As a fully managed offering on Amazon SageMaker, this release makes it easy for DevOps teams and IT Admins to administer, secure, and scale their organization’s centralized data science infrastructure, using familiar AWS tools and frameworks.
Here are James' slides as well: https://github.com/blairj09-talks/rstudio-sagemaker-webinar
Answers to the Q&A are shared in this blog post: https://www.rstudio.com/blog/using-rstudio-on-amazon-sagemaker-faq/
Transcript#
This transcript was generated automatically and may contain errors.
Awesome, great. So today our topic, like Rachel mentioned, is RStudio and SageMaker. And maybe, I don't know if an apology is the right phrase here, but I have a two-year-old son who's very into Spider-Man right now. And as a result, I recently rewatched Into the Spider-Verse, which is one of my all-time favorite movies. And that's like heavily influenced the direction that these slides have gone today. So hopefully that makes sense. And if not, we can just focus on the content and less on the style that they're presented in.
But I actually kind of thought this fit because as we go through this, I consider both RStudio and SageMaker both kind of superheroes in their own way in the data science space. And we're excited about this collaboration and the ways in which they can complement and kind of work with one another. And we'll talk through that today. Again, as Rachel said, my name is James Blair, and I work as a solutions engineer here at RStudio.
Overview of the agenda
Just to give kind of an outline of the plan for today. First, we're just gonna talk briefly about RStudio Workbench. I'm operating under the assumption that many of us are probably already familiar with RStudio or RStudio Workbench to some degree. But for those who may not be, we'll just run through kind of a brief introduction of what that tool is. We'll also do the same for SageMaker. And then we'll talk about RStudio Workbench and SageMaker together and what that offers. We'll look at a little bit of a demonstration and then provide some resources for you to continue learning on your own and then answer any questions that come up through the course of the presentation.
RStudio Workbench
So RStudio Workbench is at its core an R-centric development environment. If you've used the RStudio open source software, either at the desktop level or through RStudio server, you're likely familiar with this experience. You have a development environment that gives you lots of tooling around working with R. Ways to manage packages, ways to manage your environment, edit files, write code, debug. All these tools are part of the RStudio development environment.
RStudio Workbench gives you this environment accessible through a browser. It's typically something that organizations will install, host and manage within their own infrastructure, within their own firewalls. We'll talk about how that model's a little bit different with SageMaker throughout the course of our presentation today. One of the things that RStudio Workbench provides that you don't find in the open source version is you have the opportunity to support multiple versions of R concurrently. And there's some additional functionality that's also available related to security and scalability in RStudio Workbench itself.
Another kind of important component of the RStudio development environment, especially as it relates to the topic today, is that there are tools there for Python interoperability. So the ability to work in R and Python kind of simultaneously is something that's available. And that's not restrictive just to RStudio Workbench. That's just a feature of really the R language, but there's some tooling inside of RStudio, the development environment, that make it a little bit easier to work with Python frameworks within kind of within an R context. And we'll talk to why that's important here in a moment.
Amazon SageMaker
Amazon SageMaker, on the other hand, is a fully managed machine learning service. There are a large and growing number of services available through SageMaker. In fact, at AWS reInvent just last week, they announced some new functionality and some new features that are being made available on the platform. So it's continuing to grow, continuing to evolve. It's one of the fastest growing kind of AWS products that Amazon offers.
And for good reason, it's highly scalable. It provides access to a lot of native machine learning algorithms. You have an integrated machine learning environment for doing development and testing and model deployment and things like that. And then it gives you a really nice production ready way to deploy machine learning models, track those models, monitor them, kind of everything within the scope of model development and machine learning operations is available through the SageMaker platform.
Combining RStudio and SageMaker
With this said, it might be kind of easy to look at these two different products and these two different platforms and to kind of pit them against one another, right? SageMaker provides a machine learning kind of development environment that's built on top of JupyterLab. They provide lots of really nice functionality. And RStudio, on the other hand, provides a development environment heavily focused on the R user.
Thankfully, instead of putting these two things against one another, instead what's happened is we've combined the two, right? We've said, look, what if we have RStudio as an available editor, as an available tool through the...
And that's been driven in large part by... I'm just gonna mute someone real quick.
And this effort has largely been driven by the R community. As our customer base has grown, both professionally as well as just the open source users who use RStudio products every day, there's been a growing interest in having some sort of solution offered through the SageMaker platform. And for good reason, right? SageMaker provides all these functionalities around machine learning and tooling that R users are likely very attracted to. But the RStudio IDE is the place where R users feel most at home. And so we've worked closely with the SageMaker team and we're happy to announce that RStudio is an editor and an environment that is now natively available through Amazon SageMaker. And we'll take a look at what that looks like in just a moment.
But the RStudio IDE is the place where R users feel most at home.
And we're really excited about this, right? We think this is an awesome opportunity, not only for us, but for R users kind of everywhere within organizations throughout the globe to use a tool in an environment that they're comfortable and familiar with with the enhancements provided by the SageMaker platform.
So a little bit of a summary of what this is, right? It's a managed RStudio solution, which means that running RStudio Workbench on SageMaker means that as an organization or as an individual, you do not need to set up, install, maintain RStudio yourself. Instead, that's handled on the SageMaker side. It's simply something that you choose to opt into when you set up your SageMaker domain. It uses, if you have an existing RStudio Workbench license, you can use that license and you can carry that over into SageMaker.
It gives you access to scalable Amazon resources, easy access to additional SageMaker features and capabilities like some of the machine learning abilities and model deployment and management and other things that are part of what SageMaker offers to users. And you have flexible compute resources for the different workloads that you might be involved in and engaged in. And we'll take a look at some of these things in an example here in a moment.
So here's a just kind of quick little video, and we'll actually look at this in real time in just a moment, but just to give you an idea of what this looks like in SageMaker on AWS, you go and open up the launch app dropdown, click on RStudio if it's been configured through your domain, open up, you'll have the RStudio Workbench landing page. And from there, you can start a new RStudio session. It's really, you know, like as simple as that is, the powerful thing is that it's that easy to get in, to get working inside of RStudio. Again, fully managed, hosted, maintained by SageMaker.
And then just kind of a word that I think helps highlight the significance of this for us, but also hopefully the significance of this for the R community in general. This is a quote from Tarif, the president of RStudio. And he said, RStudio is excited to collaborate with the Amazon SageMaker team on this release, as they make it easier for organizations to move their open source data science workloads to the cloud. We are committed to helping our joint customers use our commercial offerings to bring their production workloads to Amazon SageMaker and to further collaborations with the Amazon SageMaker team.
And I'll kind of touch on that last component here, which for me is kind of a personally exciting aspect of this whole thing. And that is that we're not done, right? We're excited about what we've started here. We're excited about what's available today, but we're also excited as we look towards the future and what we anticipate being made available in the near future. And we'll discuss some of what that will look like here towards the end of our conversation today.
Live demo
So with all this said and done, let's go ahead and jump in and let's look at a demo. Let's investigate what we can do, what's available to us in this integration. So I'm going to go ahead and switch over here. Let me see if I can move zoom controls out of the way. So I'm going to open up, here's my SageMaker domain on AWS. I can see my user here inside of SageMaker. And then over here, I can go to launch app and I'll see that I have three different options here. Studio, which is the native SageMaker interface, RStudio, which is what we've been talking about here today. And then Canvas is the new tool that was just announced last week that brings some kind of no-code functionality into SageMaker.
If we start with the traditional experience, just to give you an idea, if you've never been exposed to SageMaker before, and we open up SageMaker Studio, this is the kind of traditional interface through which developers will interact with SageMaker. Like I mentioned previously, it's built and heavily influenced by JupyterLab, but it's also heavily modified to provide lots of integration with the SageMaker platform and the tooling that that platform provides.
So here we can see, I have different tiles that I can scroll through. I have different projects that I can start. I have different kind of work streams that I can work on or different styles of projects that I can work on from within this environment. Now, this has been an environment that's been offered by SageMaker for quite a while. And our users may have experienced this environment themselves. There's been support for R, the language, inside of SageMaker for a while. And typically that interaction happens through Jupyter Notebooks.
Now, if we come back to our SageMaker landing page and we go ahead and click on RStudio, let's open this in a new tab here. Now we have, and we get dropped directly into this environment that if you've used RStudio Workbench before is likely familiar to you. Here we have our landing page where we can select sessions that we wanna work on. If we have currently running sessions, we can create new sessions if we want to. We can view projects that we've previously opened over here on the right-hand side. And we have some additional control over suspending or quitting the sessions that are running.
We're gonna be looking at this currently running session, this SageMaker webinar here in just a moment. But before we jump in there and look at some of the content there, I wanna go through the new session process just to kind of showcase what's available here. We'll go ahead and open up new session. Here we can give this session a name, example, RStudio SageMaker session. That's too many characters. We'll just say example, RStudio SageMaker. There we go. And then here we can select the editor. The only option available is RStudio.
So that's one thing to be aware of. If you are familiar with RStudio Workbench, you may be aware that it provides access to multiple editors beyond just RStudio. Those editors include Jupyter Notebooks, JupyterLab, VS Code. With the SageMaker and RStudio integration, the only editor available through RStudio is the RStudio editor, the RStudio development environment.
The other option that we have here is Cluster. Again, the only option available to us is SageMaker. And this is just kind of an interesting note, a little bit of a side note, but I think it's worth noting. And that is the fact that Amazon is one of the first groups that's taken the launcher, which is a component of RStudio Workbench that allows it to integrate with other execution engines like Kubernetes. But Amazon's one of the first groups that's taken that and created a custom backend for it. And that custom backend is this SageMaker backend. That's only available through the SageMaker integration.
But once I've selected SageMaker as my cluster, I can then define, we'll first talk about this image. I can define the Docker image. I want this particular session to be run on. As it stands currently, there's only one default image available, but that's something that will change in the near future. And then the instance type here is where I will select the EC2 instance or the Amazon compute instance that I want this particular session to run on. And there's a whole host of options. And this is one of the great kind of benefits of this architecture.
Because one, I don't have to, again, like I mentioned previously, as an organization, I don't have to manage and maintain this, right? This is something that's set up as part of my SageMaker domain. SageMaker is the owner, the maintainer of the RStudio Workbench environment. But automatically out of the box, if I go this route, I have a very flexible kind of compute engine that I can lean on. Because I can decide when I start a new session, what type of resources I might need. Do I need heavy compute? Do I have a very memory intensive process? Am I gonna be doing some really heavy model training with very big data? And I can make an intelligent selection at this point about what type of EC2 instance I want this particular session to run on so that I have the appropriate resources available to me as I run this session.
The other thing that's worth noting here is that as multiple users are engaged with RStudio through SageMaker, they're working kind of independently in their own environments. So that if one user does something in their environment, for example, reads data in that consumes all available memory or consumes all available CPU, they don't impact or negatively impact the other users because they're all kind of in their independent environments.
I'm gonna go ahead and select the default image here, start the session. We'll see a new session starting up right here. Now, because we're provisioning a separate new environment when we come in and start a session inside of SageMaker in the way that we've just done, it can sometimes take a long time to start this initial session because it takes some time to provision the environment, make the Docker image available, get that image running in a container, get everything up and running so that we have access to our RStudio session. But once that initial startup is complete, that session is available and subsequent sessions will start much more quickly. And here we see this session didn't take too long to take it up and running.
Let's go ahead and come in here and just see what we have available. And again, if you've used, let me zoom in a little bit here. I can, there we go. If you've used RStudio previously, whether at the desktop level, open source on the server, RStudio Workbench, in any case, this environment likely feels very familiar to you. I've got packages that I can scroll through down here. I can navigate my file system here. I can look at help for different functions. I can navigate and explore my environment. I've got the console here where I can execute R commands. I have this document pulled open where I can, I've got my editor where I can open up R scripts, R Markdown documents, anything that I want to work with in this context.
A couple of things just kind of technically speaking that are worth noting is one, Amazon automatically, so SageMaker automatically mounts a home directory into every session. So you'll see down here in the bottom right-hand corner when I look at files, I have a home directory available to me inside this home direct, this home directory is persistent. So this is nice because this means
that if I am working on a project and I, let's say that I start a project in SageMaker and I realized part of the way through that I've under provisioned my environment, I didn't give myself enough resources.
And if I want to be able to conclude my analysis, I need to do it in a more heavily provisioned environment. Well, I can terminate my existing session. I can save my changes, first of all, terminate my existing session, start a new session with a new, bigger environment based on what I've learned from the previous session. And then once that environment starts up, I'll have access back to the same files I was working on previously within my home directory. So these files follow you around.
This also means by extension that if I install an R package, right? If I'm in here and I say install packages, let's do, yeah, let's install the line package. Then this package will install into my home directory as a user package. And then it will be available to me persistently from that point forward. So I don't need to reinstall packages every time I start a new session in SageMaker. Those packages are persistent and follow me into whatever session I happen to be running on.
And we can see those packages installed. Here, we can see the user library that are packages I've installed to my own home directory. And then below that, we can see the system packages, the SageMaker instance. So that default instance that we selected contains a large number of kind of commonly used data science packages. So you'll see in here, we have, let's scroll down a little bit.
We have the tidyverse in here. We have data table in here. We have a number of kind of common data manipulation and data modeling packages that are made available here inside of the SageMaker image by default.
RStudio functionality on SageMaker
Okay, so while this is continuing to run down here, let's go ahead and look at a couple of other things that we can do, right? So we're in RStudio and for our users, this is an environment that we're likely comfortable in. So I can, if I want to, from in here, I can start a new Shiny application if I wanted to. I mean, this might take a minute while this package install wraps up.
In fact, let's come back here. We're gonna open RStudio back up and drop into our, if we can, maybe we've frozen everything up.
Okay, once this pulls up, we're gonna drop into our webinar environment that we have set up already, the running session that we currently have for the RStudio SageMaker webinar. Let's see if we can get this to unfreeze, maybe.
Of course, live demos are always exciting and things never go as planned. Okay, maybe it'll come up for us.
If not, we'll switch to another environment and try it in there. This is my fault for waiting off script, that's what I get.
There we go, okay. All right, so let's come in. We'll leave that one running, but let's come into this environment, this session that we have running. Again, one of the advantages is that other session's kind of tied up, but we can drop into this session and go from here.
So again, I'm in my RStudio environment. Let's just examine a couple of things that we can do just to verify that things kind of work and behave the way that we would expect them to. So if I start, if I create a new file, I can create a new Shiny application. We'll call this Shiny example. Go ahead and create that. I can run this here within SageMaker. I'll see, in fact, let's run it in the viewer pane here.
So I can run this here. I can see the behavior that I would expect, which is I have my rendered Shiny application running over here. I can do what I would expect to do, which is interact with that application. If I wanted to, I could then publish this application to a place like RStudio Connect or Shiny Apps IO. Obviously this application isn't of any real consequence or significance, but this is evidence that if I wanted to, and this is likely the case, I can use SageMaker to do things like fully develop my internal Shiny application that I might then share on our internal RStudio Connect platform or some other mechanism.
So Shiny works as I would expect it to. Tools like Plumber also work. If we come in here and say, let's start a new Plumber API, we'll call this example Plumber. We can see my Plumber file running here. I can run this. In fact, let's do that in the viewer pane again. Here we go.
So I can run this API in here. And again, I have the behavior that I would expect, right? And the nice thing about this, and the reason that I'm going through kind of these simple examples is to highlight that once you're into this environment, it works as you would expect. I'm able to install R packages. I'm able to write R code. I'm able to interact with R documents in the way that I would expect, whether those are source code files, like a Shiny application or just a script file that I'm working on, or something like a R Markdown document or like Plumber API or any number of other things.
What R users gain from SageMaker
So now that we've kind of verified some of this basic functionality, I think the natural next question, and this was kind of my next question once I started getting into this and becoming more familiar with SageMaker, and that was, okay, I understand the significance and the advantage from the administrative standpoint. I don't need to maintain infrastructure. I have a flexible environment. I've got scalable compute resources. I have a lot of convenience on the administrative side when I allow SageMaker to manage the environment for me.
But as an R user, what do I get? Do I just get RStudio? It's just running somewhere else? Because in most cases, I don't, as the R user, I don't necessarily care about where RStudio is running. I just want to make sure that I have access to it. But the question in my mind was, is there something that I can now do that was difficult to do before? And the answer to that is yes. There's a lot of functionality within SageMaker that becomes very easy and kind of natural to work with once you're inside of this environment.
And the answer to that is yes. There's a lot of functionality within SageMaker that becomes very easy and kind of natural to work with once you're inside of this environment.
And so we're going to pull open an example document here. I'm not going to spend a ton of time. And just another note, all of the kind of code and everything that we look at here is available on GitHub. And I'll share a link at the end of the presentation that will take you to the GitHub repository. The slides will be there. Any source code or examples or anything that we look at will be there as well. So don't feel like you need to frantically try to copy and paste and follow along. Everything's available and will be shared after the fact.
So I'm going to open up, this is an R Markdown notebook here. And let me just, yeah, okay. So we're not going to walk through this entire thing. It's a fairly lengthy document. And I'll be honest, this is pulled from an example, Jupyter notebook that Amazon has provided. So there's a GitHub repository that Amazon has that contains a whole host of SageMaker resources, examples, getting started guides, all kinds of resources to become familiar with some of the SageMaker features. So this particular example here is pulled directly from a Jupyter notebook that they provide that walks through how to interact with SageMaker via R.
And so I want to highlight some of the patterns. And again, I'm not going to walk in depth through everything that's here, but I'm just going to highlight some of the patterns and functionality that's available and how we make use of it from within this RStudio environment that happens to be running on SageMaker.
Using the SageMaker Python SDK via reticulate
Now, the first thing that we're going to do, let me just, so we can start clean, I'm going to restart my session here. Okay. Now, I mentioned this previously as one of the strengths of the RStudio development environment. And that was the fact that it works really well as kind of an, not a front end, but it provides some tooling around Python interoperability, right? If I'm working with Python and R concurrently within the same document, I have some functionality that can help me out with that. And that becomes beneficial because one of the easiest ways to work with some of the SageMaker tooling is through the SageMaker Python SDK.
Now, I'm not, I don't spend a lot of time in Python. I'm much more comfortable in R, but fortunately the reticulate package, which allows me to bounce back and forth between R and Python, could be used to allow me access to this Python SDK from my R session. And so that's what we're going to do here at first. We're going to load in the reticulate package. We're going to bring in the tidyverse as well so that we can use the tidyverse for some things later on. And then I'm going to bring in this SageMaker package that's available in Python. So here, this import function comes from reticulate. This is loading that SageMaker SDK into my R session as this SageMaker object. I'm going to go ahead and run this.
This will load up. I have already set up my Python environment. The default image for RStudio on SageMaker has reticulate already available at the system library. So everything should be set up and configured so that you can just kind of hit the ground running. And if we open up my environment here, we can see I've got this SageMaker object that's actually the SageMaker module from Python. So this SageMaker object in my R session now gives me access to all the tooling that's available in that SageMaker Python module.
Now we're going to create a couple of different resources that we can use as we go through this process of training and tuning this model. So we're going to create this session object and this bucket that identifies an Amazon S3 bucket that we're going to use to store artifacts, data and objects that we create throughout the course of this document.
And then one of the really, I think, convenient features of running RStudio directly inside of SageMaker is the fact that I don't have to, I'm already permissioned, right? Like the role that I have when I open up and start running SageMaker is the role that I assume whenever I execute any of these SageMaker commands. So I don't need to reauthenticate myself to Amazon. That permission is already scoped and attached to me as I start running here. So I can grab that role right here by running this get execution role function.
And notice as I'm interacting here, right? I'm using this SageMaker module that we see here. And this SageMaker module is a Python module that I've loaded into my R session. And so I access the methods and different objects attached to that module with this dollar sign, just as if I was manipulating a list or other object here inside of R. So here I'm running these different functions or these different methods off of SageMaker to get this functionality.
Preparing the dataset and uploading to S3
Okay, so what we're gonna do is, and again, a lot of this comes directly from this Jupyter Notebook, but we're gonna pull down this Avalone dataset that comes from the UCI Machine Learning Repository. And we're gonna do a little bit of manipulation on that dataset. Not anything super crazy, we're gonna download it. We'll notice that if we scroll over, the sex column here is a character column, but it really should be factors because we only have three different levels here. So we'll go ahead and change that to be a factor.
We can look at a summary of what this dataset now looks like. And we see that in height, we have some that have zero height. And we wanna take a look at what those are. So we can go ahead and use ggplot to investigate those. We see a couple of outliers here. And then we have some infants over here and we've added some jitter to this just so that we can gain more visibility into the data. But we can see that we have a couple of observations over here that are infants that have zero height reported.
So we're gonna go ahead and remove any observations where the height value is zero. And now we're gonna go through and we're going to prepare this dataset for training. So we're gonna come in here and we're going to create these kind of one hot encoding columns for the sex column and then remove the sex column itself here.
The other thing that we're gonna do is we're gonna move rings, which is the target of our machine learning model that we're going to build. We're gonna move that into the first column of our dataset. SageMaker expects the first column to be the target value when you define models. And so in order to comply with that, we're gonna move rings over here to the front.
Okay, now we're gonna split up our data so that we can get training on this. We're gonna go ahead and sample 70% of our data for training and then the remaining 30% we're gonna split in half and have half for testing and half for validation. And we're doing that here. And again, I'm not gonna step through everything. The other thing to highlight, a couple of things to highlight as we kind of round this example out is, one, like this is not intended to be an example of totally great and perfect machine learning practices. Rather, the intention here is to kind of highlight how to use some of the SageMaker features and functionality from within RStudio. And then the other thing to note is that I am by no means a SageMaker expert. So somebody like I becoming more and more familiar as we go. And thankfully, we have some folks from Amazon on the line today as we get questions towards the end that might be able to help and provide some guidance there. But just worth noting that I'm by no means consider myself a SageMaker expert.
Okay, so we're gonna go ahead and trim down our data set to be only 500 rows. And the reason for this is because we wanna do some stuff towards the end where we're going to submit predictions to the, or we're going to submit data for prediction to an endpoint that we deploy. And we have to have, the maximum payload we can submit is 500 rows. So we're gonna go ahead and trim down our test set to be 500 rows here.
And then we're gonna write this data out as CSV files to our local directory. Now, the reason we write this data out as CSV files is so that we can upload it to S3. And that's what we're gonna do here. We're gonna create these different files in S3 that represent our training validation and test data.
Okay. And then we're going to define these input types so that when we train our model, SageMaker knows what data it's dealing with. So we're gonna create these train input and validation input types that just identify where the data is living and what type of data it is.
Training an XGBoost model
Okay. Now we're going to go ahead and start getting ready to train our XGBoost model. So SageMaker has ready-made containers for training certain types of models. XGBoosting is one of those model types. So here we can go ahead and retrieve this model or this container definition. And if we look at this, and again, this is all using that SageMaker SDK that we've loaded into our R session.
Here we can see, here's where the container is living, and we can reference that as we go through our training process.
Now we're gonna define our estimator. Again, I'm not gonna go through everything that's available here. All this content will be available, but we're gonna go ahead and define the estimator that we wanna use by providing it with the container that we wanna train with, the instance type that we wanna do our training on, and where the output should go from that model and things of that nature.
Now, once we've defined what our estimator is, we can go through and define hyperparameters that we wanna explore and how we plan on tuning those hyperparameters. Again, I'm not gonna walk through everything that's involved here, but the idea is, again, I'm making use of this SageMaker module that's available to me in my R session through this SageMaker object.
We're also identifying our validation metric here.
Now, once this is all said and done, we can build the tuner that we're going to use to tune our model. We can give this job a name, define our input data. So here's the path in S3 where that input data is stored. Here's the path in S3 where the validation of data is stored. And then finally, we can use this fit method of this tuner object that we created to actually fit this tuner, which will go through and explore this hyperparameter space that we've defined and identify the best fitting model.
Now, this job has now kicked off. And the thing that's significant to understand is we've defined this training job entirely to be run and managed by SageMaker, right? So again, we're using R, we're using RStudio, but we've used these tools to orchestrate this training job that is now being executed by SageMaker itself. And if we scroll back up just a little bit to see where we define our estimator, we can see that we've defined an instance type that we're gonna run this training job on. And we've defined some other attributes so that SageMaker knows when we fit this tuner and when we train this model, it goes out and provisions the necessary resources, grabs the appropriate container that has all the available and necessary dependencies to run this, to train this XGB model, and then runs through that training job in a totally separate environment.
That's why when we ran this, if we come back down to where we're fitting our tuner here, scroll down, there we go. If we, when we look at how we ran this, we can see that our R session isn't tied up, right? We can still, I can still do things here in the console. Oops. I have a, I still have a listening R session because my R session isn't being used to do the model training. It's SageMaker managed resources that are handling the model training at this point.
Now I can query that process to see how far along it is using Boto3, which is another Python SDK for Amazon services. So again, we'll follow the same pattern that we use with SageMaker. We'll load in this Boto3 module as an R object, and then we can query our SageMaker tuning job by running a few commands from this Boto3 library. So here we can see, I have four in-progress models. The job status is currently in progress. No models have yet succeeded, and no models have yet failed.
And if I look back up here just a little bit, I can see that I set this max parallel jobs parameter when I set up my tuner to be four. So that's why we see four parallel training jobs taking place, and I have a maximum jobs set to be 10. So once I've gone through 10 different iterations here, this particular tuning will be complete, and we'll be able to extract what the best model was from that process.
Go ahead and run this one more time and see if we've completed any yet. We see that we still have four in-progress models. So I'll let that continue running and just kind of talk through what the rest of this would look like.
Reviewing model results and deployment options
Once we've run this model, we can then grab what the best training job was out of the status of the tuning job that we've run. We can investigate what the metrics are of that model, and we can also figure out where that model's being stored inside of S3. So we have lots of functionality around how we manipulate the models that get created from our tuning jobs.
And then at this point, we have two different options. Typically the point of building a model isn't just to build the model itself, but to then do something with it, to leverage that model in some way, to run new data through the model and generate predictions on that new data. And SageMaker provides kind of two frameworks for doing that. One is batch transformations, which is, I'm not necessarily looking for real-time inference, but rather I'm looking for a way to run a batch of new data through my model all at one time. And that's something that's supported through the SageMaker SDK.
This walks through an example of setting up, and I'm not gonna walk through it right now, but this walks through an example of how to set up that batch transformation and run a set of new test data through the model, collect those results, and then compare them to the original observations. So that's one option.
The other option here is, let me scroll down a little bit. Okay, the other option, which is the one that I'll focus on here for a moment, is deploying the model. SageMaker provides native tooling for being able to take a model that's been trained in SageMaker and deploy it directly into SageMaker itself as an endpoint. And then from that endpoint, you can now generate real-time predictions by submitting either HTTP requests to the endpoint through other tools, like you might create a Shiny application that queries that endpoint and generates real-time requests based on user input. You might have a front-end mobile application that's built within your organization that queries this model through this deployed endpoint that you create.
Like I mentioned, SageMaker has native support for deploying these endpoints for certain types of models. This XGB model that we've trained here is one such example of those. And so here we can see, we use this deploy method on our tuner object to deploy this model into this environment. And then once that model has been deployed, we can define a serializer for it, and we can use this predict method on the model itself to submit requests to that endpoint, generate predictions, and bring those predictions back into our existing R session.
Now, let me come back up and just see if our tuning job has made any progress here. And we can take a look at where we're at. Okay, so we have four succeeded models. We have four models that are currently in progress being trained. I'm not going to wait for that to conclude, but we see that we're making progress here, and we can continue to query that progress using this Boto3 library that we've brought into our R session.
Exploring the SageMaker studio interface
Now, I'm going to come back into, let me see if I can get back into it here. Okay, so here I'm in SageMaker. This is the SageMaker studio, so the JupyterLab interface. And the one other thing that I wanted to highlight is if I come down here, I can see this. I have the SageMaker resources view that's available to me here, and I can come in and I can look at this endpoint section, and I can see these are previously deployed endpoints that I have published in preparation for our discussion today.
So here I can see, these are both models trained on the same data, just on separate days, but I can come in here and click on one of these, and I can open up an entire view into what that model looks like. And here I can submit test requests to the model. I can view how this model is set up, what the endpoint for the model is, information about the runtime of the model. If I had specified that I wanted to enable model tracking, I could view things like quality, explainability, bias. These types of metrics are supported in SageMaker as long as I configure my deployment to allow for tracking and metric collection, which I haven't done in this case, but it is something that's available if that's something that's of interest.
The value of RStudio on SageMaker
Now, to back up a little bit, right? If we come back here for a second, what's the big deal? What's the excitement about this? Well, there's kind of two things. One is maybe the, depending on your perspective, might be the less exciting of the two things here, but that is the fact that you can, as an RStudio customer, you can bring existing RStudio Workbench licenses into SageMaker and use RStudio Workbench within your SageMaker environment. Now you have an entirely managed hosted solution of RStudio Workbench that you don't need to worry about maintaining, installing, updating, or anything like that, but it remains flexible and gives you lots of resources at your disposal for doing your day-to-day analysis inside of a native RStudio environment.
The other thing that we've just looked at is once you're in that environment as an R user, you gain access to a whole collection of SageMaker tools from model training and tuning to deployment, monitoring, all those things are now available to you directly from within your SageMaker environment. Now, today, that access is managed through reticulate, like we walked through in the example just now. So using the reticulate package, we can bring in the SageMaker SDK, and then we can use that to interact with the SageMaker environment, from model training and tuning to deployment and any other things that we might want to interact with.
you gain access to a whole collection of SageMaker tools from model training and tuning to deployment, monitoring, all those things are now available to you directly from within your SageMaker environment.
What's coming next
Now, kind of as we look towards the future and what's coming up in this space, one of the kind of immediate term things to be addressed is that there will soon be the ability to bring custom images for RStudio Workbench in Amazon SageMaker. So if we come back here, just to remind us of what that looks like, if we come back into our home screen here, when we start a new session, currently there's only one image available to select from, but that will change in the near future, and there will be the ability to bring additional custom images into RStudio Workbench. You could define your own images within your organization. There may be predefined other images that are available that could contain different libraries, different versions of R that would support the use case that you're after.
The other thing that we're really excited about and actually working on bringing to the table is RStudio Connect managed by SageMaker in the same way that we see RStudio Workbench managed by SageMaker today. Now, it is possible today to use RStudio Connect and install it and manage within your own environment in connection with RStudio Workbench installed and managed by SageMaker. And what that process would look like is you would develop and do your work inside of RStudio Workbench in the SageMaker environment. And then when it came time to publish what you were working on, you would just publish that to Connect. And Connect might, in this case, Connect would be something that you've installed and managed somewhere else. But down the road, we anticipate bringing RStudio Connect to SageMaker as well in much in the same way that we have RStudio Workbench integrated there today.
When you set up the RStudio integration on SageMaker, one of the things that you have the ability to do is to predefine your both RStudio Connect URL if you already have an RStudio Connect environment and you want to automatically configure that for publishing from Workbench. You can do that when you set up Workbench on SageMaker. And then the other thing is you can automatically define or you can set up and define an RStudio Package Manager URL for users to use when you go through the setup process.
Resources and closing remarks
Finally, a few resources. We put out a blog post about this, announcing this integration a few weeks ago. There's a link to that here. AWS has put out a number of different blog posts. There are two of them are linked from here. This news blog is kind of a general blog about, let me just open this up, kind of a general blog about what the offering is and what's available today. And then this getting started post here is kind of a more technical post that walks through from the administrative side. What do you need to do to set up RStudio on Amazon SageMaker? How does it work? What do you need to do? How do you get the license into the right place? And what do you do on your SageMaker domain to configure this to work?
And then finally, there's this GitHub link here. Let me open this up. So this GitHub repository contains the slides from today, as well as the example code that we walked through. Like I mentioned, that example code pulls from this repository here. That's a whole collection of R examples provided by the SageMaker team. These are all in the form of Jupyter notebooks, but they can easily be kind of repurposed or re-imagined into standard R scripts or R markdown documents, whatever the case is, now that RStudio itself is available within the SageMaker environment.
And James, would you be able to copy that GitHub link into the chat as well? Yeah, I can. I'm anticipating that question. Let me grab that. It's a great idea.
Perfect. All right. There we go. Okay, so there's the link to this GitHub repository in the chat. So you can see the links to the additional resources under the slides. If you open up the slides directory in here, it contains a PDF output of all the slides. And that resources page has the resources links that we just discussed.
Finally, as much as I'd like to take credit for the fun theme of these slides, I pulled these from a website that made these freely available, and I'm grateful for that. And some of the comic book graphics and things like that were also provided by Freepic.
And as a final note, thank you everyone for your time today. I know there's probably lots of questions, and so we'll take some time here at the end to address as many of those as we can or give the folks from Amazon a chance to address those if there's some better suited for them. But I just want to say, I really appreciate the time. We at RStudio are very excited about this. And I just want to reiterate what Tarif had mentioned in his quote, and that is that we're committed to continuing to build out this integration. We were really excited about the momentum we've seen. We're really excited about the early adoption that we've seen. And personally, just from my perspective, I'm really excited about the capabilities that this introduces into the R ecosystem. And I'm excited to see what things people are now able to do with the solution that perhaps previously were unavailable or more difficult to do now that we have this SageMaker integration directly available. So with that, I'll see what questions we have. I think there's folks that have been watching the Slido links. So Rachel, I don't know if you want to kind of- Happy to help with that. And thank you so much, James. That was awesome. And those slides are beautiful.
So we do also have some people on from the Amazon SageMaker team as well, who you may have seen were helping answer questions in Slido too. So I just want to take a second to have them introduce themselves as well. Michael and Georgios, if you want to jump on for a second.
Hi, my name is Michael Xie. I'm an AIML specialist solution architect from AWS. Thanks for having me for today's session. Really looking forward to having conversations on RStudio on SageMaker. Thank you.
Hello from me as well. My name is Georgios Xinas. I'm a machine learning specialist solutions architect as well as Michael, I'm based in London and I'm really happy to be here today.
and hopefully can answer questions that the community has.
Awesome, thank you. And I'll start by going through the Slido questions and the ones that were the most upvoted, but we want to make sure to answer everything as well. So I've talked with Lou on our team about writing a blog post that goes through all the Q&A as well.
But just to address this one, James, the most upvoted question was, do you need a paid RStudio Workbench license in order to use RStudio in SageMaker?
Yes, the way that we've shown this integration today, it only works with a paid RStudio Workbench license.
And that can be just to elaborate on that a little bit further, that can be either standard, which is a license for one server, one activation or enterprise, which gives you unlimited server activations. Both of those models will work with SageMaker. If you do standard, then SageMaker becomes your one installation of RStudio. If you have enterprise, you could be running RStudio in SageMaker as well as have your own on-prem solution. You can, you have lots of flexibility at that point. But the answer to that question is yes, it does require a license for RStudio Workbench.
ML solutions and R in SageMaker
Thank you. And I see Eduardo, you asked a question that a lot of people have upvoted as well. And I'd love to hear from the community too, if you want to read that question, Eduardo, if you're still on.
And I can, I'll, I can read it now. And if you want to add any more context, please feel free to jump in.
But the question was, how does SageMaker help ML solutions designed with R into production? Is there a specific ML package that SageMaker can deal with? For example, tidy models or caret?
Yeah, I can speak to that with, like I said, I'm not a SageMaker expert. So I'm happy to be corrected by the folks on the call. I'm happy to be corrected by the folks on the Amazon side as well. But from my understanding today, right?
Most of the functionality when you interact directly with SageMaker is going to come through that SageMaker Python SDK. So like we use reticulate, we brought that module in and then we use methods and functions from that module to manipulate and train a model and deploy the model and all those types of things. Now, one of the kind of underlying components of that is the fact that all that whole process, that model training, tuning, deployment process is all actually happening in Python, right? The container that we ran was running XGBoost and interacting with that via Python. We were managing it from the R side with reticulate, but most of the work was being done on the Python side.
Now, there is support in SageMaker for being able to define kind of your own custom containers and images for model training and deployment where you could define ways to interact with R processes. But to my understanding today, there's not a lot of native R tooling there yet. Now, that's something I'd love to see change and something that I'm hopeful will change over time as this partnership continues to grow and expand. I've had discussions with folks about some changes I'd like to see, for example, and this isn't an indication that this will happen, but my own personal just utopian future would be that there is an R native SDK for SageMaker that allows R users to natively interact with SageMaker resources, as well as support for things like tidy models and SageMaker. Now, there's a lot of work to be done to get there. And again, this isn't a promise that that will ever come to fruition, but it's something that I'd like to work towards and would love to see happen.
but my own personal just utopian future would be that there is an R native SDK for SageMaker that allows R users to natively interact with SageMaker resources, as well as support for things like tidy models and SageMaker.
And today- This is Michael. So I'd like to add on what James has provided. In SageMaker, you can definitely bring in your R containers. So you can package your tidy models, correct into a container and start a training and also hosting your models built natively within R into SageMaker. And then, you know, and doing all the ML Ops CLCD along with SageMaker using the SageMaker SDK within your R environment. So we do have a couple of resources and artifacts showing how to do so. So happy to share those information.
Shiny app development and hosting
Awesome. Thank you, Michael. And James, I know you addressed this question a bit towards the end, but I think it'd be good to address as well. But Sheikha asks, is it a good solution for host- Is this a good solution for hosting and developing Shiny applications?
Yeah. So for developing, absolutely, right? It gives you a valid environment where you can develop these Shiny applications. And the nice thing is you can develop these applications in a way that natively reaches out to and interacts with your AWS resources. So it becomes really easy because you're already operating inside of AWS to read data in from S3 and to interact with other AWS resources without needing to worry about like credential management.
Now that's on the development side. On the like publication and hosting side, this story is a little bit different today because currently RStudio Connect, which would be kind of the preferred method of deploying and hosting Shiny applications, isn't something that's offered through SageMaker. That's the next step for us is making that available. And it's something that's under current conversation to have done. And so we're hopeful that that will be available shortly. But in the meantime, what that means is you would develop inside of RStudio Workbench on SageMaker and then you would publish or deploy that application to some other location, whether that's RStudio Connect that you have separately installed and managed somewhere else, or Shiny Apps IO or some other solution.
The challenge with that is the fact that once you kind of cross that boundary and you're no longer operating inside of that kind of SageMaker domain, now you have to start thinking about like, how do I, you know, if I'm interacting with other AWS services, for example, like S3, now I need to make sure that I have my credentials under control and I know what I'm doing in terms of like authenticating to the service.
When RStudio Connect becomes available through SageMaker, I imagine that that story will become a little bit more clear because you'll be able to publish directly from Workbench on SageMaker to Connect on SageMaker and you'll still have that same kind of nice native authentication that's already taken place.
Tidy models and SageMaker advantages
Rayon, I see you asked a question around advantages of using tidy models within SageMaker. Would you want to jump on and add any context to that question too?
Hi, can you hear me? Yes, I can. Yeah, thank you very much. I think partly this question was answered. Was just asking if tidy models take any advantage of SageMaker and whether it runs in a separate environment. But as James said, at the moment Python is doing the heavy, heavy lifting.
Yeah, that's correct. Again, I would love, this is still early stage for us. We're beyond excited about what we're seeing and what we see as we look towards the future and we'll continue to work towards that future with the SageMaker team. I would love to see SageMaker added as an engine on the tidy model side. Again, whether that happens or not remains to be seen, but I can see ways in which that could happen. But again, you're entirely correct in the fact that today, if you're trying to do use some of the native tooling and technology, what's available is primarily on the Python side. Thankfully, we do have a good entry point in there via Reticulate, but I'm hoping that kind of the R aspect will start to kind of build out over time here as well.
R kernel vs RStudio in SageMaker
Great, thank you. Maisie, I see you asked a great question as well from the Zoom chat. And I think you copied over to Slido too, if you'd want to ask that one live.
Sure. I did again. Oh yeah, so when I, before I saw the RStudio launch in the studio lab in SageMaker, I started kind of building a workflow with the R kernel in the notebook instance. And so I wanted to just know like what would be the difference between, or what would, yeah, what would be the difference between using the R kernel in the notebook instance versus like RStudio in the studio lab?
Yeah, really good question. Like functionality wise, there's not gonna be much of a difference in terms of like what you can or can't do or what types of workflows are, aren't supported. Really what it comes down to, I think is just a preference, right? Like if I'm comfortable using the R kernel in the native kind of Jupyter style environment, then I can do that. And I can interact with my environment that way. What we found, and one of the main motivating factors behind this whole integration has been that many R users have come to SageMaker and said, look, we'd really love to have RStudio because it's home to us, right? We feel comfortable. We know what to do. We have fewer barriers to entry when we're using an RStudio type environment. And so it's really just kind of an environmental preference, right? I myself am much more comfortable in RStudio than I am inside of Jupyter. So any chance I have to work inside of an RStudio environment when using R is something that I'm gonna jump at. So in terms of functionality, I don't think you have really any significant differences. It's just a matter of preference in terms of which environment suits you better.
RStudio Workbench architecture on SageMaker
Thank you. Next question was an anonymous one that was, is RStudio Workbench fully on SageMaker or is it using SageMaker as a launcher backend, which would still require a front-end Workbench server? Oh man, such a good question. I meant to talk to this point because it's a very nuanced question, but it's a good one. So when you set up your SageMaker domain to support RStudio, one of the things that you do is you identify a persistent instance that will host RStudio.
So you're right, there does need to be some persistent environment that runs, that then launches these sessions into SageMaker and allow SageMaker to manage the resources behind those sessions. So there is that persistent environment. I believe the default, and it doesn't need to be very big because there's not any computation happening there. That environment gets automatically provisioned for you when you set up this inside your SageMaker domain and you can decide what instance type you want. I'm trying to remember, I think T3 medium is kind of the default.
And I believe that SageMaker gives that to you for free, like as part of the RStudio offering on SageMaker, that that host environment that's just running constantly to support the RStudio front end is there, but it's still maintained by SageMaker. And I don't believe it's something that's charged for. Yeah, just a quick comment on that, James, you're right, both on the instance type, it's T3 medium and it's also free. Perfect, thank you for confirming.
Environment management and reproducibility
Awesome, there's another question that was, what are the expectations for environment management? Is it managed by AWS, RStudio, me? Will I have access to the same environment two years from now to maintain reproducibility?
Yeah, so I think there's two sides to this question because environment can mean a couple of things. So one is like your local R environment is within your control. So if you want, you can install packages, those will go into your home directory, that home directory is persistent, like we mentioned. So different sessions that start will have the same access to the same files and packages that you were working with previously. And what that means is that there's support for things, there's automatically, because of that fact, there's automatically support for things like RM. So if you wanted to create a very specific collection of packages for a very specific project and have those version to a very specific set of versions, that's totally supported through tools like RM.
In combination with what you're getting out of SageMaker. So your local environment, totally within your control, and certainly you can set it up so that you can come back to that environment two years down the road and reinstantiate it the way that it was and continue working from where you left off. The other side of this is, what about the administrative environment? The server, the settings for RStudio Workbench, things like that. That's something that falls under the SageMaker control, under SageMaker's control, right? So when you say, look, I'm gonna set up and manage RStudio Workbench through SageMaker, part of what you're doing is saying, I'm gonna let SageMaker handle the RStudio administrative tasks for me, which can be a huge benefit because I don't have to worry about that stuff anymore.
And in this particularly, I'm really excited to see how this helps. We work with a lot of organizations that are very Windows centric and all of our software needs to be installed in Linux environments. And that sometimes is a big hurdle to overcome. Now all of a sudden you can say, look, I'm just gonna let SageMaker manage and host it for me. And I don't need to worry about all the Linux stuff behind the scenes. As long as I can work with AWS to get the domain set up right, then I've got an environment I can use. But the other thing that that means is that I'm letting SageMaker handle that for me. So if there's questions or concerns or things that I want adjusted there, or features that I want enabled or whatever, that becomes a conversation to have with SageMaker.
And then it looks like, sorry, just real quick. There was a clarification in the chat about, it says the question was about environments has more to do with system libraries rather than R packages. So the system libraries component typically will come, well, two things. One is you have currently today, when you're in your session running on SageMaker, you have root access to that container. So when you go into the terminal tab of RStudio, you have already assumed the root role. So you can modify that container as you need. So if there's a system dependency that you're in the middle of a project and you're like, oh no, I needed this thing. You should be able to get in, add it to that container at that time and run with it from there.
Now that's not persistent though, right? So if that session terminates and that container goes away and I start a new session, I'm gonna have to reinstall that dependency at that point. I can do it, but it's not persistent. The other side is this custom image functionality that we anticipate coming to SageMaker in the near future, which would allow you to identify at the Docker level as you build out these Docker files, what system dependencies you need available in your environment. And that's how you would manage those persistently.
Awesome, thanks James. And for anyone who asked the question, feel free to jump in to add more context to and unmute yourself as well.
And I will say, let's maybe take one more. I unfortunately am booked back to back. So I've got to jump off for a minute. Sorry about that James, during a bad time of monitoring. I would love to hang around and answer all these questions and part of me really wants to, but it's irresponsible. So let's do one more question then I've got to drop off.
RStudio in SageMaker Studio Lab
Awesome, so one other question is, you put a lot of pressure on me to ask the questions. I'm just going to go from the most upvoted. So it was, this might be more for Amazon, but will RStudio be available in the new Amazon SageMaker Studio lab?
Yeah, so yeah, I think I can take this question. So for now SageMaker Studio lab is only supposed to work with JupyterLab, but if we see that there is interest from the community, we can take that feedback back
and then work with you guys from the RStudio side to see if we can somehow find a good solution that could help the whole community.
Awesome, thank you. James, I know you have to drop to another meeting. To the Amazon team, do you have a few more minutes or do you have to jump as well?
Myself, I also have another meeting to go to.
Yeah, we will try to answer some questions on the chat on the, I guess the Slido will remain open, if I'm not mistaken. Yes, the Slido will remain open. And what we can also do is take all the questions from Slido and answer those in a blog post format as well. So I'll share that with the recording.
Once we have that available. So the recording will go up to the RStudio YouTube before tomorrow, and then we'll work on the Q&A blog post too.
But I also just wanted to give anyone else from the Amazon side a moment to introduce themselves as well. I know a few people from the Amazon sales team were on as well, who may have had to drop, but if anyone's here, feel free to unmute yourself and jump in too.
Well, thank you all so much for joining. There's so many great questions. I really appreciate it. And we'll do our best to make sure that we answer every single one of them.
I'm happy to stick around for just like general questions around resources or meetups or anything that you have. But unfortunately, I know James and the AWS team have to jump. But thank you all so much for joining. Have a great rest of the day.
