|
|
|
|
@ -1,43 +1,36 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
nginx &
|
|
|
|
|
|
|
|
|
|
export ESD_CODE_BRANCH=main
|
|
|
|
|
export INSTALL_SCRIPT=https://raw.githubusercontent.com/awslabs/stable-diffusion-aws-extension/main/install.sh
|
|
|
|
|
export ESD_VERSION='1.5.0'
|
|
|
|
|
export WEBUI_PORT=8080
|
|
|
|
|
|
|
|
|
|
if [[ $ECR_IMAGE_TAG == *"dev"* ]]; then
|
|
|
|
|
export ESD_CODE_BRANCH=dev
|
|
|
|
|
export INSTALL_SCRIPT=https://raw.githubusercontent.com/awslabs/stable-diffusion-aws-extension/dev/install.sh
|
|
|
|
|
trap 'echo "error_lock" > /error_lock; exit 1' ERR
|
|
|
|
|
if [ -f "/error_lock" ]; then
|
|
|
|
|
# nginx -c /etc/nginx/nginx_error.conf &
|
|
|
|
|
echo "start failed, please check the log"
|
|
|
|
|
sleep 30
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "*********************************************************************************"
|
|
|
|
|
cat $0
|
|
|
|
|
cores=$(lscpu | grep "^Core(s) per socket:" | awk '{print $4}')
|
|
|
|
|
sockets=$(lscpu | grep "^Socket(s):" | awk '{print $2}')
|
|
|
|
|
cup_core_nums=$((cores * sockets))
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "whoami: $(whoami)"
|
|
|
|
|
echo "cup_core_nums: $cup_core_nums"
|
|
|
|
|
echo "Current shell: $SHELL"
|
|
|
|
|
echo "Running in $(bash --version)"
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
nvidia-smi
|
|
|
|
|
export INSTALL_SCRIPT=https://raw.githubusercontent.com/awslabs/stable-diffusion-aws-extension/$ESD_CODE_BRANCH/install.sh
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
printenv
|
|
|
|
|
|
|
|
|
|
export ESD_VERSION='1.5.0'
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "INSTANCE_TYPE: $INSTANCE_TYPE"
|
|
|
|
|
echo "ECR_IMAGE_TAG: $ECR_IMAGE_TAG"
|
|
|
|
|
echo "IMAGE_URL: $IMAGE_URL"
|
|
|
|
|
echo "ENDPOINT_NAME: $ENDPOINT_NAME"
|
|
|
|
|
echo "ENDPOINT_ID: $ENDPOINT_ID"
|
|
|
|
|
echo "ESD_VERSION: $ESD_VERSION"
|
|
|
|
|
echo "CREATED_AT: $CREATED_AT"
|
|
|
|
|
created_time_seconds=$(date -d "$CREATED_AT" +%s)
|
|
|
|
|
current_time=$(date "+%Y-%m-%dT%H:%M:%S.%6N")
|
|
|
|
|
@ -47,15 +40,15 @@ echo "NOW_AT: $current_time"
|
|
|
|
|
echo "Init from Create: $init_seconds seconds"
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
export S3_LOCATION="esd-$ESD_VERSION-$INSTANCE_TYPE"
|
|
|
|
|
export S3_LOCATION="esd-$INSTANCE_TYPE-$ESD_VERSION"
|
|
|
|
|
|
|
|
|
|
if [ -n "$EXTENSIONS" ]; then
|
|
|
|
|
export S3_LOCATION="$ENDPOINT_NAME"
|
|
|
|
|
export S3_LOCATION="$ENDPOINT_NAME-$ESD_VERSION"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
tar_file="webui.tar"
|
|
|
|
|
|
|
|
|
|
echo "Check s3://$BUCKET_NAME/$S3_LOCATION files..."
|
|
|
|
|
echo "Checking s3://$BUCKET_NAME/$S3_LOCATION files..."
|
|
|
|
|
output=$(s5cmd ls "s3://$BUCKET_NAME/")
|
|
|
|
|
if echo "$output" | grep -q "$S3_LOCATION"; then
|
|
|
|
|
|
|
|
|
|
@ -90,32 +83,63 @@ if echo "$output" | grep -q "$S3_LOCATION"; then
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "accelerate launch..."
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process=6 launch.py --api --listen --port 7860 --xformers --no-half-vae --no-download-sd-model --no-hashing --nowebui --skip-torch-cuda-test --skip-load-model-at-start --disable-safe-unpickle --skip-prepare-environment --skip-python-version-check --skip-install --skip-version-check
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process=$cup_core_nums launch.py --enable-insecure-extension-access --api --api-log --log-startup --listen --port $WEBUI_PORT --xformers --no-half-vae --no-download-sd-model --no-hashing --nowebui --skip-torch-cuda-test --skip-load-model-at-start --disable-safe-unpickle --skip-prepare-environment --skip-python-version-check --skip-install --skip-version-check
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Not found files in S3, just install the environment..."
|
|
|
|
|
|
|
|
|
|
cd /home/ubuntu
|
|
|
|
|
curl -sSL "$INSTALL_SCRIPT" | bash;
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "Set conda"
|
|
|
|
|
export AWS_REGION="us-west-2"
|
|
|
|
|
s5cmd --log=error cp "s3://aws-gcr-solutions-us-west-2/extension-for-stable-diffusion-on-aws/1.5.0-g5/conda/libcufft.so.10" /home/ubuntu/conda/lib/
|
|
|
|
|
s5cmd --log=error cp "s3://aws-gcr-solutions-us-west-2/extension-for-stable-diffusion-on-aws/1.5.0-g5/conda/libcurand.so.10" /home/ubuntu/conda/lib/
|
|
|
|
|
export LD_LIBRARY_PATH=/home/ubuntu/conda/lib:$LD_LIBRARY_PATH
|
|
|
|
|
export AWS_REGION=$AWS_DEFAULT_REGION
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
# if $EXTENSIONS is not empty, it will be executed
|
|
|
|
|
if [ -n "$EXTENSIONS" ]; then
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "install extensions..."
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui/extensions/ || exit 1
|
|
|
|
|
|
|
|
|
|
cd stable-diffusion-webui
|
|
|
|
|
read -ra array <<< "$(echo "$EXTENSIONS" | tr "," " ")"
|
|
|
|
|
|
|
|
|
|
for git_repo in "${array[@]}"; do
|
|
|
|
|
IFS='#' read -r -a repo <<< "$git_repo"
|
|
|
|
|
|
|
|
|
|
git_repo=${repo[0]}
|
|
|
|
|
repo_name=$(basename -s .git "$git_repo")
|
|
|
|
|
repo_branch=${repo[1]}
|
|
|
|
|
commit_sha=${repo[2]}
|
|
|
|
|
|
|
|
|
|
echo "rm -rf $repo_name for install $git_repo"
|
|
|
|
|
rm -rf $repo_name
|
|
|
|
|
|
|
|
|
|
start_at=$(date +%s)
|
|
|
|
|
|
|
|
|
|
echo "git clone $git_repo"
|
|
|
|
|
git clone "$git_repo"
|
|
|
|
|
|
|
|
|
|
cd $repo_name || exit 1
|
|
|
|
|
|
|
|
|
|
echo "git checkout $repo_branch"
|
|
|
|
|
git checkout "$repo_branch"
|
|
|
|
|
|
|
|
|
|
echo "git reset --hard $commit_sha"
|
|
|
|
|
git reset --hard "$commit_sha"
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
end_at=$(date +%s)
|
|
|
|
|
cost=$((end_at-start_at))
|
|
|
|
|
echo "git clone $git_repo: $cost seconds"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "creating venv and install packages..."
|
|
|
|
|
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui
|
|
|
|
|
python3 -m venv venv
|
|
|
|
|
|
|
|
|
|
# chmod +x /home/ubuntu/stable-diffusion-webui/venv/bin/*
|
|
|
|
|
|
|
|
|
|
source venv/bin/activate
|
|
|
|
|
|
|
|
|
|
python -m pip install --upgrade pip
|
|
|
|
|
python -m pip install accelerate
|
|
|
|
|
python -m pip install markdown
|
|
|
|
|
|
|
|
|
|
python -m pip install onnxruntime-gpu
|
|
|
|
|
python -m pip install insightface==0.7.3
|
|
|
|
|
|
|
|
|
|
@ -123,81 +147,106 @@ export TORCH_INDEX_URL="https://download.pytorch.org/whl/cu118"
|
|
|
|
|
export TORCH_COMMAND="pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url $TORCH_INDEX_URL"
|
|
|
|
|
export XFORMERS_PACKAGE="xformers==0.0.20"
|
|
|
|
|
|
|
|
|
|
# if $EXTENSIONS is not empty, it will be executed
|
|
|
|
|
if [ -n "$EXTENSIONS" ]; then
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui/extensions/ || exit 1
|
|
|
|
|
remove_unused(){
|
|
|
|
|
echo "rm $1"
|
|
|
|
|
rm -rf "$1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
read -ra array <<< "$(echo "$EXTENSIONS" | tr "," " ")"
|
|
|
|
|
remove_unused_list(){
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "deleteing big unused files..."
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/docs
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/infrastructure
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/middleware_api
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/test
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/repositories/BLIP/BLIP.gif
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/repositories/generative-models/assets/
|
|
|
|
|
remove_unused /home/ubuntu/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/assets/
|
|
|
|
|
|
|
|
|
|
for git_repo in "${array[@]}"; do
|
|
|
|
|
start_at=$(date +%s)
|
|
|
|
|
echo "git clone $git_repo"
|
|
|
|
|
git clone "$git_repo"
|
|
|
|
|
end_at=$(date +%s)
|
|
|
|
|
cost=$((end_at-start_at))
|
|
|
|
|
echo "git clone $git_repo: $cost seconds"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
echo "deleteing git dir..."
|
|
|
|
|
find /home/ubuntu/stable-diffusion-webui -type d \( -name '.git' -o -name '.github' \) | while read dir; do
|
|
|
|
|
remove_unused "$dir";
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/docs
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/infrastructure
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/middleware_api
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/extensions/stable-diffusion-aws-extension/test
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/repositories/BLIP/BLIP.gif
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/repositories/generative-models/assets/
|
|
|
|
|
rm -rf /home/ubuntu/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/assets/
|
|
|
|
|
echo "deleteing unused files..."
|
|
|
|
|
find /home/ubuntu/stable-diffusion-webui -type f \( -name '.gitignore' -o -name 'README.md' -o -name 'CHANGELOG.md' \) | while read file; do
|
|
|
|
|
remove_unused "$file";
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "delete git..."
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type d -name '.git' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type d -name '.github' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name '.gitignore' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name 'README.md' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name 'CHANGELOG.md' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name 'CODE_OF_CONDUCT.md' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name 'LICENSE.md' -exec rm -rf {} +
|
|
|
|
|
find "/home/ubuntu/stable-diffusion-webui" -type f -name 'NOTICE.md' -exec rm -rf {} +
|
|
|
|
|
find /home/ubuntu/stable-diffusion-webui -type f \( -name 'CODE_OF_CONDUCT.md' -o -name 'LICENSE.md' -o -name 'NOTICE.md' \) | while read file; do
|
|
|
|
|
remove_unused "$file";
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
check_ready() {
|
|
|
|
|
while true; do
|
|
|
|
|
PID=$(lsof -i :8080 | awk 'NR!=1 {print $2}' | head -1)
|
|
|
|
|
find /home/ubuntu/stable-diffusion-webui -type f \( -name 'CODEOWNERS' -o -name 'LICENSE.txt' -o -name 'LICENSE' \) | while read file; do
|
|
|
|
|
remove_unused "$file";
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ -n "$PID" ]; then
|
|
|
|
|
echo "Port 8080 is in use by PID: $PID. tar files and upload to S3"
|
|
|
|
|
|
|
|
|
|
echo "collection big files..."
|
|
|
|
|
upload_files=$(mktemp)
|
|
|
|
|
big_files=$(find "/home/ubuntu/stable-diffusion-webui" -type f -size +2520k)
|
|
|
|
|
for file in $big_files; do
|
|
|
|
|
key=$(echo "$file" | cut -d'/' -f4-)
|
|
|
|
|
echo "sync $file s3://$BUCKET_NAME/$S3_LOCATION/$key" >> "$upload_files"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "tar files..."
|
|
|
|
|
filelist=$(mktemp)
|
|
|
|
|
# shellcheck disable=SC2164
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui
|
|
|
|
|
find "./" \( -type f -o -type l \) -size -2530k > "$filelist"
|
|
|
|
|
tar -cf $tar_file -T "$filelist"
|
|
|
|
|
|
|
|
|
|
echo "sync $tar_file s3://$BUCKET_NAME/$S3_LOCATION/" >> "$upload_files"
|
|
|
|
|
echo "sync /home/ubuntu/conda/* s3://$BUCKET_NAME/$S3_LOCATION/conda/" >> "$upload_files"
|
|
|
|
|
echo "sync /home/ubuntu/stable-diffusion-webui/models/insightface/* s3://$BUCKET_NAME/$S3_LOCATION/insightface/" >> "$upload_files"
|
|
|
|
|
|
|
|
|
|
echo "upload files..."
|
|
|
|
|
s5cmd run "$upload_files"
|
|
|
|
|
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Port 8080 is not in use, waiting for 10 seconds..."
|
|
|
|
|
sleep 1
|
|
|
|
|
find /home/ubuntu/stable-diffusion-webui -type f \( -name '*.gif' -o -name '*.png' -o -name '*.jpg' \) | while read file; do
|
|
|
|
|
remove_unused "$file";
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
check_ready &
|
|
|
|
|
check_ready() {
|
|
|
|
|
while true; do
|
|
|
|
|
RESPONSE_CODE=$(curl -o /dev/null -s -w "%{http_code}\n" localhost:8080/ping)
|
|
|
|
|
if [ "$RESPONSE_CODE" -eq 200 ]; then
|
|
|
|
|
echo "Server is ready!"
|
|
|
|
|
|
|
|
|
|
start_at=$(date +%s)
|
|
|
|
|
|
|
|
|
|
echo "collection big files..."
|
|
|
|
|
upload_files=$(mktemp)
|
|
|
|
|
big_files=$(find "/home/ubuntu/stable-diffusion-webui" -type f -size +2520k)
|
|
|
|
|
for file in $big_files; do
|
|
|
|
|
key=$(echo "$file" | cut -d'/' -f4-)
|
|
|
|
|
echo "sync $file s3://$BUCKET_NAME/$S3_LOCATION/$key" >> "$upload_files"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
echo "tar files..."
|
|
|
|
|
filelist=$(mktemp)
|
|
|
|
|
# shellcheck disable=SC2164
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui
|
|
|
|
|
find "./" \( -type f -o -type l \) -size -2530k > "$filelist"
|
|
|
|
|
tar -cf $tar_file -T "$filelist"
|
|
|
|
|
|
|
|
|
|
echo "sync $tar_file s3://$BUCKET_NAME/$S3_LOCATION/" >> "$upload_files"
|
|
|
|
|
echo "sync /home/ubuntu/conda/* s3://$BUCKET_NAME/$S3_LOCATION/conda/" >> "$upload_files"
|
|
|
|
|
|
|
|
|
|
# for ReActor
|
|
|
|
|
echo "sync /home/ubuntu/stable-diffusion-webui/models/insightface/* s3://$BUCKET_NAME/$S3_LOCATION/insightface/" >> "$upload_files"
|
|
|
|
|
|
|
|
|
|
echo "upload files..."
|
|
|
|
|
s5cmd run "$upload_files"
|
|
|
|
|
end_at=$(date +%s)
|
|
|
|
|
cost=$((end_at-start_at))
|
|
|
|
|
echo "sync endpoint files: $cost seconds"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep 2
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "set conda environment..."
|
|
|
|
|
export AWS_REGION="us-west-2"
|
|
|
|
|
s5cmd --log=error cp "s3://aws-gcr-solutions-us-west-2/extension-for-stable-diffusion-on-aws/1.5.0-g5/conda/libcufft.so.10" /home/ubuntu/conda/lib/
|
|
|
|
|
s5cmd --log=error cp "s3://aws-gcr-solutions-us-west-2/extension-for-stable-diffusion-on-aws/1.5.0-g5/conda/libcurand.so.10" /home/ubuntu/conda/lib/
|
|
|
|
|
export LD_LIBRARY_PATH=/home/ubuntu/conda/lib:$LD_LIBRARY_PATH
|
|
|
|
|
export AWS_REGION=$AWS_DEFAULT_REGION
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
nvidia-smi
|
|
|
|
|
|
|
|
|
|
cd /home/ubuntu/stable-diffusion-webui
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "install webui..."
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process=$cup_core_nums launch.py --enable-insecure-extension-access --api --api-log --log-startup --listen --port $WEBUI_PORT --xformers --no-half-vae --no-download-sd-model --no-hashing --nowebui --skip-torch-cuda-test --skip-load-model-at-start --disable-safe-unpickle --exit
|
|
|
|
|
|
|
|
|
|
remove_unused_list
|
|
|
|
|
|
|
|
|
|
check_ready &
|
|
|
|
|
|
|
|
|
|
echo "---------------------------------------------------------------------------------"
|
|
|
|
|
echo "accelerate launch..."
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process=6 launch.py --api --listen --port 7860 --xformers --no-half-vae --no-download-sd-model --no-hashing --nowebui --skip-torch-cuda-test --skip-load-model-at-start --disable-safe-unpickle
|
|
|
|
|
accelerate launch --num_cpu_threads_per_process=$cup_core_nums launch.py --enable-insecure-extension-access --api --api-log --log-startup --listen --port $WEBUI_PORT --xformers --no-half-vae --no-download-sd-model --no-hashing --nowebui --skip-torch-cuda-test --skip-load-model-at-start --disable-safe-unpickle --skip-prepare-environment --skip-python-version-check --skip-install --skip-version-check
|