Use Serverless Function Compute to Deploy Stable Diffusion
By Hanxie
AIGC has gone viral! Stable Diffusion is also making waves in the realm of generative art, profoundly affecting painting, video production, and other related fields. Even ordinary people can produce amazing works of art with this technology.
Today, I will use Alibaba Cloud Function Compute to deploy Stable Diffusion WebUI to show you the charm of this technology.
Before starting with the technical tutorial, let's take a look at some pictures I generated with this technology.
Stable Diffusion WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui
Gallery
sd+ mdjrny/ChilloutMix

Cheese Daddy

Chinese style

daclefo_painting

Advantages of Function Compute
- It is out-of-the-box and can be quickly deployed through the Application Center or Serverless Devs without complex environment configuration.
- Based on the Serverless scaling policy, you are only charged after you start the service.
- It supports GPU rendering and generates images quickly at a low cost.
Preparation
- Activate Alibaba Cloud Function Compute[1]
- Activate Alibaba Cloud Container Registry (ACR)[2]
- Install Serverless Devs[3]
- Use Serverless Devs to configure Alibaba Cloud Key Information[4]
Quick Start
One-Line Instruction Deployment
- Create a local file directory (such as stable-diffusion)
- Create an s.yaml file in stable-diffusion with the following content:
edition: 1.0.0
name: fc-stable-diffusion
access: default
services:
cn-shanghai-stable-diffusion-sd:
component: devsapp/fc
props:
region: cn-shanghai
service:
description: stable-diffusion部署到函数计算
internetAccess: true
name: stable-diffusion
function:
handler: index.handler
timeout: 600
diskSize: 10240
caPort: 7860
instanceType: fc.gpu.tesla.1
runtime: custom-container
cpu: 8
customContainerConfig:
args: ''
accelerationType: Default
image: registry.cn-shanghai.aliyuncs.com/vipas/stable-diffusion-web:v2
accelerationInfo:
status: Preparing
command: ''
webServerMode: true
instanceConcurrency: 1
memorySize: 32768
environmentVariables: {}
gpuMemorySize: 16384
name: sd
asyncConfiguration: {}
triggers:
- name: defaultTrigger
description: ''
type: http
qualifier: LATEST
config:
methods:
- GET
- POST
- PUT
- DELETE
authType: anonymous
disableURLInternet: false
customDomains:
- domainName: auto
protocol: HTTP
routeConfigs:
- path: /*
- Execute the deployment instruction:
s deploy
Effect Preview and Operation
After executing the deployment instruction, you will get the access address, as shown in the following:http://sd.stable-diffusion.xxxxxx.cn-shanghai.fc.devsapp.net (xxxxxx is your account uid)
cn-shanghai-stable-diffusion-sd:
region: cn-shanghai
service:
name: stable-diffusion
function:
name: sd
runtime: custom-container
handler: index.handler
memorySize: 32768
timeout: 600
url:
system_url: https://sd-stable-iffusion-zulpjlkgaj.cn-shanghai.fcapp.run
custom_domain:
-
domain: http://sd.stable-diffusion.xxxxxx.cn-shanghai.fc.devsapp.net
triggers:
-
type: http
name: defaultTrigger
It takes Function Compute 3-4 minutes to start the first time. You need to complete operations, such as image pulling and cold start.
The final screen is shown below:

The default image provided comes with a base model, Stable Diffusion.
After the deployment is successful, you can enter some text descriptions to generate pictures. As shown in the picture above, Stable Diffusion generated a picture of a cute puppy 🐕.
Summary and Extension
You can use Function Compute to deploy Stable Diffusion and run it with one-line instruction. However, there are many practical problems. For example, the image used here only retains a base model, and the image needs to be re-mirrored if the model is expanded later, which is very troublesome. In addition, the overall cold start time is long, making the initial access experience not good. How to dynamically manage and extend the model and speed up the startup will be discussed further in the next practice section.
Related Links
[1] Function Compute
https://www.alibabacloud.com/product/function-compute
[2] Alibaba Cloud Container Registry (ACR)
https://www.alibabacloud.com/product/container-registry
[3] Serverless Devs
https://docs.serverless-devs.com/en/serverless-devs/quick_start
[4] Alibaba Cloud Key Information
https://docs.serverless-devs.com/en/serverless-devs/command/config
Read previous post:
Alibaba Cloud Function Compute Helps to Upgrade the Architecture of Amap RTA Advertising System
Read next post:
Summary of Stability Construction of Kubernetes-based Serverless PaaS
-
-
Alibaba Cloud Serverless
99 posts | 7 followers
Follow
Comments
-
-
Alibaba Cloud Serverless
99 posts | 7 followers
Follow
Related Products
-
Container Compute Service (ACS)
A cloud computing service that provides container compute resources that comply with the container specifications of Kubernetes
Learn More -
Function Compute
Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn More -
Container Registry
A secure image hosting platform providing containerized image lifecycle management
Learn More -
Container Service for Kubernetes
Alibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn More
More Posts by Alibaba Cloud Serverless
- Themepica Technology Enhances Data Processing Efficiency with Serverless
- Function Compute and AIGC Help Semir Generate Design Drafts Within 30 Seconds
- CloudFlow: Streamlined Development Makes It Easier to Build Applications on the Cloud
- Building an ETL System: The Best Practice for Database + Serverless Function Compute
- Why Does Serverless Improve Resource Utilization?
- Summary of Stability Construction of Kubernetes-based Serverless PaaS
- Alibaba Cloud Function Compute Helps to Upgrade the Architecture of Amap RTA Advertising System
- When Rokid Meets Function Compute
- Alibaba Cloud Serverless | Practice 2: Two Minutes to Deploy Serverless Application