How to use Stable Diffusion on Cloud Run
Key Takeaways
This video demonstrates how to use Stable Diffusion on Cloud Run, an open-source model for generating images from text prompts, by setting up the model with TorchServe and deploying it on Cloud Run with GPU support.
Full Transcript
now that I can use gpus serverless in Cloud run what can I do with it good question you can run different op Source models on it like stable diffusion XL for image generation and let me show you [Music] how welcome to the show Lisa what do you do here at Google Cloud I'm a product manager at Google coud focusing on C run and gke and my years of experience in the C industry have given me a deep understanding of the challenges Enterprises face I am passionate about using this knowledge to drive product development and ensure a simless user experience for our customers seamless user experience I love it uh so what are we building today Lisa we're building a simple AI inference application that generates image it uses the stable diffusion Excel model with torch serf running similarly on carun once deployed the application will allow you to generate images simply by providing a text prompt describing the image you want and here's an example of what it can do but you could also use Google's hosted image and model for image generation uh why are we using stable diffusion Google's imj model is really good good it's hosted by Google and generates photo realistic images it's easy to call from your code so you can get your application to Market quickly if you use that on the other hand if you host your own model or open models on carun you get more control you get more transparency and customization and that's what we're doing today ah I see so you said before that we're going to set up stable diffusion excel in Cloud run uh can viewers try for themselves yeah of course you can follow along in the collab Martin can you please make sure to include the link in the show notes okay we'll do all right the first step is to enable the right apis in your Google call project and I have done that in my project but the collab list all the commands for this got it next I will create a torch serve app torch serve is an open source model serving library that makes my life easier to work with the stable diffusion Excel model and the stable diffusion Excel model will run in the GPU enabled cand service then I will create a requirements file that list all the libraries the application will use I will add a file called config do properties that gives torch serve is configuration now it's time to add the main code of the application I'll create a new file called stable diffusion Handler and paste the code from the cab in there whoa that's a lot of code uh where does the image generation happen here in the inference method and that's where the real action happens this inference method takes a list of input promps and generate images using the loaded models it first used the pipeline to generate a initial image from the pump and then it used the refiner to refine the image and remove the artifacts ah got it next I will create a shell script file that starts the torch serve application I'll will ask cun to call this show script Cloud run runs and scales containers for us in the cloud so I need a Docker file to build that container here at the end of the docker file I'm asking Cloud run to execute the show script that starts the torch serve application ah understood and now it's time to deploy the app yeah that is right it takes some time to download a stable diffusion Excel model from the internet so to speed things up let's run this two commands to set up a Callet and that will increase the bandwidth to huging face website where the model is stored sounds useful uh deployment time yeah it is first I will run gcal builds Summit to build a container and this command will build a container in the cloud on a Google host dat to build server it will take a while so let's take a te break and we're back the build was completed successfully now I will run Gard run deploy to deploy the build container and give it a public https edges and it looks like you're setting up cloudron to use gpus here Lisa yeah GPU equals one means that the service will use one GPU and then GPU type flag specified the service will Ed Nvidia L4 GPU let's run that command it will take a minute to complete looks like the deployment finished it did let's try it out first let's put the service URL in an environment variable next let's set up environment variable for the prompt and I'll ask for a image of a dog running in the park since the dog is my favorite pet and then I will run this Cur command to send a request to my app with the prom and this will take a minute also due to the cloud run service code start and it's done here's the image very nice um could the dog wear a pink shirt and sunglasses sure let's do it I'll send another request to the app with a new prompt and here you are this is the image how do you like it Martin it looks great Lisa uh well thank you for showing us this Lisa yes thanks for having me Martin and thank you everyone for watching if you have any questions for Lisa or me please add them in the comments also please let me know what you thought of this episode I read every single comment I can't wait to see what you build [Music]
Original Description
Codelab → https://goo.gle/41tWN1W
Discover how to use GPUs in Cloud Run for running Stable Diffusion, an open-source model for generating images from text prompts. Join Googlers Martin Omander and Lisa Shen as they demonstrate how to set up Stable Diffusion, package it with TorchServe, and deploy it on Cloud Run for on demand image generation.
Chapters:
0:00 - Intro
0:53 - Building an image generation app
2:10 - Creating a TorchServe app
3:02 - Inference method for image generation
3:55 - Deploying the app
5:08 - Testing the app
5:58 - Conclusion
Watch more Serverless Expeditions → https://goo.gle/ServerlessExpeditions
Subscribe to Google Cloud Tech → https://goo.gle/GoogleCloudTech
#ServerlessExpeditions #GoogleCloud
Speaker: Martin Omander, Lisa Shen
Products Mentioned: Cloud Run, Gemini
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Google Cloud Tech · Google Cloud Tech · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
I’m going for it #GoogleCloudCertified
Google Cloud Tech
I had to get #GoogleCloudCertified
Google Cloud Tech
Be better overall at what you do #GoogleCloudCertified
Google Cloud Tech
Cloud Monitoring on our radar #Analysis #Uptime
Google Cloud Tech
Introduction to Generative AI Studio
Google Cloud Tech
How to use Github Actions with Google's Workload Identity Federation
Google Cloud Tech
Introduction to Responsible AI
Google Cloud Tech
Networking updates and CDMC-certified architecture
Google Cloud Tech
Create and use a Cloud Storage bucket
Google Cloud Tech
How to digitize text from documents
Google Cloud Tech
Faster analytical queries with AlloyDB
Google Cloud Tech
Next ‘23 sessions and FaaS Wave
Google Cloud Tech
Introduction to Assured Open Source Software
Google Cloud Tech
BigQuery Cost Optimization: Storage
Google Cloud Tech
BigQuery Cost Optimization: Compute
Google Cloud Tech
BigQuery Cost Optimization: Select Queries
Google Cloud Tech
Remote Field Equipment Management with Manufacturing Data Engine
Google Cloud Tech
Supercharging your applications with Cloud SQL Enterprise Plus
Google Cloud Tech
Vector Support on our radar #GenAI
Google Cloud Tech
Architecting a blockchain startup with Google Cloud
Google Cloud Tech
Kubernetes and multitasking updates!
Google Cloud Tech
GKE: Using Kubernetes Events
Google Cloud Tech
How to configure firewall rules for Cloud Composer
Google Cloud Tech
Vertex AI Embeddings API + Matching Engine: Grounding LLMs made easy
Google Cloud Tech
Geospatial analytics on our radar #EarthEngine #BigQuery
Google Cloud Tech
Ensuring requests are set in Kubernetes
Google Cloud Tech
Cloud Next 2023, Google research program, and more!
Google Cloud Tech
How to migrate projects between organizations with Resource Manager
Google Cloud Tech
How to run #MySQL in Google Cloud
Google Cloud Tech
#GenerativeAI for enterprises and #Next2023
Google Cloud Tech
How Google Photos scales to store 4 trillion photos and videos
Google Cloud Tech
Google Cross-Cloud Interconnect (Demo 2)
Google Cloud Tech
GKE Cost Optimization Golden Signals: Introduction
Google Cloud Tech
GKE Cost Optimization Golden Signals: Workload Rightsizing
Google Cloud Tech
GKE Load Balancing: Overview
Google Cloud Tech
GKE Load Balancing: Best Practices
Google Cloud Tech
Disaster Recovery in GKE
Google Cloud Tech
How to configure IP masquerade agent in GKE Standard clusters
Google Cloud Tech
Enable and use GKE Control plane logs
Google Cloud Tech
Compliance in Australia with Assured Workloads
Google Cloud Tech
Creating budgets and budget alerts in Google Cloud #FinOps
Google Cloud Tech
Cloud SQL Enterprise Plus on our radar #mySQL
Google Cloud Tech
What's Next for Google Cloud?
Google Cloud Tech
How Loveholidays scaled with Contact Center AI
Google Cloud Tech
What is fleet team management in GKE?
Google Cloud Tech
Troubleshoot VPC Network Peering
Google Cloud Tech
Introduction to DocAI and Contact Center AI
Google Cloud Tech
Cloud Run Direct VPC egress explained
Google Cloud Tech
Database deployment options in GKE
Google Cloud Tech
Analyze cloud billing data with #BigQuery
Google Cloud Tech
Tips to becoming a world-class Prompt Engineer
Google Cloud Tech
Serverless is simple. Do I need CI/CD?
Google Cloud Tech
Accelerating model deployment with MLOps
Google Cloud Tech
How Hawaii's Department of Human Services scaled with CCAI
Google Cloud Tech
Pricing API on our #Radar
Google Cloud Tech
How Recommendations AI for Media can boost customer retention
Google Cloud Tech
Troubleshooting: Node Not Ready Status
Google Cloud Tech
One weekend until Cloud Next 2023!
Google Cloud Tech
#GoogleCloudNext starts tomorrow!
Google Cloud Tech
#GoogleCloudNext will be demand!
Google Cloud Tech
More on: Image Generation Basics
View skill →Related Reads
📰
📰
📰
📰
How can I batch-generate 3D assets from prompts or images using an API, and which 3D generation APIs support batch generation?
Reddit r/artificial
How AI Head Swap Works: The Technology Behind Realistic AI Image Replacement
Dev.to AI
How I Built an AI Pet Portrait Generator That Turns Photos Into Art
Dev.to · William Li
I Put Google’s Squoosh Codecs in the Browser — and Cut My Image Bill Before the Upload Even…
Medium · Programming
Chapters (7)
Intro
0:53
Building an image generation app
2:10
Creating a TorchServe app
3:02
Inference method for image generation
3:55
Deploying the app
5:08
Testing the app
5:58
Conclusion
🎓
Tutor Explanation
DeepCamp AI