Help Center/ Elastic Cloud Server/ Best Practices/ Best Practices for GPU ECSs/ Deploying Stable Diffusion WebUI on a GPU ECS
Updated on 2026-07-29 GMT+08:00

Deploying Stable Diffusion WebUI on a GPU ECS

Scenarios

Stable Diffusion provides comprehensive text-to-image generation capabilities. It is suitable for creating creative posters, advertising images, product concept images, packaging design drafts, game characters, scene concept images, and film storyboard sketches. It is a good choice for creative and design teams within enterprises to quickly iterate product prototypes. In addition, Stable Diffusion provides image-to-image generation capabilities to help you complete complex image editing without professional designers. These capabilities reduce costs and improve image processing efficiency.

You can deploy Stable Diffusion WebUI on GPU ECSs quickly and easily.

Architecture

Figure 1 Stable Diffusion WebUI deployment

Advantages

You can use GPU ECSs to deploy Stable Diffusion WebUI in a Conda virtual environment from scratch. This solution provides enterprises with a highly stable, reliable, and scalable dedicated compute environment for efficient AI productivity alongside robust privacy and security.

Resource Planning

Table 1 Resources and costs

Resource

Description

Cost

Security group

Inbound rule:

  • Priority: 1
  • Action: Allow
  • Type: IPv4
  • Protocol & Port: TCP:8000
  • Source: 0.0.0.0/0

Free

ECS

  • Billing mode: Yearly/Monthly
  • AZ: AZ1
  • Flavor: pi2.2xlarge.4 For more recommended specifications, see Table 2.
  • Image: Ubuntu 22.04 server 64bit with NO Driver(40 GiB); GPU driver version: 535; CUDA version: 12.2
  • System disk: 100 GiB
  • Data disk: 100 GiB
  • EIP: Auto assign
  • EIP type: Dynamic BGP
  • Billed by: Traffic
  • Bandwidth: 300 Mbit/s

The following resources generate costs:

  • ECSs
  • EVS disks
  • EIPs

For billing details, see Billing Mode Overview.

miniconda

Miniconda is a lightweight version of Conda, an environment management tool used to manage Python environments and install third-party libraries.

Download URL: https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

Free

Stable Diffusion WebUI

Stable Diffusion WebUI is a visualized web page interface for Stable Diffusion (SD). It supports operations such as text-to-image and image-to-image.

Download URL: https://github.com/AUTOMATIC1111/stable-diffusion-webui.git

Free

Table 2 GPU ECS flavors available for running Stable Diffusion WebUI

Model Name

Minimum Flavor

GPU

clip-vit-large-patch14

stable-diffusion-v1-5

pi2.2xlarge.4

T4 (16 GiB) × 1

p2s.4xlarge.8

V100 (32 GiB) × 1

g6.4xlarge.4

T4 (16 GiB) × 1

Contact Huawei Cloud technical support to select GPU ECSs suitable for your deployment.

Prerequisites

  • The rule listed in Table 3 has been added to the security group that the target ECS belongs to. For operation details, see Configuring Security Group Rules.
    Table 3 Security group rules

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source

    Inbound

    1

    Allow

    IPv4

    TCP: 8000

    0.0.0.0/0

Procedure

  1. Create a GPU ECS.

    Here, we use the pi2.2xlarge.4 flavor and the Ubuntu OS as an example. When creating the ECS, pay attention to the parameters listed below. For details about other parameters, see Purchasing an ECS in Custom Config Mode.

    1. Instance: Select pi2.2xlarge.4. For more recommended flavors, see Table 2.
    2. Image: You are advised to select the Huawei Cloud EulerOS 2.0 or Ubuntu 22.04 public image that does not have drivers installed for GPU ECSs.
      Figure 2 Selecting an image
    3. EIP: Select Auto assign to enable public network access. The EIP is used to download the environment dependencies and access Stable Diffusion WebUI.
    4. Security Group: Allow inbound traffic on TCP port 8000 to access Stable Diffusion WebUI. For operation details, see Configuring Security Group Rules.
    5. Storage & Backup: To ensure service stability and data security, you are advised to deploy the system disk and data disk separately.
      • System disk: 100 GiB, used to install the OS, driver, and runtime environment.
      • Data disk: 100 GiB, used to store the model file, generated images, and related service data.

  2. Check the GPU driver and CUDA versions.

    Query GPU details.

    nvidia-smi

    Install the driver of version 535 and CUDA of 12.2. For details, see Manually Installing a Tesla Driver on a GPU-accelerated ECS.

  3. Initialize the data disk to store the model file and related resources.

    After the GPU ECS is created, initialize the data disk by referring to Initializing a Linux Data Disk. In this example, we mount the data disk to the /mnt/model directory. You can change the directory as required.

  4. Create a conda virtual environment.

    1. Download the miniconda installation package.
      wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    2. Install miniconda.
      bash Miniconda3-latest-Linux-x86_64.sh
    3. Add the conda environment variable to the startup file.
      echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.bashrc
      source ~/.bashrc
    4. Create a virtual environment based on Python 3.10.6.
      conda create -n sdwebui python=3.10.6
      conda activate sdwebui

  5. Download the model file.

    1. Create a script for downloading the model.
      vim download_models.py

      Press i to enter insert mode and add the following content:

      from modelscope import snapshot_download
      model_dir = snapshot_download('AI-ModelScope/stable-diffusion-v1-5', cache_dir='/mnt/model', revision='master')

      AI-ModelScope/stable-diffusion-v1-5 indicates the model name, and /mnt/model indicates the directory where the model is stored. You can change the directory as required.

      After the content is added, press Esc to exit insert mode. Type :wq and press Enter to save the file and exit.

    2. Download the stable-diffusion model.
      pip install modelscope
      python download_models.py

      Wait until the model is downloaded. If Download model 'AI-ModelScope/stable-diffusion-v1-5' successfully. is displayed in the command output, the model is downloaded.

    3. Change the stable-diffusion model to the clip model.
      vim download_models.py

      Press i to enter insert mode and change the model name to clip-vit-large-patch14.

      model_dir = snapshot_download('AI-ModelScope/clip-vit-large-patch14', cache_dir='/mnt/model', revision='master')

      Press Esc to exit insert mode. Type :wq and press Enter to save the file and exit.

    4. Download the clip model.
      python download_models.py

      Wait until the model is downloaded. If Download model 'AI-ModelScope/clip-vit-large-patch14' successfully. is displayed in the command output, the model is downloaded.

    ModelScope is an open-source model community in China, which provides faster access in China. If you are using the model outside China, obtain it from Hugging Face.

  6. Install Stable Diffusion WebUI and its dependencies.

    1. Download the stable-diffusion-webui project.
      git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
    2. Go to the project directory and modify the project configuration.
      cd stable-diffusion-webui
      sed -i 's|stable_diffusion_repo = .*|stable_diffusion_repo = os.environ.get('"'"'STABLE_DIFFUSION_REPO'"'"', "https://github.com/w-e-w/stablediffusion.git")|' ./modules/launch_utils.py
    3. Move the model to the project directory.
      mv /mnt/model/AI-ModelScope/stable-diffusion-v1-5/v1-5-pruned-emaonly.safetensors /root/stable-diffusion-webui/models/Stable-diffusion/
      mkdir /root/stable-diffusion-webui/openai/
      mv /mnt/model/AI-ModelScope/clip-vit-large-patch14 /root/stable-diffusion-webui/openai/

  7. Start Stable Diffusion WebUI.

    Run the project.

    bash webui.sh -f --listen --port 8000 --no-hashing --no-download-sd-model --api

    If the command fails to be executed and the message Command: "/root/stable-diffusion-webui/venv/bin/python" -m pip install https://github.com/openai/CLIP/archive/d50d76daa670286dd6cacf3bcd80b5e4823fc8e1.zip --prefer-binary is displayed, run the following commands:

    source venv/bin/activate
    pip install git+https://github.com/openai/CLIP.git
    bash webui.sh -f --listen --port 8000 --no-hashing --no-download-sd-model --api

  8. Open Stable Diffusion WebUI for testing.

    1. View the EIP on the ECS details page.

    2. Open a browser and enter http://EIP:8000 to access Stable Diffusion WebUI.

    3. Open a browser and enter http://EIP:8000/docs to access the Stable Diffusion WebUI API documentation.

    Then, Stable Diffusion WebUI has been successfully deployed and verified. You can access http://EIP:8000 from a local browser to generate images through Web UI sessions or via API calls.