Quickly launch Stable Diffusion WebUI using DSW
This topic describes how to quickly launch Stable Diffusion WebUI in DSW to perform model inference with a Stable Diffusion (SD) model.
Background information
Artificial Intelligence Generated Content (AIGC) uses artificial intelligence (AI) technology to automatically create content. It is the next major industrial trend after the Internet era. Text-to-image generation is a popular cross-modality task that creates images from text descriptions. This tutorial shows an example of launching Stable-Diffusion-WebUI to perform SD model inference. The following figure shows the expected result.
Prepare the environment and resources
Activate PAI and create a workspace. For more information, see Activate PAI and create a default workspace.
Create a DSW instance. Configure the key parameters as follows. For more information, see Create a DSW instance.
Region and Zone: For this tutorial, select one of the following regions: China (Beijing), China (Shanghai), China (Hangzhou), or China (Shenzhen). These regions provide faster download speeds for the ChatGLM model data.
Instance Type: ecs.gn6v-c8g1.2xlarge.
Image: From Alibaba Cloud Image, select
stable-diffusion-webui-develop:1.0-pytorch2.0-gpu-py310-cu117-ubuntu22.04.
Step 1: Download the stable-diffusion-webui open source library and other dependencies
Open the DSW instance, go to the Launcher page, select the Notebook tab, and then click Python 3 under Notebook in the QuickStart area.
In the Notebook, run the following code to download the files.
import os ! apt update ! apt install -y aria2 def aria2(url, filename, d): !aria2c --console-log-level=error -c -x 16 -s 16 {url} -o {filename} -d {d} url_prefix = { "cn-shanghai": "http://pai-vision-data-sh.oss-cn-shanghai-internal.aliyuncs.com", "cn-hangzhou": "http://pai-vision-data-hz2.oss-cn-hangzhou-internal.aliyuncs.com", "cn-shenzhen": "http://pai-vision-data-sz.oss-cn-shenzhen-internal.aliyuncs.com", "cn-beijing": "http://pai-vision-data-bj.oss-cn-beijing-internal.aliyuncs.com", } dsw_region = os.environ.get("dsw_region") prefix = url_prefix[dsw_region] if dsw_region in url_prefix else "http://pai-vision-data-sh.oss-cn-shanghai.aliyuncs.com" webui_url = f"{prefix}/aigc-data/code/stable-diffusion-webui-v1.tar.gz" aria2(webui_url, webui_url.split("/")[-1], "./")
Step 2: Install common plug-ins
This example installs the tagcomplete and Chinese localization plug-ins by default. You can also add other plug-ins as needed.
! tar -xf stable-diffusion-webui-v1.tar.gz
! cd stable-diffusion-webui && wget -c http://pai-vision-data-sh.oss-cn-shanghai.aliyuncs.com/aigc-data/webui_config/config.json
Step 3: Download the model
This example uses the open source SD model Counterfeit-v2.5 as the base model. To ensure a stable download, a cached link is provided on OSS. Run the following command to download the cached model.
model_url = f"{prefix}/aigc-data/sd_models/Counterfeit-V2.5_fp16.safetensors"
aria2(model_url, model_url.split("/")[-1], "stable-diffusion-webui/models/Stable-diffusion")
vae_url = f"{prefix}/aigc-data/vae_models/Counterfeit-V2.5.vae.pt"
aria2(vae_url, vae_url.split("/")[-1], "stable-diffusion-webui/models/VAE")
embedding_url = f"{prefix}/aigc-data/embedding/EasyNegative.safetensors"
aria2(embedding_url, embedding_url.split("/")[-1], "stable-diffusion-webui/embeddings")
clip_url = f"{prefix}/aigc-data/clip/ViT-L-14.pt"
! mkdir -p /root/.cache/clip
aria2(clip_url, clip_url.split("/")[-1], " /root/.cache/clip")
bert_url = f"{prefix}/aigc-data/hug_model/models--bert-base-uncased.tar.gz"
aria2(bert_url, bert_url.split("/")[-1], "~/.cache/huggingface/hub")
! cd ~/.cache/huggingface/hub && tar -xvf models--bert-base-uncased.tar.gz
Alternatively, you can download the models from their open source addresses:
After the models are downloaded, you can also download other types of SD models from ModelScope or HuggingFace. Save them to the ./stable-diffusion-webui/models directory. On the WebUI page, you can then switch to these models for inference.
Step 4: Launch the WebUI
Run the following command to launch the WebUI.
! cd stable-diffusion-webui && python launch.py --no-half-vae --xformersIn the output, click the URL that follows
Running on public URL, such as http://127.0.0.1:7860, to open the WebUI page. You can then perform model inference on this page.NoteBecause
http://127.0.0.1:7860is an internal endpoint, you can access the WebUI page only by clicking the link from within the current DSW instance. You cannot access it directly from an external browser.
Step 5: Test the model
After you complete the preceding steps, the WebUI for the AIGC text-to-image model is deployed. You can now test the deployment by performing model inference on the WebUI page. Configure the parameters as follows, and then click Generate.

VAE model: Counterfeit-V2.5.vae.pt
Prompts:
Prompt
((masterpiece,best quality)),1girl, solo, animal ears, rabbit, barefoot, knees up, dress, sitting, rabbit ears, short sleeves, looking at viewer, grass, short hair, smile, white hair, puffy sleeves, outdoors, puffy short sleeves, bangs, on ground, full body, animal, white dress, sunlight, brown eyes, dappled sunlight, day, depth of fieldNegative prompt (Used to prevent or reduce unwanted content in the generated image)
EasyNegative, extra fingers,fewer fingers
Sampler: DPM++2M Karras
Hires. fix: Click
and configure the following parameters:Denoising strength: 0.6
Upscale by: 1.8
Height: 832
CFG Scale: 10
Seed: 2337269170
References
For more information about DSW, see Overview of DSW.
For more information about how to fine-tune an AIGC Stable Diffusion text-to-image LoRA model in DSW and use the WebUI for virtual try-on, see Fine-tune an AIGC Stable Diffusion text-to-image LoRA model for virtual try-on.
Elastic Algorithm Service (EAS) provides a pre-built stable-diffusion-webui image. You can use this image to quickly build an AI web application based on the AIGC Stable Diffusion WebUI. For more information, see Quickly deploy an AI art SDWebUI application using EAS.