This is a sample cloudformation template to launch latest version of AUTOMATIC1111/stable-diffusion-webui on EC2 instance. Some variant includes bmaltais/kohya_ss for training model and filebrowser/filebrowser for GUI based file manipulation.
There are four cloudformation templates:
Launch Stack | Cfn Template | Description |
---|---|---|
sd-webui.yaml | publicly accessible (some features are disabled for security reason) | |
sd-webui-private.yaml | privately accessible through SSM Session Manager Port Forwarding. File can be accessed using filebrowser/filebrowser. | |
sd-webui-kohya-private.yaml | privately accessible through SSM Session Manager Port Forwarding with bmaltais/kohya_ss installed as well. File can be accessed using filebrowser/filebrowser. | |
sd-webui-kohya-private-s3.yaml | privately accessible through SSM Session Manager Port Forwarding with bmaltais/kohya_ss installed as well. S3 is mounted for keeping file on cloud. File can be accessed using filebrowser/filebrowser. |
- Launch template from console or with command
aws cloudformation create-stack --stack-name sd-webui-stack --template-body file://sd-webui.yaml --region us-east-1 --parameters ParameterKey=SubnetId,ParameterValue=<SubnetId> ParameterKey=VpcId,ParameterValue=<VpcId>
- It takes 10 min ~ to launch application.
- Open
<public ip address>:7860
Prerequisite:
- Install session manager plugin following document if not installed yet
- Launch template from console or with command
aws cloudformation create-stack --stack-name sd-webui-stack --template-body file://sd-webui-private.yaml --region us-east-1 --parameters ParameterKey=SubnetId,ParameterValue=<SubnetId>
- It takes 10 min ~ to launch application.
- Run Port Forwarding with
./port-forwarding.sh <instance_id> <region> 7860 8080
- Open
localhost:7860
for Stable Diffusion Web UI. Openlocalhost:8080
for file browser.
For more control over SSM Session Manager, please check out the document to limit access of specific user to specific instance.
- Launch template from console or with command
aws cloudformation create-stack --stack-name sd-webui-stack --template-body file://sd-webui-kohya-private.yaml --region us-east-1 --parameters ParameterKey=SubnetId,ParameterValue=<SubnetId>
- Run Port Forwarding with
./port-forwarding.sh <instance_id> <region> 7860 7861 8080
- Open
localhost:7860
for Stable Diffusion Web UI. Openlocalhost:7861
for Kohya-ss. Openlocalhost:8080
for file browser.
- Launch template from console or with command
aws cloudformation create-stack --stack-name sd-webui-stack --template-body file://sd-webui-kohya-private-s3.yaml --region us-east-1 --parameters ParameterKey=EC2InstanceProfileName,ParameterValue=<InstanceProfile> ParameterKey=S3BucketName,ParameterValue=<Bucket> ParameterKey=SubnetId,ParameterValue=<SubnetId>
- Run Port Forwarding with
./port-forwarding.sh <instance_id> <region> 7860 7861 8080
- Open
localhost:7860
for Stable Diffusion Web UI. Openlocalhost:7861
for Kohya-ss. Openlocalhost:8080
for file browser.
- Access port 8080
- Enter default user/password: admin/admin
/home/ubuntu
is mapped tofiles
by default. (ex./files/s3
=/home/ubuntu/s3
)
- Access port 7861
- Upload Images using Filebrowser
- Generate CLIP for images from Utilities tab.
- Start Training. Check
kohya-log.txt
for training logs. - Download weight / move weight to
~/stable-diffusion-webui/models/Lora
to use it. - For detailed instruction, see bmaltais/kohya_ss
You can stop instance when you do not use it. The application will automatically launch when EC2 instance restarts.
You may use following commands to start/stop instance.
aws ec2 stop-instances --region <region> --instance-ids <instance-id>
aws ec2 start-instances --region <region> --instance-ids <instance-id>
You can either add extension from UI or command line.
When using command line with SSM Session Manager,
- Access server:
aws ssm start-session --region <region> --target <instance_id>
ssm-user
is the default user when using SSM Session Manager. You can change user withsudo su ubuntu
for example.
- Cannot access server
- Check reachability with VPC Reachability Analyzer
- Turn off VPN in case the port 7860 is blocked.
- See logs
-
- Get in to the instance with SSM Session Manager from console or with command
aws ssm start-session --region <region> --target <instance_id>
- Get in to the instance with SSM Session Manager from console or with command
-
- View log of running userdata with
tail /var/log/cloud-init-output.log
- View log of running userdata with
-
- View log of Stable Diffusion Web UI with
tail /home/ubuntu/sd-webui-log.txt
- View log of Stable Diffusion Web UI with
-
- View log of Kohya SS with
tail /home/ubuntu/kohya-log.txt
- View log of Kohya SS with
-
- Cannot access server with SSM Session Manager
- Follow SSM Session Manager guide to enable Session Manager
- It will be easier to opt for region level setting from Fleet Manager
- Cannot install extension from UI (Error: AssertionError: extension access disabled because of command line flags)
- CUDA out of memory for training.
- Stopping Stable Diffusion Web UI may save some GPU memory. Fine pid consuming GPU memory with
nvidia-smi
and stop it withkill -9 <pid>
- Alternatively, you may launch cloudformation template on larger instance.
- Stopping Stable Diffusion Web UI may save some GPU memory. Fine pid consuming GPU memory with
- Nothing happens after clicking train / caption on kohya_ss.
- There is no UI feedback for kohya_ss. See
kohya-log.txt
for logs. Access it from filebrowser or tail it.
- There is no UI feedback for kohya_ss. See
- Insufficient Capacity when launching instance
- Try another instance type supporting AMI or another region.
Cloudformation templates in this project uses following software.
- AUTOMATIC1111/stable-diffusion-webui: GNU Affero General Public License v3.0
- bmaltais/kohya_ss: Apache License 2.0
- filebrowser/filebrowser: Apache License 2.0
Although you may choose the model you like, stable-diffusion-webui downloads following model by default.