Closed7
AWSで stable-diffusion-webui を動かす
基本的には 下記通り
ただ、動かないところや 東京リージョンに合わせる修正をする
AMI の修正
Ec2ImageId
は下記にする
Ec2ImageId:
Type: String
Default: ami-09e6f55b0eefaa8ef
Description: Enter appropriate AMI ID in your region. Tested with "Deep Learning AMI GPU PyTorch 1.13.1 (Ubuntu 20.04) 20230510" in ap-north-east1.
立ち上げようとすると次のエラーが出る対策
Version: v1.3.2
Commit hash: baf6946e06249c5af9851c60171692c44ef633e0
Installing requirements
Launching Web UI with arguments: --xformers
Traceback (most recent call last):
File "/home/ubuntu/stable-diffusion-webui/launch.py", line 38, in <module>
main()
File "/home/ubuntu/stable-diffusion-webui/launch.py", line 34, in main
start()
File "/home/ubuntu/stable-diffusion-webui/modules/launch_utils.py", line 330, in start
import webui
File "/home/ubuntu/stable-diffusion-webui/webui.py", line 35, in <module>
import gradio
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/__init__.py", line 3, in <module>
import gradio.components as components
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/components.py", line 55, in <module>
from gradio import processing_utils, utils
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 339, in <module>
class AsyncRequest:
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 358, in AsyncRequest
client = httpx.AsyncClient()
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/httpx/_client.py", line 1397, in __init__
self._transport = self._init_transport(
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/httpx/_client.py", line 1445, in _init_transport
return AsyncHTTPTransport(
File "/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/httpx/_transports/default.py", line 275, in __init__
self._pool = httpcore.AsyncConnectionPool(
TypeError: AsyncConnectionPool.__init__() got an unexpected keyword argument 'socket_options'
下記と同様の方法で解消された
CloudFormationを修正しておく
# Launch Stable Diffusion Web UI
cd /home/ubuntu
# setup script uses existing folder if it exists. Feel free to change version here.
sudo -u ubuntu git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git -b ${SDWebUIVersion}
+ echo "httpx==0.24.1" | sudo -u ubuntu tee -a stable-diffusion-webui/requirements_versions.txt > /dev/null
sudo -u ubuntu nohup bash -c 'stable-diffusion-webui/webui.sh --xformers &> sd-webui-log.txt' &
全文
AWSTemplateFormatVersion: "2010-09-09"
Description: A CloudFormation template to deploy the Stable Diffusion Web UI by Automatic1111
Parameters:
SubnetId:
Description: The ID of the subnet where the EC2 instance will be launched.
Type: AWS::EC2::Subnet::Id
Ec2ImageId:
Type: String
Default: ami-09e6f55b0eefaa8ef
Description: Enter appropriate AMI ID in your region. Tested with "Deep Learning AMI GPU PyTorch 1.13.1 (Ubuntu 20.04) 20230510" in ap-north-east1.
Ec2InstanceType:
Type: String
Default: g4dn.xlarge
EC2InstanceProfileName:
Type: String
Description: Name of the existing IAM instance profile whic has access to S3 (arn:aws:iam::<account>:instance-profile/<EC2InstanceProfileName>)
S3BucketName:
Type: String
Description: Name of the S3 bucket to mount
SDWebUIVersion:
Type: String
Description: Branch of AUTOMATIC1111/stable-diffusion-webui
Default: v1.3.2
KohyaSSVersion:
Type: String
Description: Branch of bmaltais/kohya_ss
Default: v21.7.7
Resources:
EC2Instance:
Type: AWS::EC2::Instance
Properties:
InstanceType: !Ref Ec2InstanceType
ImageId: !Ref Ec2ImageId
IamInstanceProfile: !Ref EC2InstanceProfileName
SubnetId: !Ref SubnetId
BlockDeviceMappings:
- DeviceName: /dev/sda1
Ebs:
VolumeSize: 300
VolumeType: gp2
"Tags": [{ "Key": "Name", "Value": "sd-web-ui-cf" }]
UserData:
"Fn::Base64": !Sub |
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
# Install packages
sudo apt update
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt -y install wget git s3fs
sudo apt -y install python3 python-is-python3 python3-pip python3-venv
sudo apt -y install python3.10 python3.10-distutils python3.10-venv python3.10-tk
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10
python3.10 -m pip install --upgrade pip
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
# Mount S3
cd /home/ubuntu
sudo -u ubuntu mkdir -p s3
sudo -u ubuntu s3fs -o iam_role=auto -o use_cache=/tmp -o uid=1000 -o gid=1000 ${S3BucketName} /home/ubuntu/s3
# Launch Kohya
cd /home/ubuntu
sudo -u ubuntu git clone https://github.com/bmaltais/kohya_ss.git -b ${KohyaSSVersion}
cd kohya_ss
# Needs to specify branch in setup. Feel free to change version here.
./setup.sh -b ${KohyaSSVersion} -v
sudo -u ubuntu nohup bash -c './gui.sh --listen 127.0.0.1 --server_port 7861 --headless &> ../kohya-log.txt' &
# Launch Stable Diffusion Web UI
cd /home/ubuntu
# setup script uses existing folder if it exists. Feel free to change version here.
sudo -u ubuntu git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git -b ${SDWebUIVersion}
echo "httpx==0.24.1" | sudo -u ubuntu tee -a stable-diffusion-webui/requirements_versions.txt > /dev/null
sudo -u ubuntu nohup bash -c 'stable-diffusion-webui/webui.sh --xformers &> sd-webui-log.txt' &
# Launch File Browser
cd /home/ubuntu
sudo -u ubuntu curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
sudo -u ubuntu nohup bash -c 'filebrowser -r /home/ubuntu &> ./browser-log.txt' &
--//
Outputs:
InstanceID:
Description: EC2Instance ID
Value: !Ref EC2Instance
sd-webui-log.txt をみてると、ログが下記で立ち上がり切ってないように見える。
....
Installing requirements for CodeFormer
Installing requirements
Launching Web UI with arguments: --xformers
Downloading: "https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors" to /home/ubuntu/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors
100%|██████████| 3.97G/3.97G [01:04<00:00, 65.8MB/s]
/home/ubuntu/stable-diffusion-webui/venv/lib/python3.10/site-packages/huggingface_hub/file_download.py:797: FutureWarning: `resume_download` is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use `force_download=True`.
warnings.warn(
どれだけ時間を待ってもこのまま。
ただ、この状態でも繋いでみたら無事繋げたので気にしなくて良いっぽい。
Q. 再起動したら、プロセスも再起動される?
試したけど、問題なし。プロセスも立ち上がる。
ok
このスクラップは11日前にクローズされました