×
Community Blog Use Serverless Function Compute to Deploy Stable Diffusion

Use Serverless Function Compute to Deploy Stable Diffusion

This article uses Alibaba Cloud Function Compute to deploy Stable Diffusion WebUI, explaining its advantages and showing examples.

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

1

Cheese Daddy

2

Chinese style

3

daclefo_painting

4

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

  1. Activate Alibaba Cloud Function Compute[1]
  2. Activate Alibaba Cloud Container Registry (ACR)[2]
  3. Install Serverless Devs[3]
  4. 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:

5

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

0 1 0
Share on

Alibaba Cloud Serverless

99 posts | 7 followers

You may also like

Comments