By binding an EAIS instance to an ECS instance (a non-GPU instance), you can create a GPU-accelerated compute environment. Compared with directly purchasing a GPU instance, this method provides greater elasticity and helps reduce both deployment and usage costs. You can bind an EAIS instance on demand to flexibly add GPU acceleration to an ECS instance. This topic describes how to bind an EAIS instance to an ECS instance, install a container, and use an EAIS-provided image, which includes EAIS and related model packages, to quickly deploy the Stable-Diffusion service.
Background information
Stable-Diffusion is an image generation model. You can deploy it by binding an EAIS instance to an ECS instance or by directly using a GPU instance. Deploying Stable-Diffusion with an EAIS instance can save costs compared to using a GPU instance directly. For more information about the benefits of EAIS, see Low cost.
For more information about Stable-Diffusion, see Stable-Diffusion.
For more information about GPU instances, see What is a GPU instance?.
Reduced deployment costs:
You do not need to create an EAIS instance until after you finish setting up the environment on your non-GPU ECS instance. During the setup period, you are billed only for the ECS instance. Deploying the environment on a GPU instance incurs higher costs during this phase.
Reduced usage costs:
Flexible GPU attachment: After you deploy Stable-Diffusion, you can unbind and release the EAIS instance when it is not needed. When you need to run tasks again, you can create and bind a new EAIS instance without affecting the environment on your ECS instance. This allows you to maintain a lower-cost ECS instance for the long term and bind an EAIS instance only when GPU power is required, leading to significant cost savings.
NoteFor EAIS instances created in the EAIS console or by calling the CreateEaisEi API operation, you can also control costs by stopping and starting the EAIS instance. You are billed only when the EAIS instance is running. Stopping the instance pauses billing, which further reduces costs.
Lower unit price: For equivalent compute power, an EAIS instance is less expensive than a GPU instance.
Billing
You are billed for the following resources when deploying and using Stable-Diffusion:
ECS instance: For more information, see Billing overview.
EAIS instance: For more information, see Product billing.
Environment
This tutorial uses the following example configurations to show you how to deploy Stable-Diffusion.
ECS instance:
Instance type: ecs.g7.xlarge (4 vCPUs, 16 GiB memory)
Operating system: Ubuntu 20.04
System disk capacity: 100 GiB
EAIS instance type: eais.ei-a6.2xlarge
Region and availability zone for the ECS and EAIS instances: China (Beijing) Zone I
NoteCreate the ECS instance in a region and availability zone where your selected EAIS instance type is available. Placing the ECS instance and the EAIS instance in the same availability zone improves inference performance. For information about the regions and availability zones that support specific EAIS instance types, see Instance type limitations.
Step 1: Create an ECS instance
Log on to the ECS instance creation page.
Create an ECS instance in a VPC to which you will bind the EAIS instance.
For detailed instructions, see Create an instance.
When you create the ECS instance, use the following parameters. You can configure other parameters as needed.
Parameter
Example configuration
Billing method
Pay-as-you-go
Region
China (Beijing)
Network and zone
Network Type: VPC
Availability Zone: China (Beijing) Zone I
Instance type
ecs.g7.xlarge
Image
Select Public Image and set it to Ubuntu 20.04 64-bit.
System disk
Set Capacity to 100 GiB.
Public IP
Select Assign Public IPv4 Address.
Step 2: Deploy Stable-Diffusion on the ECS instance
Remotely connect to the ECS instance.
For detailed instructions, see Use a username and password for authentication in Linux or Mac OS X.
Install Docker.
Run the following command to install Docker dependencies.
sudo apt-get update && \ sudo apt install -y software-properties-commonRun the following command to install Docker.
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository \ "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(lsb_release -cs) \ stable" && \ sudo apt-get update && \ sudo apt-get install -y docker-ce
Run the following command to pull the Stable-Diffusion image provided by EAIS.
sudo docker pull registry.cn-beijing.aliyuncs.com/eai_beijing/stable-diffusion-webui:v4.2.5
Step 3: Create and bind an EAIS instance
Create an EAIS instance.
For detailed instructions, see Create an EAIS instance.
When you create the EAIS instance, use the following parameters. You can configure other parameters as needed.
Parameter
Example configuration
Region
China (Beijing)
Instance type
eais.ei-a6.2xlarge
Bind the EAIS instance to the ECS instance. For detailed instructions, see Bind an EAIS instance to an ECS instance.
Step 4: Start the EAIS instance
This step is required only for EAIS instances that are created in the EAIS console or by calling the CreateEaisEi operation.
After you bind the EAIS instance to the ECS instance, you must start the EAIS instance to enable its GPU capabilities. For more information, see Start an EAIS instance.
Step 5: Start the Stable-Diffusion web service
Remotely connect to the ECS instance.
For detailed instructions, see Use a username and password for authentication in Linux or Mac OS X.
Run the following command to start the Stable-Diffusion web service.
sudo docker run --rm -it --net host registry.cn-beijing.aliyuncs.com/eai_beijing/stable-diffusion-webui:v4.2.5The following output indicates that the Stable-Diffusion web service has started successfully. Note the service port, which is 7860 by default.
root@ixxx Z:~# docker run --rm -it --net host registry.cn-beijing.aliyuncs.com/eai_beijing/stable-diffusion-webui:v4.2.5 Python 3.10.9 (main, Mar 8 2023, 10:47:38) [GCC 11.2.0] Version: v1.3.2 Commit hash: baf6xxx9f633e0 Launching Web UI with arguments: --listen --api --enable-insecure-extension-access --skip-install --xformers Calculating sha256 for /workspace/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors: Running on local URL: http://0.0.0.0:7860 To create a public link, set `share=True` in `launch()`. Startup time: 8.3s (import torch: 0.9s, import gradio: 1.2s, import ldm: 0.7s, other imports: 4.5s, load scripts: 0.4s, create ui: 0.2s). 6ce0xxx06fa2fa Loading weights [6ce0161689] from /workspace/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors Creating model from config: /workspace/stable-diffusion-webui/configs/v1-inference.yaml LatentDiffusion: Running in eps-prediction mode DiffusionWrapper has 859.52 M params.Configure a security group rule for the ECS instance.
Add a rule to the security group of your ECS instance to allow inbound traffic on port 7860. Set the source to the IP address or CIDR block from which you will access the Stable-Diffusion web service. For detailed instructions, see Add a security group rule. In the security group, add a rule for the inbound direction: set the Action to Allow, Priority to 1, protocol type to Custom TCP, destination port range to 7860, and the source to
172.16.0.0/12. For the description, enter "Add access permission for port 7860".On your local machine, access
http://The public IP address of your ECS instance:7860in a browser to verify that the Stable-Diffusion web service is deployed successfully. When you access the URL, the txt2img page of the Stable Diffusion WebUI is displayed. The Stable Diffusion checkpoint at the top has loaded thev1-5-pruned-emaonly.safetensorsmodel, which indicates that the web service is running properly.
(Optional) Step 6: Stop the EAIS instance
This operation is supported only for EAIS instances that are created in the EAIS console or by calling the CreateEaisEi operation.
If you temporarily do not need the GPU capabilities of the EAIS instance, stop it to avoid charges. For more information, see Stop an EAIS instance.
(Optional) Step 7: Unbind and release the EAIS instance
You can unbind and then release the EAIS instance to flexibly manage GPU resources.
Unbind the EAIS instance from the ECS instance.
For detailed instructions, see Unbind an EAIS instance from an ECS instance.
Release the EAIS instance.
For detailed instructions, see Release an EAIS instance.
Related documents
If you need to deploy ChatGLM-6B with an EAIS instance, see Deploy ChatGLM-6B by using an EAIS instance.
If you need to deploy ChatGLM2-6B with an EAIS instance, see Deploy ChatGLM2-6B by using an EAIS instance.