From 0a54bd3395e30bf7772ad6f11d69c5c437a1ab73 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Wed, 9 Nov 2022 11:15:17 -0600 Subject: [PATCH 1/2] Optional Accelerate Launch --- requirements.txt | 1 + requirements_versions.txt | 1 + webui-user.bat | 1 + webui-user.sh | 3 +++ webui.bat | 13 +++++++++++++ webui.sh | 16 ++++++++++++---- 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0fba0b23..762db4f3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +accelerate basicsr diffusers fairscale==0.4.4 diff --git a/requirements_versions.txt b/requirements_versions.txt index f7059f20..662ca684 100644 --- a/requirements_versions.txt +++ b/requirements_versions.txt @@ -1,5 +1,6 @@ transformers==4.19.2 diffusers==0.3.0 +accelerate==0.12.0 basicsr==1.4.2 gfpgan==1.3.8 gradio==3.9 diff --git a/webui-user.bat b/webui-user.bat index e5a257be..0c120111 100644 --- a/webui-user.bat +++ b/webui-user.bat @@ -4,5 +4,6 @@ set PYTHON= set GIT= set VENV_DIR= set COMMANDLINE_ARGS= +set ACCELERATE= call webui.bat diff --git a/webui-user.sh b/webui-user.sh index 30646f5c..16e42759 100644 --- a/webui-user.sh +++ b/webui-user.sh @@ -40,4 +40,7 @@ export COMMANDLINE_ARGS="" #export CODEFORMER_COMMIT_HASH="" #export BLIP_COMMIT_HASH="" +# Uncomment to enable accelerated launch +#export ACCELERATE="True" + ########################################### diff --git a/webui.bat b/webui.bat index a38a28bb..2a066d60 100644 --- a/webui.bat +++ b/webui.bat @@ -28,15 +28,28 @@ goto :show_stdout_stderr :activate_venv set PYTHON="%~dp0%VENV_DIR%\Scripts\Python.exe" echo venv %PYTHON% +if [%ACCELERATE%] == ["True"] goto :accelerate goto :launch :skip_venv +:accelerate +echo "Checking for accelerate" +dir %VENV_DIR%\Scripts\accelerate.exe >tmp/stdout.txt 2>tmp/stderr.txt +if %ERRORLEVEL% == 0 goto :accelerate_launch + :launch %PYTHON% launch.py %* pause exit /b +:accelerate_launch +echo "Accelerating2" +set ACCELERATE="%~dp0%VENV_DIR%\Scripts\accelerate.exe" +%ACCELERATE% launch --num_cpu_threads_per_process=6 launch.py +pause +exit /b + :show_stdout_stderr echo. diff --git a/webui.sh b/webui.sh index cc06f344..d89b344b 100755 --- a/webui.sh +++ b/webui.sh @@ -134,7 +134,15 @@ else exit 1 fi -printf "\n%s\n" "${delimiter}" -printf "Launching launch.py..." -printf "\n%s\n" "${delimiter}" -"${python_cmd}" "${LAUNCH_SCRIPT}" "$@" +if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ] +then + printf "\n%s\n" "${delimiter}" + printf "Accelerating launch.py..." + printf "\n%s\n" "${delimiter}" + accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@" +else + printf "\n%s\n" "${delimiter}" + printf "Launching launch.py..." + printf "\n%s\n" "${delimiter}" + "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" +fi From ac6fd2a5d91ca1ee36d721ef483b101597d3ee25 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Thu, 10 Nov 2022 09:39:43 -0600 Subject: [PATCH 2/2] Fix accelerate check when spaces in path --- webui.bat | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/webui.bat b/webui.bat index 2a066d60..d4d626e2 100644 --- a/webui.bat +++ b/webui.bat @@ -35,8 +35,8 @@ goto :launch :accelerate echo "Checking for accelerate" -dir %VENV_DIR%\Scripts\accelerate.exe >tmp/stdout.txt 2>tmp/stderr.txt -if %ERRORLEVEL% == 0 goto :accelerate_launch +set ACCELERATE="%~dp0%VENV_DIR%\Scripts\accelerate.exe" +if EXIST %ACCELERATE% goto :accelerate_launch :launch %PYTHON% launch.py %* @@ -44,8 +44,7 @@ pause exit /b :accelerate_launch -echo "Accelerating2" -set ACCELERATE="%~dp0%VENV_DIR%\Scripts\accelerate.exe" +echo "Accelerating" %ACCELERATE% launch --num_cpu_threads_per_process=6 launch.py pause exit /b