[Change the model by yourself] How to deploy Stable Diffusion with one click with Serverless?

Author: Han Xie

The previous article talked about how to use Serverless Devs and Function Compute to quickly experience the deployment of Stable Diffusion. This article continues to talk about how to solve the problem of dynamic model loading, from playing to using.

Thoughts

In fact, it is very simple, we only need to map the dynamic path in the image to NAS [ 1] file storage, and use NAS for independent storage File models, extensions, language packs, etc., and we can separately configure a visual background for managing NAS, and manage our files in a simple way of uploading and deleting files. For this reason, we need to expand the mirroring script, in order to complete the entire process Let’s take a look at the overall preparations next.

Preparation items

  1. Open Alibaba Cloud Function Compute [ 2]

  2. File storage NAS (you can create an instance with better performance according to the situation)

  3. Open Alibaba Cloud Container Mirroring Service ACR [ 3]

  4. Install Serverless Devs [ 4]

$ npm install @serverless-devs/s -g
  1. Use Serverless Devs Configure Alibaba Cloud key information [ 5]

Quick start

Initialize application template

s init fc-stable-diffusion-plus

Select region: cn-hangzhou

Input image: registry.cn-hangzhou.aliyuncs.com/serverlessdevshanxie/sd-auto-nas:v1

Deploy application template

cd fc-stable-diffusion-plus & amp; & amp; s deploy

Deployment will take some time (estimated 5 minutes), after which you will receive two domain names back.

fc-nas-init:
  region: cn-hangzhou
  service:
    name: fc-stable-diffusion-plus
  function:
    name: nas-init
    runtime: python3.9
    handler: index.handler
    memorySize: 3072
    timeout: 1200
    cpu: 2
    diskSize: 512
fc-nas-filemgr:
  region: cn-hangzhou
  service:
    name: fc-stable-diffusion-plus
  function:
    name: admin
    runtime: custom
    handler: index.handler
    memorySize: 3072
    timeout: 7200
    cpu: 2
    diskSize: 512
  url:
    system_url: https://xxx.cn-hangzhou.fcapp.run
    system_intranet_url: https://xxx.cn-hangzhou-vpc.fcapp.run
    custom_domain:
      -
        domain: http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.net
  triggers:
    -
      type: http
      name: httpTrigger
keep-warm:
  region: cn-hangzhou
  service:
    name: fc-stable-diffusion-plus
  function:
    name: keep-warm
    runtime: python3
    handler: index.handler
    memorySize: 128
    timeout: 120
    cpu: 0.1
    diskSize: 512
  triggers:
    -
      type: timer
      name: timerTrigger
stable-diffusion-sd-server:
  region: cn-hangzhou
  service:
    name: fc-stable-diffusion-plus
  function:
    name: sd
    runtime: custom-container
    handler: index.handler
    memorySize: 32768
    timeout: 600
    cpu: 8
    diskSize: 10240
  url:
    system_url: https://xxx.cn-hangzhou.fcapp.run
    system_intranet_url: https://xxx.cn-hangzhou-vpc.fcapp.run
    custom_domain:
      -
        domain: http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.net
  triggers:
    -
      type: http
      name: defaultTrigger

in:

http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.net is the background management page

http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.net is the interface of Stable Diffusion

Upload model

Because the model part is removed from the above container image, you cannot start the Stable Diffusion interface yet. You need to upload your own model, and then start the Stable Diffusion interface. There are two ways to upload the model:

Method 1

Upload through the visual interface, visit http://admin.fc-stable-diffusion-plus.xxxx.cn-hangzhou.fc.devsapp.net, click on it, after configuring the login password, come to this interface: file management, and then Enter “/mnt/auto/sd” in the path bar

You will see the local directory you are familiar with~

Then visit models/Stable-diffusion/ and drag the model in.

However, it is worth noting that the model uploaded in this way will be unstable when it exceeds 2 or 3 G. So if your model is very large, you can consider using the nas command we provide.

Method 2

Use the nas command to upload, enter the project root directory, and execute ↓

s fc-nas-init nas upload -r <your model address> /mnt/auto/sd/models/Stable-diffusion/

That’s it, all that’s left is to wait, which can take up to 30 minutes.

Note: Others such as controlNet and extension can follow a similar method, but pay attention to changing the corresponding nas address.

Page preview

When we are ready, we start using the page, open this address↓

http://sd.fc-stable-diffusion-plus.xxxxx.cn-hangzhou.fc.devsapp.net There will be a certain loading time on cold start.

Wen Shengtu

Graphic graph

Others can explore more by themselves.

Prize experience

Alibaba Cloud will provide free serverless function computing product resources, and invite you to experience the pleasure of painting by AIGC-level masters such as Picasso, Leonardo da Vinci, and Van Gogh. Please let your imagination run wild! ! Double prize setting, complete the experience scene, you can get 1000 points in the community to exchange for prizes, and you can also participate in the AI-generated image competition to win Airpods, 500 yuan cat super card and community custom pillows!

Experience address:

https://developer.aliyun.com/topic/aigc

You can also easily make the following paintings

Related links:

[1] NAS

https://www.aliyun.com/product/nas?spm=5176

[2] Function Compute

https://www.aliyun.com/product/fc?spm=5176.devs

[3] Container Mirroring Service ACR

https://www.aliyun.com/product/acr?spm=5176.28055625.J_3207526240.121.1d22154aWn0gl1 & amp;scm=20140722.M_4776670._.V_1

[4] Serverless Devs

https://docs.serverless-devs.com/serverless-devs/quick_start

[5] Configure Alibaba Cloud key information

https://docs.serverless-devs.com/serverless-devs/command/config#config-add-command

Click here to enter the experience