Deploy Stable Diffusion On AWS SageMaker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
stable diffusion is one of the most powerful text to image AI models and recently AWS sagemaker released a quick way for you to deploy it on your AWS account which is exactly what we're going to do today [Music] hello everyone this is Marcus speaking a few months ago I showed to you how to set up an account on stability AI website and connect your nest.js code to the model using their API but sometimes you want to have a full control over where the model is being deployed like deploying it on your own AWS account luckily with AWS sagemaker and Foundation models you can pretty easily do that and I'm gonna show to you on the next few minutes how you can accomplish such thing but before we proceed if you like this kind of content just give me a thumbs up share this video with your friends and subscribe to the channel so you can learn more about AWS ecosystem and these AI Integrations and never forget that the more you learn the better you become and more value you can provide so let's do this okay great so here we are on AWS console so the first thing that we need to do is search for sagemaker AWS Sage maker which is this one my case is already here so just click it here as well perfect so here on sagemaker page you can see that on the left side we have this panel and we can see this new Jump Start section and with the foundation models so if you click here you will see some Foundation models that we can easily Deploy on AWS Sage maker you can deploy llama 2 with some of some of its variations like the 7 billion parameters the seven in billion parameters and so on you also have the Falcon 40b which is another text generation model like jgpt but in our case we're going to focus on stable diffusion so we have some versions here in our case we're going to deploy the 2.1 base model from stable diffusion so I can click here to see more information about the model but in order to deploy the model the first thing that we need to do is to create a sagemaker domain so we click here on the left side on the domain section this is the first thing that we need to do so here we click to create a new domain for managing our sagemaker environment okay great so here on sagemaker domain page you can put the domain name that you want for creating your domain I'm gonna call it npcsj Sage maker experiment one can click to use the quick setup if you want to experiment with sagemaker if you want to do something more deep kind of go to the standard setup and configure more options in our case the quick setup is is fine for us and then you click to submit okay great in a few minutes we're gonna have our sagemaker domain for deploying stable diffusion on our account okay great after a few minutes our sagemaker domain is ready if you want to see more information about it just click here but for for re launching our model just click here and click on the first option with Jupiter Studio once you click on the Jupiter Studio option you're going to see something like this and say Amazon sagemaker studio is slowly with Jupiter server for us to deploy the AI models okay great once Amazon sagemaker studio with Jupiter lab is ready we're gonna see a page like this and for deploying our model we should search for sagemaker Jumpstart you click here then you click on models notebooks and solutions and here you can see the same model that we saw previously actually we can see a few more and in our case we're going to look for a stable diffusion so in my case I'm gonna deploy the 2.1 version so we click here and then you click to deploy if you want to change the deployment model name or the machine which is going to host the model you can change the machine here but make it my case I'm going to use a default configuration and then you just click to deploy [Music] okay great after a few minutes our model is deployed on AWS sagemaker the easiest way to test the model is by going here use endpoint from studio and then click here so first we need to set up notebook environment and we click here so AWS is configuring a machine for us to run the code so here we have a basic code provided by AWS for us Tesla Model if you want to try this on your own machine you can copy the code and paste on your own environment to test the model if you have AWS configured on your machine and a set of credentials you can run this code outside of sagemaker 2. so let's wait a little bit for the for the machine and the kernel to be ready for us to make the experiment okay great here with the sample code provided by AWS sagemaker and the kernel is already ready for us so let's try the code so I'm gonna run this and then I'm gonna run this to define a set of functions and here you can see that we also have the endpoint name from sagemaker and then we're gonna run a simple query to the model so the Kiri the function to Kiri to call the Kiri endpoint we're gonna pass this message to sagemaker to create an image from a cottage in impressionist Style and then we display the image with this function just basically the display in the image use the matplotlib which we imported here okay great here you can see this the image generated from our Curie sagemaker also provided to us some more advanced examples and here we can see all the parameters that we can pass to the model The Prompt the width height number of inference steps the garden scale negative prompt number of images per prompt the seed so if you want to do something more advanced and even compress the image AWS Edge maker already provided to us a simple code to do this so if we proceed here for example so in this case The Prompt is going to be astronaut on a horse click here and it's already running the the code for us as you can see here these are the images generated by stable division for us and another case the AWS Sage maker already provided to us is that some cases you can hear the image size limit if the image is too large if you try to generate image with a high resolution you can you can hit a maximum size so you have to compress the image and Sage maker already provided to us a code to handle compressed images which is this one and that's it now you know how to deploy AWS sagemaker on Native blast as a bonus section I copied the code from sagemaker Studio into a simple rest API made using python flask so this is our main file that bootstraps the application and accurate the simple module here so this is our controller that receives the request so here we have a function that receives the same object as we specified on sagemaker so we have the same attributes as this one as this one so we can pass the same attributes to our python code and then the object will arrive here we will parse the Json object into a python glass into this model Define here and here I created some default values for some required parameters and once the object reaches here and then we parse the object we're gonna send this object to the service layer this one here and then the object we will arrive here into this function on the service layer and then we will do the same thing as we did on jupyter Notebook file and then we will we will receive the object sent to sagemaker client and sagemaker client will respond an object to us and then we will save this file locally into the machine and we will gener we will return the path to the image to the controller layer back here into this attribute along the meme type for returning into the HTTP request here so here we receive from the service layer the path to the image and the meme type and then we use the send file method from flask to return the image saved locally into the machine along the meme type that it was returned from the service layer so let's test this so here on Postman I create data simple prompt which is a fish playing piano so I'm gonna call this code running locally oh sorry let me change this to post and then try again okay great so this is the image generated by stable diffusion deployed on AWS sagemaker and that's it now you know how to deploy stable diffusion on AWS Sage maker [Applause] I hope you liked it and I see you in the next time
Info
Channel: Mpcsj Tech Tips
Views: 3,403
Rating: undefined out of 5
Keywords: aws, amazon web services, machine learning, deep learning, gan, sagemaker, stable diffusion, generate image
Id: pyCyKRmJBZY
Channel Id: undefined
Length: 10min 51sec (651 seconds)
Published: Sat Sep 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.