🔥 Supports Release 1.5.1 · AUTOMATIC1111/stable-diffusion-webui - released at July 27, 2023
A quickstart automation to deploy AUTOMATIC1111 stable-diffusion-webui with AWS EC2.
The CloudFormation template deploys an EC2 instance in your AWS environment. The user data will install and configure Stable Diffusion WebUI automatically at launch. The one-click deployment takes around 20 minutes to complete.
-
A GPU-based EC2 instance
- AMI:
Deep Learning AMI GPU PyTorch 1.13.1 (Ubuntu 20.04) 20230530
- static public IP address (Elastic IP)
- swap volumes from instance store
- security group allows only whitelist IP CIDR to access
- AMI:
-
Auto install stable-diffusion-webui and run as a systemctl service
-
Auto install some popular models, extensions and embeddings
Open this link to request for service quota increase for G instances. Make sure you are requesting the correct AWS region! The limit has to be at least 4 for running one xlarge instance. You may request for a higher quota such as 8 or 16.
AWS accounts have quotas in each region that limit how many vCPUs of a particular instance type you can run at once. The quota for GPU instances are all 0 for a new AWS account. It may take a couple days for AWS to approve the quota increase.
Follow this link to create a key pair so that you can connect to the instance using SSH.
-
Download template sd-webui-ec2.yaml and save it locally.
-
Log in to the AWS CloudFormation console at https://console.aws.amazon.com/cloudformation. Choose Create stack with new resources (standard), then choose Upload a template file as template source, with the file that you downloaded in the first step.
-
For stack details,
-
Stack Name:
sd-webui
(any name you like) -
Ec2KeyPair: Choose a EC2 key pair
-
Ec2InstanceType:
g5.xlarge
org4dn.xlarge
should be good.g5.xlarge
- $0.526 per hour in us-east-1- 4 vCPU + 16 GB RAM + NVIDIA A10G GPU / 16 GB VRAM
- available in limited regions, such as us-east-1 (N. Virginia), us-east-2 (Ohio), us-west-2 (Oregon), eu-west-1 (Ireland), eu-west-2 (London) and ap-southeast-1 (Singapore)
- it takes around 0.5 minutes to generate an image of 512x768px with 28 steps + highres fix 2x upscaling with 20 steps
g4dn.xlarge
- $1.006 per hour in us-east-1- 4 vCPU + 16 GB RAM + NVIDIA T4 GPU / 16 GB VRAM
- available in many AWS regions
- it takes around 1.5 minutes to generate an image of 512x768px with 28 steps + highres fix 2x upscaling with 20 steps
-
CidrBlock: Input your public address so only you can access the Web UI and ssh. Choose
0.0.0.0/0
if you don't mind everyone can access.
-
-
The stack status will become
CREATE_COMPLETE
around 10 minutes.Command to view installation log:
tail -f /var/log/cloud-init-output.log
-
The first launch of
stable-diffusion-webui
takes up to 10 minutes to install its python dependencies. Then you can open the stable diffusion web UI using the link in output tab.Command to view WebUI log:
journalctl -f -u sd-webui
You can connect to the EC2 instance using one of the following methods.
ssh key pair
ssh -i <key-pair.pem> ubuntu@<ip-address>SSM Session Manager (from the
Connect
button in AWS console), then switch toubuntu
usersudo su ubuntu
Common commands:
-
View installation log:
tail -f /var/log/cloud-init-output.log
-
View WebUI log:
journalctl -afu sd-webui
-
Start WebUI:
sudo systemctl start sd-webui
-
Stop WebUI:
sudo systemctl start sd-webui
-
Check WebUI service status:
systemctl status sd-webui
-
Disable WebUI start on boot:
sudo systemctl disable sd-webui
-
Run WebUI foreground:
cd stable-diffusion-webui/; ./webui.sh --listen
https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki
Installed Models
Installed Loras
Installed Extensions
- Stable-Diffusion-Webui-Civitai-Helper
- sd-webui-additional-networks
- sd-webui-infinite-image-browsing
- sd-webui-roop
- sd-webui-controlnet
- Model files for ControlNet 1.1 - canny and openpose only
- openpose-editor
Installed Textual Inversion (Embeds)
Some models that I like
You can download models easily by pasting the Civitai link in
Civitai Helper
->Civitai URL
inDownload Model
.
If you see this error stable diffusion webui pretraining cv2.error: OpenCV(4.8.0) /io/opencv/modules/dnn/src/net_impl.cpp:279: error: (-204:Requested object was not found) Layer with requested id=-1 not found in function 'getLayerData'
, trying downgrade OpenCV to 4.7.0.72 as suggested here.
cd stable-diffusion-webui/
source venv/bin/activate
pip install opencv-python==4.7.0.72
deactivate
sudo systemctl restart sd-webui
Modify /home/ubuntu/stable-diffusion-webui/webui-user.sh
and restart WebUI by sudo systemctl start sd-webui
. More details of command line arguments can be found at https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Command-Line-Arguments-and-Settings.