From 80bcfabc480979c58c0ec383df05dca7d56a5aa3 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 14 Apr 2023 17:32:27 +0530 Subject: [PATCH 01/35] Upgrade to PyTorch 2.0; Doesn't use a special repo url for pytorch on Linux --- scripts/check_modules.py | 18 ++++++++++++++---- scripts/on_sd_start.bat | 17 ++++++++++++----- scripts/on_sd_start.sh | 38 +++++++++++++++----------------------- 3 files changed, 41 insertions(+), 32 deletions(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 416ad851..991acee7 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -1,13 +1,23 @@ -''' +""" This script checks if the given modules exist -''' + +E.g. python check_modules.py sdkit==1.0.3 sdkit.models ldm transformers numpy antlr4 gfpgan realesrgan +""" import sys import pkgutil +from importlib.metadata import version modules = sys.argv[1:] missing_modules = [] for m in modules: - if pkgutil.find_loader(m) is None: - print('module', m, 'not found') + m = m.split("==") + module_name = m[0] + module_version = m[1] if len(m) > 1 else None + is_installed = pkgutil.find_loader(module_name) is not None + if not is_installed: + print("module", module_name, "not found") + exit(1) + elif module_version and version(module_name) != module_version: + print("module version is different! expected: ", module_version, ", actual: ", version(module_name)) exit(1) diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 7efd4577..0a890c21 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -7,6 +7,11 @@ @copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y @copy sd-ui-files\scripts\check_modules.py scripts\ /Y +set TORCH_VERSION=2.0.0+cu117 +set TORCHVISION_VERSION=0.15.1+cu117 +set SDKIT_VERSION=1.0.71 +set SD_VERSION=2.1.4 + if exist "%cd%\profile" ( set USERPROFILE=%cd%\profile ) @@ -65,7 +70,7 @@ if not exist "%INSTALL_ENV_DIR%\DLLs\libssl-1_1-x64.dll" copy "%INSTALL_ENV_D if not exist "%INSTALL_ENV_DIR%\DLLs\libcrypto-1_1-x64.dll" copy "%INSTALL_ENV_DIR%\Library\bin\libcrypto-1_1-x64.dll" "%INSTALL_ENV_DIR%\DLLs\" @rem install torch and torchvision -call python ..\scripts\check_modules.py torch torchvision +call python ..\scripts\check_modules.py torch==%TORCH_VERSION% torchvision==%TORCHVISION_VERSION% if "%ERRORLEVEL%" EQU "0" ( echo "torch and torchvision have already been installed." ) else ( @@ -75,13 +80,15 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 || ( + call python -m pip install --upgrade torch==%TORCH_VERSION% torchvision==%TORCHVISION_VERSION% --index-url https://download.pytorch.org/whl/cu117 || ( echo "Error installing torch. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" pause exit /b ) ) +call python -c "from importlib.metadata import version; print('torch version:', version('torch'))" + set PATH=C:\Windows\System32;%PATH% @rem install/upgrade sdkit @@ -95,7 +102,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install --upgrade sdkit==1.0.70 -q || ( + call python -m pip install --upgrade sdkit==%SDKIT_VERSION% -q || ( echo "Error updating sdkit" ) ) @@ -106,7 +113,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install sdkit==1.0.70 || ( + call python -m pip install sdkit==%SDKIT_VERSION% || ( echo "Error installing sdkit. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" pause exit /b @@ -116,7 +123,7 @@ if "%ERRORLEVEL%" EQU "0" ( call python -c "from importlib.metadata import version; print('sdkit version:', version('sdkit'))" @rem upgrade stable-diffusion-sdkit -call python -m pip install --upgrade stable-diffusion-sdkit==2.1.4 -q || ( +call python -m pip install --upgrade stable-diffusion-sdkit==%SD_VERSION% -q || ( echo "Error updating stable-diffusion-sdkit" ) call python -c "from importlib.metadata import version; print('stable-diffusion version:', version('stable-diffusion-sdkit'))" diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index fcf7dc53..6b62c468 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -7,6 +7,11 @@ cp sd-ui-files/scripts/check_modules.py scripts/ source ./scripts/functions.sh +TORCH_VERSION="2.0.0" +TORCHVISION_VERSION="0.15.1" +SDKIT_VERSION="1.0.71" +SD_VERSION="2.1.4" + # activate the installer env CONDA_BASEPATH=$(conda info --base) source "$CONDA_BASEPATH/etc/profile.d/conda.sh" # avoids the 'shell not initialized' error @@ -64,14 +69,7 @@ case "${OS_NAME}" in esac # install torch and torchvision -if python ../scripts/check_modules.py torch torchvision; then - # temp fix for installations that installed torch 2.0 by mistake - if [ "$OS_NAME" == "linux" ]; then - python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 -q - elif [ "$OS_NAME" == "macos" ]; then - python -m pip install --upgrade torch==1.13.1 torchvision==0.14.1 -q - fi - +if python ../scripts/check_modules.py torch==$TORCH_VERSION torchvision==$TORCHVISION_VERSION; then echo "torch and torchvision have already been installed." else echo "Installing torch and torchvision.." @@ -79,21 +77,15 @@ else export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - if [ "$OS_NAME" == "linux" ]; then - if python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 ; then - echo "Installed." - else - fail "torch install failed" - fi - elif [ "$OS_NAME" == "macos" ]; then - if python -m pip install --upgrade torch==1.13.1 torchvision==0.14.1 ; then - echo "Installed." - else - fail "torch install failed" - fi + if python -m pip install --upgrade torch==$TORCH_VERSION torchvision==$TORCHVISION_VERSION ; then + echo "Installed." + else + fail "torch install failed" fi fi +python -c "from importlib.metadata import version; print('torch version:', version('torch'))" + # install/upgrade sdkit if python ../scripts/check_modules.py sdkit sdkit.models ldm transformers numpy antlr4 gfpgan realesrgan ; then echo "sdkit is already installed." @@ -103,7 +95,7 @@ if python ../scripts/check_modules.py sdkit sdkit.models ldm transformers numpy export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - python -m pip install --upgrade sdkit==1.0.70 -q + python -m pip install --upgrade sdkit==$SDKIT_VERSION -q fi else echo "Installing sdkit: https://pypi.org/project/sdkit/" @@ -111,7 +103,7 @@ else export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - if python -m pip install sdkit==1.0.70 ; then + if python -m pip install sdkit==$SDKIT_VERSION ; then echo "Installed." else fail "sdkit install failed" @@ -121,7 +113,7 @@ fi python -c "from importlib.metadata import version; print('sdkit version:', version('sdkit'))" # upgrade stable-diffusion-sdkit -python -m pip install --upgrade stable-diffusion-sdkit==2.1.4 -q +python -m pip install --upgrade stable-diffusion-sdkit==$SD_VERSION -q python -c "from importlib.metadata import version; print('stable-diffusion version:', version('stable-diffusion-sdkit'))" # install rich From 1ba3a139d912d6806a02302adb20abae7ca35181 Mon Sep 17 00:00:00 2001 From: JeLuF Date: Sun, 16 Apr 2023 21:59:29 +0200 Subject: [PATCH 02/35] Don't save model_path if initial load fails Fixes #882 If the load of the model fails during the initialization, an attempt to render an image using the same model fails because ED doesn't notice that the model has to be loaded. This PR ensures that the model is being reloaded if the initial load fails. If the second load attempt fails as well, the user will get a more helpful error message than 'model not loaded yet'. --- ui/easydiffusion/model_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 296c4192..ca92d1ab 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -49,6 +49,7 @@ def load_default_models(context: Context): except Exception as e: log.error(f"[red]Error while loading {model_type} model: {context.model_paths[model_type]}[/red]") log.exception(e) + del context.model_paths[model_type] def unload_all(context: Context): for model_type in KNOWN_MODEL_TYPES: From 0c0525e11b6c025c3dcfc19b8bd692ce47536d9e Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 17 Apr 2023 15:43:08 +0530 Subject: [PATCH 03/35] sdkit 1.0.72 - use the extra attn precision yaml code for diffusers, which doesn't auto-detect black images yet --- scripts/on_sd_start.bat | 4 ++-- scripts/on_sd_start.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 7efd4577..a1d0836e 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -95,7 +95,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install --upgrade sdkit==1.0.70 -q || ( + call python -m pip install --upgrade sdkit==1.0.72 -q || ( echo "Error updating sdkit" ) ) @@ -106,7 +106,7 @@ if "%ERRORLEVEL%" EQU "0" ( set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - call python -m pip install sdkit==1.0.70 || ( + call python -m pip install sdkit==1.0.72 || ( echo "Error installing sdkit. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" pause exit /b diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index fcf7dc53..4907e7a5 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -103,7 +103,7 @@ if python ../scripts/check_modules.py sdkit sdkit.models ldm transformers numpy export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - python -m pip install --upgrade sdkit==1.0.70 -q + python -m pip install --upgrade sdkit==1.0.72 -q fi else echo "Installing sdkit: https://pypi.org/project/sdkit/" @@ -111,7 +111,7 @@ else export PYTHONNOUSERSITE=1 export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - if python -m pip install sdkit==1.0.70 ; then + if python -m pip install sdkit==1.0.72 ; then echo "Installed." else fail "sdkit install failed" From f2b5843e6ce65e4cc15aa5e08af507514d28827b Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 17 Apr 2023 15:50:51 +0530 Subject: [PATCH 04/35] merge beta --- scripts/on_sd_start.bat | 2 +- scripts/on_sd_start.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 0a890c21..424171fd 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -9,7 +9,7 @@ set TORCH_VERSION=2.0.0+cu117 set TORCHVISION_VERSION=0.15.1+cu117 -set SDKIT_VERSION=1.0.71 +set SDKIT_VERSION=1.0.72 set SD_VERSION=2.1.4 if exist "%cd%\profile" ( diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index 6b62c468..8dccb12b 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -9,7 +9,7 @@ source ./scripts/functions.sh TORCH_VERSION="2.0.0" TORCHVISION_VERSION="0.15.1" -SDKIT_VERSION="1.0.71" +SDKIT_VERSION="1.0.72" SD_VERSION="2.1.4" # activate the installer env From dc21cbe59d9769952be2867476982423c91f1157 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Mon, 17 Apr 2023 16:25:17 +0530 Subject: [PATCH 05/35] Typo --- scripts/on_sd_start.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index eb78b41d..f53f4210 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -3,9 +3,9 @@ @REM Caution, this file will make your eyes and brain bleed. It's such an unholy mess. @REM Note to self: Please rewrite this in Python. For the sake of your own sanity. -@REM @copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y -@REM @copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y -@REM @copy sd-ui-files\scripts\check_modules.py scripts\ /Y +@copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y +@copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y +@copy sd-ui-files\scripts\check_modules.py scripts\ /Y set TORCH_VERSION=2.0.0+cu117 set TORCHVISION_VERSION=0.15.1+cu117 From 44824fb5f938ff93cd2c507ba3c89ca0f3d4f7f8 Mon Sep 17 00:00:00 2001 From: JeLuF Date: Mon, 17 Apr 2023 23:22:44 +0200 Subject: [PATCH 06/35] Don't download 1.4 if other models are available --- scripts/on_sd_start.bat | 24 +++++++++++++----------- scripts/on_sd_start.sh | 7 +++++-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 7efd4577..728e0f82 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -186,22 +186,24 @@ call WHERE uvicorn > .tmp ) ) -@if not exist "..\models\stable-diffusion\sd-v1-4.ckpt" ( - @echo. & echo "Downloading data files (weights) for Stable Diffusion.." & echo. +@if not exist "..\models\stable-diffusion\*.ckpt" ( + @if not exist "..\models\stable-diffusion\*.safetensors" ( + @echo. & echo "Downloading data files (weights) for Stable Diffusion.." & echo. - @call curl -L -k https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > ..\models\stable-diffusion\sd-v1-4.ckpt + @call curl -L -k https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > ..\models\stable-diffusion\sd-v1-4.ckpt - @if exist "..\models\stable-diffusion\sd-v1-4.ckpt" ( - for %%I in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zI" NEQ "4265380512" ( - echo. & echo "Error: The downloaded model file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. + @if exist "..\models\stable-diffusion\sd-v1-4.ckpt" ( + for %%I in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zI" NEQ "4265380512" ( + echo. & echo "Error: The downloaded model file was invalid! Bytes downloaded: %%~zI" & echo. + echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. + pause + exit /b + ) + ) else ( + @echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. pause exit /b ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b ) ) diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index fcf7dc53..7582547b 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -170,8 +170,11 @@ if [ -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then fi fi -if [ ! -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then - echo "Downloading data files (weights) for Stable Diffusion.." + +if find "../models/stable-diffusion/" -name "*.ckpt" -or -name "*.safetensors" > /dev/null; then + echo "Found existing model file(s)." +else + echo "Downloading data files (weights) for Stable Diffusion..." curl -L -k https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > ../models/stable-diffusion/sd-v1-4.ckpt From 893b6d985cf5d00da06ff4f6805c4c175857d667 Mon Sep 17 00:00:00 2001 From: JeLuF Date: Tue, 18 Apr 2023 09:12:26 +0200 Subject: [PATCH 07/35] Add "Start scanning..." to getModels() Provide a hint to users what ED is currently using. Use case: User has built an infinite loop using symlinks, ED model scan will never finish. https://discord.com/channels/1014774730907209781/1097764777553580092 --- ui/easydiffusion/model_manager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/easydiffusion/model_manager.py b/ui/easydiffusion/model_manager.py index 296c4192..f32cfd9b 100644 --- a/ui/easydiffusion/model_manager.py +++ b/ui/easydiffusion/model_manager.py @@ -245,6 +245,7 @@ def getModels(): except MaliciousModelException as e: models["scan-error"] = e + log.info(f"[green]Scanning all model folders for models...[/]") # custom models listModels(model_type="stable-diffusion") listModels(model_type="vae") From e7dc41e2715c28f41928530cf6f9bb7ec91408f7 Mon Sep 17 00:00:00 2001 From: Diana <5275194+DianaNites@users.noreply.github.com> Date: Tue, 18 Apr 2023 02:32:39 -0700 Subject: [PATCH 08/35] Automatic AMD GPU detection on Linux (#1078) * Automatic AMD GPU detection on Linux Automatically detects AMD GPUs and installs the ROCm version of PyTorch instead of the cuda one A later improvement may be to detect the GPU ROCm version and handle GPUs that dont work on upstream ROCm, ether because they're too old and need a special patched version, or too new and need `HSA_OVERRIDE_GFX_VERSION=10.3.0` added, possibly check through `rocminfo`? * Address stdout suppression and download failure * If any NVIDIA GPU is found, always use it * Use /proc/bus/pci/devices to detect GPUs * Fix comparisons `-eq` and `-ne` only work for numbers * Add back -q --------- Co-authored-by: JeLuF --- scripts/on_sd_start.sh | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index 53f2c3b0..bc4b1608 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -63,11 +63,30 @@ case "${OS_NAME}" in *) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit esac +# Detect GPU types + +if grep -q amdgpu /proc/bus/pci/devices; then + echo AMD GPU detected + HAS_AMD=yes +fi + +if grep -q nvidia /proc/bus/pci/devices; then + echo NVidia GPU detected + HAS_NVIDIA=yes +fi + + + # install torch and torchvision if python ../scripts/check_modules.py torch torchvision; then # temp fix for installations that installed torch 2.0 by mistake if [ "$OS_NAME" == "linux" ]; then - python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 -q + # Check for AMD and NVIDIA dGPUs, always preferring an NVIDIA GPU if available + if [ "$HAS_NVIDIA" != "yes" -a "$HAS_AMD" = "yes" ]; then + python -m pip install --upgrade torch torchvision --extra-index-url "https://download.pytorch.org/whl/rocm5.4.2" -q || fail "Installation of torch and torchvision for AMD failed" + else + python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url "https://download.pytorch.org/whl/cu116" -q || fail "Installation of torch and torchvision for CUDA failed" + fi elif [ "$OS_NAME" == "macos" ]; then python -m pip install --upgrade torch==1.13.1 torchvision==0.14.1 -q fi @@ -80,11 +99,13 @@ else export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" if [ "$OS_NAME" == "linux" ]; then - if python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116 ; then - echo "Installed." + # Check for AMD and NVIDIA dGPUs, always preferring an NVIDIA GPU if available + if [ "$HAS_NVIDIA" != "yes" -a "$HAS_AMD" = "yes" ]; then + python -m pip install --upgrade torch torchvision --extra-index-url "https://download.pytorch.org/whl/rocm5.4.2" || fail "Installation of torch and torchvision for ROCm failed" else - fail "torch install failed" + python -m pip install --upgrade torch==1.13.1+cu116 torchvision==0.14.1+cu116 --extra-index-url "https://download.pytorch.org/whl/cu116" || fail "Installation of torch and torchvision for CUDA failed" fi + echo "Installed." elif [ "$OS_NAME" == "macos" ]; then if python -m pip install --upgrade torch==1.13.1 torchvision==0.14.1 ; then echo "Installed." @@ -151,7 +172,7 @@ else if conda install -c conda-forge -y uvicorn fastapi ; then echo "Installed. Testing.." else - fail "'conda install uvicorn' failed" + fail "'conda install uvicorn' failed" fi if ! command -v uvicorn &> /dev/null; then @@ -181,7 +202,7 @@ else if [ -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then model_size=`filesize "../models/stable-diffusion/sd-v1-4.ckpt"` if [ ! "$model_size" == "4265380512" ]; then - fail "The downloaded model file was invalid! Bytes downloaded: $model_size" + fail "The downloaded model file was invalid! Bytes downloaded: $model_size" fi else fail "Error downloading the data files (weights) for Stable Diffusion" From 80384e6ee1b370dd51324c2385c60d651c12b2e5 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 18 Apr 2023 15:42:33 +0530 Subject: [PATCH 09/35] Install PyTorch 2.0 by default, but allow existing PyTorch 1.13.1 installations to continue running; Unify and streamline the installation of dependencies --- scripts/check_modules.py | 126 +++++++++++++++++++++++++++++++++------ scripts/on_sd_start.bat | 103 +++----------------------------- scripts/on_sd_start.sh | 110 ++-------------------------------- 3 files changed, 120 insertions(+), 219 deletions(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 991acee7..7365000d 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -1,23 +1,111 @@ """ -This script checks if the given modules exist - -E.g. python check_modules.py sdkit==1.0.3 sdkit.models ldm transformers numpy antlr4 gfpgan realesrgan +This script checks and installs the required modules. """ -import sys -import pkgutil -from importlib.metadata import version +import os +from importlib.metadata import version as pkg_version +import platform -modules = sys.argv[1:] -missing_modules = [] -for m in modules: - m = m.split("==") - module_name = m[0] - module_version = m[1] if len(m) > 1 else None - is_installed = pkgutil.find_loader(module_name) is not None - if not is_installed: - print("module", module_name, "not found") - exit(1) - elif module_version and version(module_name) != module_version: - print("module version is different! expected: ", module_version, ", actual: ", version(module_name)) - exit(1) +os_name = platform.system() + +modules_to_check = { + "torch": ("1.13.1", "2.0.0"), + "torchvision": ("0.14.1", "0.15.1"), + "sdkit": "1.0.72", + "stable-diffusion-sdkit": "2.1.4", + "rich": "12.6.0", + "uvicorn": "0.19.0", + "fastapi": "0.85.1", +} + + +def version(module_name: str) -> str: + try: + return pkg_version(module_name) + except: + return None + + +def install(module_name: str, module_version: str): + index_url = None + if module_name in ("torch", "torchvision"): + module_version, index_url = apply_torch_install_overrides(module_version) + + install_cmd = f"python -m pip install --upgrade {module_name}=={module_version}" + if index_url: + install_cmd += f" --index-url {index_url}" + if module_name == "sdkit": + install_cmd += " -q" + + print(">", install_cmd) + os.system(install_cmd) + + +def init(): + for module_name, allowed_versions in modules_to_check.items(): + if os.path.exists(f"../src/{module_name}"): + print(f"Skipping {module_name} update, since it's in developer/editable mode") + continue + + allowed_versions, latest_version = get_allowed_versions(module_name, allowed_versions) + if version(module_name) not in allowed_versions: + try: + install(module_name, latest_version) + except: + fail(module_name) + + print(f"{module_name}: {version(module_name)}") + + +### utilities + + +def get_allowed_versions(module_name: str, allowed_versions: tuple[str]): + allowed_versions = (allowed_versions,) if isinstance(allowed_versions, str) else allowed_versions + latest_version = allowed_versions[-1] + + if module_name in ("torch", "torchvision"): + allowed_versions = include_cuda_versions(allowed_versions) + + return allowed_versions, latest_version + + +def apply_torch_install_overrides(module_version: str): + index_url = None + if os_name == "Windows": + module_version += "+cu117" + index_url = "https://download.pytorch.org/whl/cu117" + elif os_name == "Linux": + with open("/proc/bus/pci/devices", "r") as f: + device_info = f.read() + if "amdgpu" in device_info: + index_url = "https://download.pytorch.org/whl/rocm5.4.2" + + return module_version, index_url + + +def include_cuda_versions(module_versions: tuple) -> tuple: + "Adds CUDA-specific versions to the list of allowed version numbers" + + allowed_versions = tuple(module_versions) + allowed_versions += tuple(f"{v}+cu116" for v in module_versions) + allowed_versions += tuple(f"{v}+cu117" for v in module_versions) + + return allowed_versions + + +def fail(module_name): + print( + f"""Error installing {module_name}. Sorry about that, please try to: +1. Run this installer again. +2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting +3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB +4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues +Thanks!""" + ) + exit(1) + + +### start + +init() diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 52bf3330..0b74e9f0 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -7,12 +7,6 @@ @copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y @copy sd-ui-files\scripts\check_modules.py scripts\ /Y -set TORCH_VERSION=2.0.0+cu117 -set TORCHVISION_VERSION=0.15.1+cu117 -set TORCH_INDEX_URL=https://download.pytorch.org/whl/cu117 -set SDKIT_VERSION=1.0.72 -set SD_VERSION=2.1.4 - if exist "%cd%\profile" ( set USERPROFILE=%cd%\profile ) @@ -70,98 +64,17 @@ if exist "RealESRGAN_x4plus_anime_6B.pth" move RealESRGAN_x4plus_anime_6B.pth .. if not exist "%INSTALL_ENV_DIR%\DLLs\libssl-1_1-x64.dll" copy "%INSTALL_ENV_DIR%\Library\bin\libssl-1_1-x64.dll" "%INSTALL_ENV_DIR%\DLLs\" if not exist "%INSTALL_ENV_DIR%\DLLs\libcrypto-1_1-x64.dll" copy "%INSTALL_ENV_DIR%\Library\bin\libcrypto-1_1-x64.dll" "%INSTALL_ENV_DIR%\DLLs\" -@rem install torch and torchvision -call python ..\scripts\check_modules.py torch==%TORCH_VERSION% torchvision==%TORCHVISION_VERSION% -if "%ERRORLEVEL%" EQU "0" ( - echo "torch and torchvision have already been installed." -) else ( - echo "Installing torch and torchvision.." - - @REM prevent from using packages from the user's home directory, to avoid conflicts - set PYTHONNOUSERSITE=1 - set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - - call python -m pip install --upgrade torch==%TORCH_VERSION% torchvision==%TORCHVISION_VERSION% --index-url %TORCH_INDEX_URL% || ( - echo "Error installing torch. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" - pause - exit /b - ) -) - -call python -c "from importlib.metadata import version; print('torch version:', version('torch'))" - +@rem install or upgrade the required modules set PATH=C:\Windows\System32;%PATH% -@rem install/upgrade sdkit -call python ..\scripts\check_modules.py sdkit sdkit.models ldm transformers numpy antlr4 gfpgan realesrgan -if "%ERRORLEVEL%" EQU "0" ( - echo "sdkit is already installed." +@REM prevent from using packages from the user's home directory, to avoid conflicts +set PYTHONNOUSERSITE=1 +set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - @rem skip sdkit upgrade if in developer-mode - if not exist "..\src\sdkit" ( - @REM prevent from using packages from the user's home directory, to avoid conflicts - set PYTHONNOUSERSITE=1 - set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - - call python -m pip install --upgrade sdkit==%SDKIT_VERSION% -q || ( - echo "Error updating sdkit" - ) - ) -) else ( - echo "Installing sdkit: https://pypi.org/project/sdkit/" - - @REM prevent from using packages from the user's home directory, to avoid conflicts - set PYTHONNOUSERSITE=1 - set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - - call python -m pip install sdkit==%SDKIT_VERSION% || ( - echo "Error installing sdkit. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" - pause - exit /b - ) -) - -call python -c "from importlib.metadata import version; print('sdkit version:', version('sdkit'))" - -@rem upgrade stable-diffusion-sdkit -call python -m pip install --upgrade stable-diffusion-sdkit==%SD_VERSION% -q || ( - echo "Error updating stable-diffusion-sdkit" -) -call python -c "from importlib.metadata import version; print('stable-diffusion version:', version('stable-diffusion-sdkit'))" - -@rem install rich -call python ..\scripts\check_modules.py rich -if "%ERRORLEVEL%" EQU "0" ( - echo "rich has already been installed." -) else ( - echo "Installing rich.." - - set PYTHONNOUSERSITE=1 - set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - - call python -m pip install rich || ( - echo "Error installing rich. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" - pause - exit /b - ) -) - -set PATH=C:\Windows\System32;%PATH% - -call python ..\scripts\check_modules.py uvicorn fastapi -@if "%ERRORLEVEL%" EQU "0" ( - echo "Packages necessary for Easy Diffusion were already installed" -) else ( - @echo. & echo "Downloading packages necessary for Easy Diffusion..." & echo. - - set PYTHONNOUSERSITE=1 - set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages - - @call conda install -c conda-forge -y uvicorn fastapi || ( - echo "Error installing the packages necessary for Easy Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" - pause - exit /b - ) +call python ..\scripts\check_modules.py +if "%ERRORLEVEL%" NEQ "0" ( + pause + exit /b ) call WHERE uvicorn > .tmp diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index 275dfc1a..fbf96de0 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -7,11 +7,6 @@ cp sd-ui-files/scripts/check_modules.py scripts/ source ./scripts/functions.sh -TORCH_VERSION="2.0.0" -TORCHVISION_VERSION="0.15.1" -SDKIT_VERSION="1.0.72" -SD_VERSION="2.1.4" - # activate the installer env CONDA_BASEPATH=$(conda info --base) source "$CONDA_BASEPATH/etc/profile.d/conda.sh" # avoids the 'shell not initialized' error @@ -61,108 +56,13 @@ if [ -e "GFPGANv1.3.pth" ]; then mv GFPGANv1.3.pth ../models/gfpgan/; fi if [ -e "RealESRGAN_x4plus.pth" ]; then mv RealESRGAN_x4plus.pth ../models/realesrgan/; fi if [ -e "RealESRGAN_x4plus_anime_6B.pth" ]; then mv RealESRGAN_x4plus_anime_6B.pth ../models/realesrgan/; fi -OS_NAME=$(uname -s) -case "${OS_NAME}" in - Linux*) OS_NAME="linux";; - Darwin*) OS_NAME="macos";; - *) echo "Unknown OS: $OS_NAME! This script runs only on Linux or Mac" && exit -esac - -# Detect GPU types - -if grep -q amdgpu /proc/bus/pci/devices; then - echo AMD GPU detected - HAS_AMD=yes +if ! python ../scripts/check_modules.py; then + read -p "Press any key to continue" + exit 1 fi -if grep -q nvidia /proc/bus/pci/devices; then - echo NVidia GPU detected - HAS_NVIDIA=yes -fi - - - -# install torch and torchvision -if python ../scripts/check_modules.py torch==$TORCH_VERSION torchvision==$TORCHVISION_VERSION; then - echo "torch and torchvision have already been installed." -else - echo "Installing torch and torchvision.." - - export PYTHONNOUSERSITE=1 - export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - - if python -m pip install --upgrade torch==$TORCH_VERSION torchvision==$TORCHVISION_VERSION ; then - echo "Installed." - else - fail "torch install failed" - fi -fi - -python -c "from importlib.metadata import version; print('torch version:', version('torch'))" - -# install/upgrade sdkit -if python ../scripts/check_modules.py sdkit sdkit.models ldm transformers numpy antlr4 gfpgan realesrgan ; then - echo "sdkit is already installed." - - # skip sdkit upgrade if in developer-mode - if [ ! -e "../src/sdkit" ]; then - export PYTHONNOUSERSITE=1 - export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - - python -m pip install --upgrade sdkit==$SDKIT_VERSION -q - fi -else - echo "Installing sdkit: https://pypi.org/project/sdkit/" - - export PYTHONNOUSERSITE=1 - export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - - if python -m pip install sdkit==$SDKIT_VERSION ; then - echo "Installed." - else - fail "sdkit install failed" - fi -fi - -python -c "from importlib.metadata import version; print('sdkit version:', version('sdkit'))" - -# upgrade stable-diffusion-sdkit -python -m pip install --upgrade stable-diffusion-sdkit==$SD_VERSION -q -python -c "from importlib.metadata import version; print('stable-diffusion version:', version('stable-diffusion-sdkit'))" - -# install rich -if python ../scripts/check_modules.py rich; then - echo "rich has already been installed." -else - echo "Installing rich.." - - export PYTHONNOUSERSITE=1 - export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - - if python -m pip install rich ; then - echo "Installed." - else - fail "Install failed for rich" - fi -fi - -if python ../scripts/check_modules.py uvicorn fastapi ; then - echo "Packages necessary for Easy Diffusion were already installed" -else - printf "\n\nDownloading packages necessary for Easy Diffusion..\n\n" - - export PYTHONNOUSERSITE=1 - export PYTHONPATH="$INSTALL_ENV_DIR/lib/python3.8/site-packages" - - if conda install -c conda-forge -y uvicorn fastapi ; then - echo "Installed. Testing.." - else - fail "'conda install uvicorn' failed" - fi - - if ! command -v uvicorn &> /dev/null; then - fail "UI packages not found!" - fi +if ! command -v uvicorn &> /dev/null; then + fail "UI packages not found!" fi if [ -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then From d8d44c579ce3783fd7c0be5b557efc8c090992c2 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 18 Apr 2023 15:43:56 +0530 Subject: [PATCH 10/35] Typo --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 7365000d..60e12fa4 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -60,7 +60,7 @@ def init(): ### utilities -def get_allowed_versions(module_name: str, allowed_versions: tuple[str]): +def get_allowed_versions(module_name: str, allowed_versions: tuple): allowed_versions = (allowed_versions,) if isinstance(allowed_versions, str) else allowed_versions latest_version = allowed_versions[-1] From 30a133bad9206e6646db25292cdaa1629e299728 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 18 Apr 2023 16:10:46 +0530 Subject: [PATCH 11/35] Allow torch 1.11 to continue being installed --- scripts/check_modules.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 60e12fa4..2b47527f 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -1,5 +1,9 @@ """ This script checks and installs the required modules. + +TODO - Maybe replace the bulk of this script with a call to `pip install -f requirements.txt`, with +a custom index URL depending on the platform. + """ import os @@ -9,8 +13,8 @@ import platform os_name = platform.system() modules_to_check = { - "torch": ("1.13.1", "2.0.0"), - "torchvision": ("0.14.1", "0.15.1"), + "torch": ("1.11.0", "1.13.1", "2.0.0"), + "torchvision": ("0.12.0", "0.14.1", "0.15.1"), "sdkit": "1.0.72", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", From bf3df097b8763611101e588d053821af3f65d1bf Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 18 Apr 2023 17:14:24 +0530 Subject: [PATCH 12/35] Don't use ROCm on Linux if an NVIDIA card is present --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 2b47527f..0abf754e 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -82,7 +82,7 @@ def apply_torch_install_overrides(module_version: str): elif os_name == "Linux": with open("/proc/bus/pci/devices", "r") as f: device_info = f.read() - if "amdgpu" in device_info: + if "amdgpu" in device_info and "nvidia" not in device_info: index_url = "https://download.pytorch.org/whl/rocm5.4.2" return module_version, index_url From becbef4fac4da4c314333ac1aecb8f5482b125c9 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Tue, 18 Apr 2023 17:36:52 +0530 Subject: [PATCH 13/35] Include ROCm in the list of allowed versions --- scripts/check_modules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 0abf754e..fff51aa8 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -94,6 +94,7 @@ def include_cuda_versions(module_versions: tuple) -> tuple: allowed_versions = tuple(module_versions) allowed_versions += tuple(f"{v}+cu116" for v in module_versions) allowed_versions += tuple(f"{v}+cu117" for v in module_versions) + allowed_versions += tuple(f"{v}+rocm5.4.2" for v in module_versions) return allowed_versions From c1e8637a9fb16a213b7a1154e6c1eee079fed899 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:11:16 +0530 Subject: [PATCH 14/35] Re-implement the code for downloading models in python. Save some eyeballs from bleeding --- scripts/check_models.py | 99 ++++++++++++++++++++++ scripts/check_modules.py | 4 +- scripts/on_sd_start.bat | 173 ++------------------------------------- scripts/on_sd_start.sh | 157 ++--------------------------------- 4 files changed, 113 insertions(+), 320 deletions(-) create mode 100644 scripts/check_models.py diff --git a/scripts/check_models.py b/scripts/check_models.py new file mode 100644 index 00000000..16dc93b3 --- /dev/null +++ b/scripts/check_models.py @@ -0,0 +1,99 @@ +# this script runs inside the legacy "stable-diffusion" folder + +from sdkit.models import download_model, get_model_info_from_db +from sdkit.utils import hash_file_quick + +import os +import shutil +from glob import glob + +models_base_dir = os.path.abspath(os.path.join("..", "models")) + +models_to_check = { + "stable-diffusion": [ + {"file_name": "sd-v1-4.ckpt", "model_id": "1.4"}, + ], + "gfpgan": [ + {"file_name": "GFPGANv1.4.pth", "model_id": "1.4"}, + ], + "realesrgan": [ + {"file_name": "RealESRGAN_x4plus.pth", "model_id": "x4plus"}, + {"file_name": "RealESRGAN_x4plus_anime_6B.pth", "model_id": "x4plus_anime_6"}, + ], + "vae": [ + {"file_name": "vae-ft-mse-840000-ema-pruned.ckpt", "model_id": "vae-ft-mse-840000-ema-pruned"}, + ], +} +MODEL_EXTENSIONS = { # copied from easydiffusion/model_manager.py + "stable-diffusion": [".ckpt", ".safetensors"], + "vae": [".vae.pt", ".ckpt", ".safetensors"], + "hypernetwork": [".pt", ".safetensors"], + "gfpgan": [".pth"], + "realesrgan": [".pth"], + "lora": [".ckpt", ".safetensors"], +} + + +def download_if_necessary(model_type: str, file_name: str, model_id: str): + model_path = os.path.join(models_base_dir, model_type, file_name) + expected_hash = get_model_info_from_db(model_type=model_type, model_id=model_id)["quick_hash"] + + other_models_exist = any_model_exists(model_type) + known_model_exists = os.path.exists(model_path) + known_model_is_corrupt = known_model_exists and hash_file_quick(model_path) != expected_hash + + if known_model_is_corrupt or (not other_models_exist and not known_model_exists): + print("> download", model_type, model_id) + download_model(model_type, model_id, download_base_dir=models_base_dir) + + +def init(): + migrate_legacy_model_location() + + for model_type, models in models_to_check.items(): + for model in models: + try: + download_if_necessary(model_type, model["file_name"], model["model_id"]) + except: + fail(model_type) + + print(model_type, "model(s) found.") + + +### utilities +def any_model_exists(model_type: str) -> bool: + extensions = MODEL_EXTENSIONS.get(model_type, []) + for ext in extensions: + if any(glob(f"{models_base_dir}/{model_type}/**/*{ext}", recursive=True)): + return True + + return False + + +def migrate_legacy_model_location(): + 'Move the models inside the legacy "stable-diffusion" folder, to their respective folders' + + for model_type, models in models_to_check.items(): + for model in models: + file_name = model["file_name"] + if os.path.exists(file_name): + dest_dir = os.path.join(models_base_dir, model_type) + os.makedirs(dest_dir, exist_ok=True) + shutil.move(file_name, os.path.join(dest_dir, file_name)) + + +def fail(model_name): + print( + f"""Error downloading the {model_name} model. Sorry about that, please try to: +1. Run this installer again. +2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting +3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB +4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues +Thanks!""" + ) + exit(1) + + +### start + +init() diff --git a/scripts/check_modules.py b/scripts/check_modules.py index fff51aa8..ffbbd08b 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -1,6 +1,8 @@ """ This script checks and installs the required modules. +This script runs inside the legacy "stable-diffusion" folder + TODO - Maybe replace the bulk of this script with a call to `pip install -f requirements.txt`, with a custom index URL depending on the platform. @@ -15,7 +17,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.72", + "sdkit": "1.0.73", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 0b74e9f0..1edd18d6 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -49,17 +49,6 @@ if exist "env" ( if exist src rename src src-old if exist ldm rename ldm ldm-old -if not exist "..\models\stable-diffusion" mkdir "..\models\stable-diffusion" -if not exist "..\models\gfpgan" mkdir "..\models\gfpgan" -if not exist "..\models\realesrgan" mkdir "..\models\realesrgan" -if not exist "..\models\vae" mkdir "..\models\vae" - -@rem migrate the legacy models to the correct path (if already downloaded) -if exist "sd-v1-4.ckpt" move sd-v1-4.ckpt ..\models\stable-diffusion\ -if exist "custom-model.ckpt" move custom-model.ckpt ..\models\stable-diffusion\ -if exist "GFPGANv1.3.pth" move GFPGANv1.3.pth ..\models\gfpgan\ -if exist "RealESRGAN_x4plus.pth" move RealESRGAN_x4plus.pth ..\models\realesrgan\ -if exist "RealESRGAN_x4plus_anime_6B.pth" move RealESRGAN_x4plus_anime_6B.pth ..\models\realesrgan\ if not exist "%INSTALL_ENV_DIR%\DLLs\libssl-1_1-x64.dll" copy "%INSTALL_ENV_DIR%\Library\bin\libssl-1_1-x64.dll" "%INSTALL_ENV_DIR%\DLLs\" if not exist "%INSTALL_ENV_DIR%\DLLs\libcrypto-1_1-x64.dll" copy "%INSTALL_ENV_DIR%\Library\bin\libcrypto-1_1-x64.dll" "%INSTALL_ENV_DIR%\DLLs\" @@ -71,6 +60,7 @@ set PATH=C:\Windows\System32;%PATH% set PYTHONNOUSERSITE=1 set PYTHONPATH=%INSTALL_ENV_DIR%\lib\site-packages +@rem Download the required packages call python ..\scripts\check_modules.py if "%ERRORLEVEL%" NEQ "0" ( pause @@ -90,162 +80,11 @@ call WHERE uvicorn > .tmp @echo conda_sd_ui_deps_installed >> ..\scripts\install_status.txt ) -@if exist "..\models\stable-diffusion\sd-v1-4.ckpt" ( - for %%I in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zI" EQU "4265380512" ( - echo "Data files (weights) necessary for Stable Diffusion were already downloaded. Using the HuggingFace 4 GB Model." - ) else ( - for %%J in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zJ" EQU "7703807346" ( - echo "Data files (weights) necessary for Stable Diffusion were already downloaded. Using the HuggingFace 7 GB Model." - ) else ( - for %%K in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zK" EQU "7703810927" ( - echo "Data files (weights) necessary for Stable Diffusion were already downloaded. Using the Waifu Model." - ) else ( - echo. & echo "The model file present at models\stable-diffusion\sd-v1-4.ckpt is invalid. It is only %%~zK bytes in size. Re-downloading.." & echo. - del "..\models\stable-diffusion\sd-v1-4.ckpt" - ) - ) - ) -) - -@if not exist "..\models\stable-diffusion\*.ckpt" ( - @if not exist "..\models\stable-diffusion\*.safetensors" ( - @echo. & echo "Downloading data files (weights) for Stable Diffusion.." & echo. - - @call curl -L -k https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > ..\models\stable-diffusion\sd-v1-4.ckpt - - @if exist "..\models\stable-diffusion\sd-v1-4.ckpt" ( - for %%I in ("..\models\stable-diffusion\sd-v1-4.ckpt") do if "%%~zI" NEQ "4265380512" ( - echo. & echo "Error: The downloaded model file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for Stable Diffusion. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) -) - - - -@if exist "..\models\gfpgan\GFPGANv1.3.pth" ( - for %%I in ("..\models\gfpgan\GFPGANv1.3.pth") do if "%%~zI" EQU "348632874" ( - echo "Data files (weights) necessary for GFPGAN (Face Correction) were already downloaded" - ) else ( - echo. & echo "The GFPGAN model file present at models\gfpgan\GFPGANv1.3.pth is invalid. It is only %%~zI bytes in size. Re-downloading.." & echo. - del "..\models\gfpgan\GFPGANv1.3.pth" - ) -) - -@if not exist "..\models\gfpgan\GFPGANv1.3.pth" ( - @echo. & echo "Downloading data files (weights) for GFPGAN (Face Correction).." & echo. - - @call curl -L -k https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth > ..\models\gfpgan\GFPGANv1.3.pth - - @if exist "..\models\gfpgan\GFPGANv1.3.pth" ( - for %%I in ("..\models\gfpgan\GFPGANv1.3.pth") do if "%%~zI" NEQ "348632874" ( - echo. & echo "Error: The downloaded GFPGAN model file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for GFPGAN (Face Correction). Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for GFPGAN (Face Correction). Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) -) - - - -@if exist "..\models\realesrgan\RealESRGAN_x4plus.pth" ( - for %%I in ("..\models\realesrgan\RealESRGAN_x4plus.pth") do if "%%~zI" EQU "67040989" ( - echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus were already downloaded" - ) else ( - echo. & echo "The RealESRGAN model file present at models\realesrgan\RealESRGAN_x4plus.pth is invalid. It is only %%~zI bytes in size. Re-downloading.." & echo. - del "..\models\realesrgan\RealESRGAN_x4plus.pth" - ) -) - -@if not exist "..\models\realesrgan\RealESRGAN_x4plus.pth" ( - @echo. & echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus.." & echo. - - @call curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth > ..\models\realesrgan\RealESRGAN_x4plus.pth - - @if exist "..\models\realesrgan\RealESRGAN_x4plus.pth" ( - for %%I in ("..\models\realesrgan\RealESRGAN_x4plus.pth") do if "%%~zI" NEQ "67040989" ( - echo. & echo "Error: The downloaded ESRGAN x4plus model file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) -) - - - -@if exist "..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth" ( - for %%I in ("..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth") do if "%%~zI" EQU "17938799" ( - echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus_anime were already downloaded" - ) else ( - echo. & echo "The RealESRGAN model file present at models\realesrgan\RealESRGAN_x4plus_anime_6B.pth is invalid. It is only %%~zI bytes in size. Re-downloading.." & echo. - del "..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth" - ) -) - -@if not exist "..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth" ( - @echo. & echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime.." & echo. - - @call curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth > ..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth - - @if exist "..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth" ( - for %%I in ("..\models\realesrgan\RealESRGAN_x4plus_anime_6B.pth") do if "%%~zI" NEQ "17938799" ( - echo. & echo "Error: The downloaded ESRGAN x4plus_anime model file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime. Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) -) - - - -@if exist "..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt" ( - for %%I in ("..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt") do if "%%~zI" EQU "334695179" ( - echo "Data files (weights) necessary for the default VAE (sd-vae-ft-mse-original) were already downloaded" - ) else ( - echo. & echo "The default VAE (sd-vae-ft-mse-original) file present at models\vae\vae-ft-mse-840000-ema-pruned.ckpt is invalid. It is only %%~zI bytes in size. Re-downloading.." & echo. - del "..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt" - ) -) - -@if not exist "..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt" ( - @echo. & echo "Downloading data files (weights) for the default VAE (sd-vae-ft-mse-original).." & echo. - - @call curl -L -k https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt > ..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt - - @if exist "..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt" ( - for %%I in ("..\models\vae\vae-ft-mse-840000-ema-pruned.ckpt") do if "%%~zI" NEQ "334695179" ( - echo. & echo "Error: The downloaded default VAE (sd-vae-ft-mse-original) file was invalid! Bytes downloaded: %%~zI" & echo. - echo. & echo "Error downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) - ) else ( - @echo. & echo "Error downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:" & echo " 1. Run this installer again." & echo " 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting" & echo " 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB" & echo " 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues" & echo "Thanks!" & echo. - pause - exit /b - ) +@rem Download the required models +call python ..\scripts\check_models.py +if "%ERRORLEVEL%" NEQ "0" ( + pause + exit /b ) @>nul findstr /m "sd_install_complete" ..\scripts\install_status.txt diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index fbf96de0..51a03d18 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -44,18 +44,7 @@ fi if [ -e "src" ]; then mv src src-old; fi if [ -e "ldm" ]; then mv ldm ldm-old; fi -mkdir -p "../models/stable-diffusion" -mkdir -p "../models/gfpgan" -mkdir -p "../models/realesrgan" -mkdir -p "../models/vae" - -# migrate the legacy models to the correct path (if already downloaded) -if [ -e "sd-v1-4.ckpt" ]; then mv sd-v1-4.ckpt ../models/stable-diffusion/; fi -if [ -e "custom-model.ckpt" ]; then mv custom-model.ckpt ../models/stable-diffusion/; fi -if [ -e "GFPGANv1.3.pth" ]; then mv GFPGANv1.3.pth ../models/gfpgan/; fi -if [ -e "RealESRGAN_x4plus.pth" ]; then mv RealESRGAN_x4plus.pth ../models/realesrgan/; fi -if [ -e "RealESRGAN_x4plus_anime_6B.pth" ]; then mv RealESRGAN_x4plus_anime_6B.pth ../models/realesrgan/; fi - +# Download the required packages if ! python ../scripts/check_modules.py; then read -p "Press any key to continue" exit 1 @@ -65,146 +54,10 @@ if ! command -v uvicorn &> /dev/null; then fail "UI packages not found!" fi -if [ -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then - model_size=`filesize "../models/stable-diffusion/sd-v1-4.ckpt"` - - if [ "$model_size" -eq "4265380512" ] || [ "$model_size" -eq "7703807346" ] || [ "$model_size" -eq "7703810927" ]; then - echo "Data files (weights) necessary for Stable Diffusion were already downloaded" - else - printf "\n\nThe model file present at models/stable-diffusion/sd-v1-4.ckpt is invalid. It is only $model_size bytes in size. Re-downloading.." - rm ../models/stable-diffusion/sd-v1-4.ckpt - fi -fi - - -if find "../models/stable-diffusion/" -name "*.ckpt" -or -name "*.safetensors" > /dev/null; then - echo "Found existing model file(s)." -else - echo "Downloading data files (weights) for Stable Diffusion..." - - curl -L -k https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt > ../models/stable-diffusion/sd-v1-4.ckpt - - if [ -f "../models/stable-diffusion/sd-v1-4.ckpt" ]; then - model_size=`filesize "../models/stable-diffusion/sd-v1-4.ckpt"` - if [ ! "$model_size" == "4265380512" ]; then - fail "The downloaded model file was invalid! Bytes downloaded: $model_size" - fi - else - fail "Error downloading the data files (weights) for Stable Diffusion" - fi -fi - - -if [ -f "../models/gfpgan/GFPGANv1.3.pth" ]; then - model_size=`filesize "../models/gfpgan/GFPGANv1.3.pth"` - - if [ "$model_size" -eq "348632874" ]; then - echo "Data files (weights) necessary for GFPGAN (Face Correction) were already downloaded" - else - printf "\n\nThe model file present at models/gfpgan/GFPGANv1.3.pth is invalid. It is only $model_size bytes in size. Re-downloading.." - rm ../models/gfpgan/GFPGANv1.3.pth - fi -fi - -if [ ! -f "../models/gfpgan/GFPGANv1.3.pth" ]; then - echo "Downloading data files (weights) for GFPGAN (Face Correction).." - - curl -L -k https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth > ../models/gfpgan/GFPGANv1.3.pth - - if [ -f "../models/gfpgan/GFPGANv1.3.pth" ]; then - model_size=`filesize "../models/gfpgan/GFPGANv1.3.pth"` - if [ ! "$model_size" -eq "348632874" ]; then - fail "The downloaded GFPGAN model file was invalid! Bytes downloaded: $model_size" - fi - else - fail "Error downloading the data files (weights) for GFPGAN (Face Correction)." - fi -fi - - -if [ -f "../models/realesrgan/RealESRGAN_x4plus.pth" ]; then - model_size=`filesize "../models/realesrgan/RealESRGAN_x4plus.pth"` - - if [ "$model_size" -eq "67040989" ]; then - echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus were already downloaded" - else - printf "\n\nThe model file present at models/realesrgan/RealESRGAN_x4plus.pth is invalid. It is only $model_size bytes in size. Re-downloading.." - rm ../models/realesrgan/RealESRGAN_x4plus.pth - fi -fi - -if [ ! -f "../models/realesrgan/RealESRGAN_x4plus.pth" ]; then - echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus.." - - curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth > ../models/realesrgan/RealESRGAN_x4plus.pth - - if [ -f "../models/realesrgan/RealESRGAN_x4plus.pth" ]; then - model_size=`filesize "../models/realesrgan/RealESRGAN_x4plus.pth"` - if [ ! "$model_size" -eq "67040989" ]; then - fail "The downloaded ESRGAN x4plus model file was invalid! Bytes downloaded: $model_size" - fi - else - fail "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus" - fi -fi - - -if [ -f "../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth" ]; then - model_size=`filesize "../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth"` - - if [ "$model_size" -eq "17938799" ]; then - echo "Data files (weights) necessary for ESRGAN (Resolution Upscaling) x4plus_anime were already downloaded" - else - printf "\n\nThe model file present at models/realesrgan/RealESRGAN_x4plus_anime_6B.pth is invalid. It is only $model_size bytes in size. Re-downloading.." - rm ../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth - fi -fi - -if [ ! -f "../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth" ]; then - echo "Downloading data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime.." - - curl -L -k https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth > ../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth - - if [ -f "../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth" ]; then - model_size=`filesize "../models/realesrgan/RealESRGAN_x4plus_anime_6B.pth"` - if [ ! "$model_size" -eq "17938799" ]; then - fail "The downloaded ESRGAN x4plus_anime model file was invalid! Bytes downloaded: $model_size" - fi - else - fail "Error downloading the data files (weights) for ESRGAN (Resolution Upscaling) x4plus_anime." - fi -fi - - -if [ -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ]; then - model_size=`filesize "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt"` - - if [ "$model_size" -eq "334695179" ]; then - echo "Data files (weights) necessary for the default VAE (sd-vae-ft-mse-original) were already downloaded" - else - printf "\n\nThe model file present at models/vae/vae-ft-mse-840000-ema-pruned.ckpt is invalid. It is only $model_size bytes in size. Re-downloading.." - rm ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt - fi -fi - -if [ ! -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ]; then - echo "Downloading data files (weights) for the default VAE (sd-vae-ft-mse-original).." - - curl -L -k https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.ckpt > ../models/vae/vae-ft-mse-840000-ema-pruned.ckpt - - if [ -f "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt" ]; then - model_size=`filesize "../models/vae/vae-ft-mse-840000-ema-pruned.ckpt"` - if [ ! "$model_size" -eq "334695179" ]; then - printf "\n\nError: The downloaded default VAE (sd-vae-ft-mse-original) file was invalid! Bytes downloaded: $model_size\n\n" - printf "\n\nError downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:\n 1. Run this installer again.\n 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting\n 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB\n 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues\nThanks!\n\n" - read -p "Press any key to continue" - exit - fi - else - printf "\n\nError downloading the data files (weights) for the default VAE (sd-vae-ft-mse-original). Sorry about that, please try to:\n 1. Run this installer again.\n 2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting\n 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB\n 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues\nThanks!\n\n" - read -p "Press any key to continue" - exit - fi +# Download the required models +if ! python ../scripts/check_models.py; then + read -p "Press any key to continue" + exit 1 fi if [ `grep -c sd_install_complete ../scripts/install_status.txt` -gt "0" ]; then From 34ea49147c0ac50cc74c3ccabea39a63c9ba3a34 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:13:29 +0530 Subject: [PATCH 15/35] Update the check_models.py script during startup --- scripts/on_env_start.bat | 1 + scripts/on_env_start.sh | 1 + scripts/on_sd_start.bat | 1 + scripts/on_sd_start.sh | 1 + 4 files changed, 4 insertions(+) diff --git a/scripts/on_env_start.bat b/scripts/on_env_start.bat index 9b461b78..ee702bb5 100644 --- a/scripts/on_env_start.bat +++ b/scripts/on_env_start.bat @@ -57,6 +57,7 @@ if "%update_branch%"=="" ( @xcopy sd-ui-files\ui ui /s /i /Y /q @copy sd-ui-files\scripts\on_sd_start.bat scripts\ /Y @copy sd-ui-files\scripts\check_modules.py scripts\ /Y +@copy sd-ui-files\scripts\check_models.py scripts\ /Y @copy "sd-ui-files\scripts\Start Stable Diffusion UI.cmd" . /Y @copy "sd-ui-files\scripts\Developer Console.cmd" . /Y diff --git a/scripts/on_env_start.sh b/scripts/on_env_start.sh index 39d3939e..4e73ca4e 100755 --- a/scripts/on_env_start.sh +++ b/scripts/on_env_start.sh @@ -43,6 +43,7 @@ cp -Rf sd-ui-files/ui . cp sd-ui-files/scripts/on_sd_start.sh scripts/ cp sd-ui-files/scripts/bootstrap.sh scripts/ cp sd-ui-files/scripts/check_modules.py scripts/ +cp sd-ui-files/scripts/check_models.py scripts/ cp sd-ui-files/scripts/start.sh . cp sd-ui-files/scripts/developer_console.sh . cp sd-ui-files/scripts/functions.sh scripts/ diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index 1edd18d6..c01b0a41 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -6,6 +6,7 @@ @copy sd-ui-files\scripts\on_env_start.bat scripts\ /Y @copy sd-ui-files\scripts\bootstrap.bat scripts\ /Y @copy sd-ui-files\scripts\check_modules.py scripts\ /Y +@copy sd-ui-files\scripts\check_models.py scripts\ /Y if exist "%cd%\profile" ( set USERPROFILE=%cd%\profile diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index 51a03d18..accc3442 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -4,6 +4,7 @@ cp sd-ui-files/scripts/functions.sh scripts/ cp sd-ui-files/scripts/on_env_start.sh scripts/ cp sd-ui-files/scripts/bootstrap.sh scripts/ cp sd-ui-files/scripts/check_modules.py scripts/ +cp sd-ui-files/scripts/check_models.py scripts/ source ./scripts/functions.sh From 7c75a61700ae38777fdb35f30fe964f2f82c94eb Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:15:15 +0530 Subject: [PATCH 16/35] Typo --- scripts/check_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_models.py b/scripts/check_models.py index 16dc93b3..aeae27d9 100644 --- a/scripts/check_models.py +++ b/scripts/check_models.py @@ -57,7 +57,7 @@ def init(): except: fail(model_type) - print(model_type, "model(s) found.") + print(model_type, "model(s) found.") ### utilities From 35c75115de3b3635aa8b888dadbc588fe848651b Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:20:08 +0530 Subject: [PATCH 17/35] Log errors during module and model initialization --- scripts/check_models.py | 2 ++ scripts/check_modules.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/check_models.py b/scripts/check_models.py index aeae27d9..0513bdbf 100644 --- a/scripts/check_models.py +++ b/scripts/check_models.py @@ -6,6 +6,7 @@ from sdkit.utils import hash_file_quick import os import shutil from glob import glob +import traceback models_base_dir = os.path.abspath(os.path.join("..", "models")) @@ -55,6 +56,7 @@ def init(): try: download_if_necessary(model_type, model["file_name"], model["model_id"]) except: + traceback.print_exc() fail(model_type) print(model_type, "model(s) found.") diff --git a/scripts/check_modules.py b/scripts/check_modules.py index ffbbd08b..b457ba8a 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -11,6 +11,7 @@ a custom index URL depending on the platform. import os from importlib.metadata import version as pkg_version import platform +import traceback os_name = platform.system() @@ -58,6 +59,7 @@ def init(): try: install(module_name, latest_version) except: + traceback.print_exc() fail(module_name) print(f"{module_name}: {version(module_name)}") From 83c34ea52ff3fdc994f84699fa364b88b2ee6d04 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:31:04 +0530 Subject: [PATCH 18/35] Remove unnecessary hotfix --- scripts/on_sd_start.bat | 2 - scripts/on_sd_start.sh | 5 - ...55dfd25693f1a71f3c6871b184042d4b126244e142 | 171 ------------------ 3 files changed, 178 deletions(-) delete mode 100644 ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142 diff --git a/scripts/on_sd_start.bat b/scripts/on_sd_start.bat index c01b0a41..e0b8c5fb 100644 --- a/scripts/on_sd_start.bat +++ b/scripts/on_sd_start.bat @@ -35,8 +35,6 @@ call conda activate @REM remove the old version of the dev console script, if it's still present if exist "Open Developer Console.cmd" del "Open Developer Console.cmd" -@REM @call python -c "import os; import shutil; frm = 'sd-ui-files\\ui\\hotfix\\9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'; dst = os.path.join(os.path.expanduser('~'), '.cache', 'huggingface', 'transformers', '9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'); shutil.copyfile(frm, dst) if os.path.exists(dst) else print(''); print('Hotfixed broken JSON file from OpenAI');" - @rem create the stable-diffusion folder, to work with legacy installations if not exist "stable-diffusion" mkdir stable-diffusion cd stable-diffusion diff --git a/scripts/on_sd_start.sh b/scripts/on_sd_start.sh index accc3442..858fa768 100755 --- a/scripts/on_sd_start.sh +++ b/scripts/on_sd_start.sh @@ -19,11 +19,6 @@ if [ -e "open_dev_console.sh" ]; then rm "open_dev_console.sh" fi -# python -c "import os; import shutil; frm = 'sd-ui-files/ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'; dst = os.path.join(os.path.expanduser('~'), '.cache', 'huggingface', 'transformers', '9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142'); shutil.copyfile(frm, dst) if os.path.exists(dst) else print(''); print('Hotfixed broken JSON file from OpenAI');" - -# Caution, this file will make your eyes and brain bleed. It's such an unholy mess. -# Note to self: Please rewrite this in Python. For the sake of your own sanity. - # set the correct installer path (current vs legacy) if [ -e "installer_files/env" ]; then export INSTALL_ENV_DIR="$(pwd)/installer_files/env" diff --git a/ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142 b/ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142 deleted file mode 100644 index 2c19f666..00000000 --- a/ui/hotfix/9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142 +++ /dev/null @@ -1,171 +0,0 @@ -{ - "_name_or_path": "clip-vit-large-patch14/", - "architectures": [ - "CLIPModel" - ], - "initializer_factor": 1.0, - "logit_scale_init_value": 2.6592, - "model_type": "clip", - "projection_dim": 768, - "text_config": { - "_name_or_path": "", - "add_cross_attention": false, - "architectures": null, - "attention_dropout": 0.0, - "bad_words_ids": null, - "bos_token_id": 0, - "chunk_size_feed_forward": 0, - "cross_attention_hidden_size": null, - "decoder_start_token_id": null, - "diversity_penalty": 0.0, - "do_sample": false, - "dropout": 0.0, - "early_stopping": false, - "encoder_no_repeat_ngram_size": 0, - "eos_token_id": 2, - "finetuning_task": null, - "forced_bos_token_id": null, - "forced_eos_token_id": null, - "hidden_act": "quick_gelu", - "hidden_size": 768, - "id2label": { - "0": "LABEL_0", - "1": "LABEL_1" - }, - "initializer_factor": 1.0, - "initializer_range": 0.02, - "intermediate_size": 3072, - "is_decoder": false, - "is_encoder_decoder": false, - "label2id": { - "LABEL_0": 0, - "LABEL_1": 1 - }, - "layer_norm_eps": 1e-05, - "length_penalty": 1.0, - "max_length": 20, - "max_position_embeddings": 77, - "min_length": 0, - "model_type": "clip_text_model", - "no_repeat_ngram_size": 0, - "num_attention_heads": 12, - "num_beam_groups": 1, - "num_beams": 1, - "num_hidden_layers": 12, - "num_return_sequences": 1, - "output_attentions": false, - "output_hidden_states": false, - "output_scores": false, - "pad_token_id": 1, - "prefix": null, - "problem_type": null, - "projection_dim" : 768, - "pruned_heads": {}, - "remove_invalid_values": false, - "repetition_penalty": 1.0, - "return_dict": true, - "return_dict_in_generate": false, - "sep_token_id": null, - "task_specific_params": null, - "temperature": 1.0, - "tie_encoder_decoder": false, - "tie_word_embeddings": true, - "tokenizer_class": null, - "top_k": 50, - "top_p": 1.0, - "torch_dtype": null, - "torchscript": false, - "transformers_version": "4.16.0.dev0", - "use_bfloat16": false, - "vocab_size": 49408 - }, - "text_config_dict": { - "hidden_size": 768, - "intermediate_size": 3072, - "num_attention_heads": 12, - "num_hidden_layers": 12, - "projection_dim": 768 - }, - "torch_dtype": "float32", - "transformers_version": null, - "vision_config": { - "_name_or_path": "", - "add_cross_attention": false, - "architectures": null, - "attention_dropout": 0.0, - "bad_words_ids": null, - "bos_token_id": null, - "chunk_size_feed_forward": 0, - "cross_attention_hidden_size": null, - "decoder_start_token_id": null, - "diversity_penalty": 0.0, - "do_sample": false, - "dropout": 0.0, - "early_stopping": false, - "encoder_no_repeat_ngram_size": 0, - "eos_token_id": null, - "finetuning_task": null, - "forced_bos_token_id": null, - "forced_eos_token_id": null, - "hidden_act": "quick_gelu", - "hidden_size": 1024, - "id2label": { - "0": "LABEL_0", - "1": "LABEL_1" - }, - "image_size": 224, - "initializer_factor": 1.0, - "initializer_range": 0.02, - "intermediate_size": 4096, - "is_decoder": false, - "is_encoder_decoder": false, - "label2id": { - "LABEL_0": 0, - "LABEL_1": 1 - }, - "layer_norm_eps": 1e-05, - "length_penalty": 1.0, - "max_length": 20, - "min_length": 0, - "model_type": "clip_vision_model", - "no_repeat_ngram_size": 0, - "num_attention_heads": 16, - "num_beam_groups": 1, - "num_beams": 1, - "num_hidden_layers": 24, - "num_return_sequences": 1, - "output_attentions": false, - "output_hidden_states": false, - "output_scores": false, - "pad_token_id": null, - "patch_size": 14, - "prefix": null, - "problem_type": null, - "projection_dim" : 768, - "pruned_heads": {}, - "remove_invalid_values": false, - "repetition_penalty": 1.0, - "return_dict": true, - "return_dict_in_generate": false, - "sep_token_id": null, - "task_specific_params": null, - "temperature": 1.0, - "tie_encoder_decoder": false, - "tie_word_embeddings": true, - "tokenizer_class": null, - "top_k": 50, - "top_p": 1.0, - "torch_dtype": null, - "torchscript": false, - "transformers_version": "4.16.0.dev0", - "use_bfloat16": false - }, - "vision_config_dict": { - "hidden_size": 1024, - "intermediate_size": 4096, - "num_attention_heads": 16, - "num_hidden_layers": 24, - "patch_size": 14, - "projection_dim": 768 - } -} From cb527919a2f785039b29295c38256887feb28a22 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:45:28 +0530 Subject: [PATCH 19/35] sdkit 1.0.75 - upgrade to diffusers 0.15.1 --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index b457ba8a..91d24caa 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.73", + "sdkit": "1.0.75", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", From fcbcb7d471bf988d6be6935f23eed9b5aaa33b95 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 19 Apr 2023 16:46:34 +0530 Subject: [PATCH 20/35] changelog --- CHANGES.md | 1 + ui/index.html | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f858700e..7e61b5aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed. ### Detailed changelog +* 2.5.32 - 19 Apr 2023 - Automatically check for black images, and set full-precision if necessary (for attn). This means custom models based on Stable Diffusion v2.1 will just work, without needing special command-line arguments or editing of yaml config files. * 2.5.31 - 10 Apr 2023 - Reduce VRAM usage while upscaling. * 2.5.31 - 6 Apr 2023 - Allow seeds upto `4,294,967,295`. Thanks @ogmaresca. * 2.5.31 - 6 Apr 2023 - Buttons to show the previous/next image in the image popup. Thanks @ogmaresca. diff --git a/ui/index.html b/ui/index.html index 7e8680d0..2e89aaf4 100644 --- a/ui/index.html +++ b/ui/index.html @@ -30,7 +30,7 @@

Easy Diffusion - v2.5.31 + v2.5.32

From 6287bcd00a2747df7fddb6327ed9ef344c5c4263 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:17:27 +0530 Subject: [PATCH 21/35] sdkit 1.0.76 - use 256 as the tile size for realesrgan, instead of 128. slightly more VRAM, but faster upscaling --- scripts/check_modules.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 91d24caa..85f64976 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.75", + "sdkit": "1.0.76", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", @@ -34,6 +34,9 @@ def version(module_name: str) -> str: def install(module_name: str, module_version: str): + if module_name == "xformers" and os_name == "Darwin": # xformers is not available on mac + return + index_url = None if module_name in ("torch", "torchvision"): module_version, index_url = apply_torch_install_overrides(module_version) From d0f4476ba589f6e9bc9e94478558b15a15db0640 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:22:42 +0530 Subject: [PATCH 22/35] Suggest downloading a model downloading in the troubleshooting steps. Thanks JeLuf --- scripts/check_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_models.py b/scripts/check_models.py index 0513bdbf..4b8d68c6 100644 --- a/scripts/check_models.py +++ b/scripts/check_models.py @@ -88,7 +88,7 @@ def fail(model_name): print( f"""Error downloading the {model_name} model. Sorry about that, please try to: 1. Run this installer again. -2. If that doesn't fix it, please try the common troubleshooting steps at https://github.com/cmdr2/stable-diffusion-ui/wiki/Troubleshooting +2. If that doesn't fix it, please try to download the file manually. The address to download from, and the destination to save to are printed above this message. 3. If those steps don't help, please copy *all* the error messages in this window, and ask the community at https://discord.com/invite/u9yhsFmEkB 4. If that doesn't solve the problem, please file an issue at https://github.com/cmdr2/stable-diffusion-ui/issues Thanks!""" From 534bb2dd842b11ba8b731bf9871ba924cdda8cb7 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:44:06 +0530 Subject: [PATCH 23/35] Use xformers 0.0.16 to speed up image generation --- scripts/check_modules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 85f64976..042086a1 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -23,6 +23,7 @@ modules_to_check = { "rich": "12.6.0", "uvicorn": "0.19.0", "fastapi": "0.85.1", + "xformers": "0.0.16", } From 6c148f1791b39d678a502724077200eef85664d1 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:48:38 +0530 Subject: [PATCH 24/35] Don't install xformers for AMD on Linux; changelog --- CHANGES.md | 1 + scripts/check_modules.py | 19 +++++++++++++------ ui/index.html | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7e61b5aa..ed648dd4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed. ### Detailed changelog +* 2.5.33 - 20 Apr 2023 - Use `xformers` to speed up image generation. * 2.5.32 - 19 Apr 2023 - Automatically check for black images, and set full-precision if necessary (for attn). This means custom models based on Stable Diffusion v2.1 will just work, without needing special command-line arguments or editing of yaml config files. * 2.5.31 - 10 Apr 2023 - Reduce VRAM usage while upscaling. * 2.5.31 - 6 Apr 2023 - Allow seeds upto `4,294,967,295`. Thanks @ogmaresca. diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 042086a1..80d198e2 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -35,7 +35,7 @@ def version(module_name: str) -> str: def install(module_name: str, module_version: str): - if module_name == "xformers" and os_name == "Darwin": # xformers is not available on mac + if module_name == "xformers" and (os_name == "Darwin" or is_amd_on_linux()): return index_url = None @@ -87,11 +87,8 @@ def apply_torch_install_overrides(module_version: str): if os_name == "Windows": module_version += "+cu117" index_url = "https://download.pytorch.org/whl/cu117" - elif os_name == "Linux": - with open("/proc/bus/pci/devices", "r") as f: - device_info = f.read() - if "amdgpu" in device_info and "nvidia" not in device_info: - index_url = "https://download.pytorch.org/whl/rocm5.4.2" + elif is_amd_on_linux(): + index_url = "https://download.pytorch.org/whl/rocm5.4.2" return module_version, index_url @@ -107,6 +104,16 @@ def include_cuda_versions(module_versions: tuple) -> tuple: return allowed_versions +def is_amd_on_linux(): + if os_name == "Linux": + with open("/proc/bus/pci/devices", "r") as f: + device_info = f.read() + if "amdgpu" in device_info and "nvidia" not in device_info: + return True + + return False + + def fail(module_name): print( f"""Error installing {module_name}. Sorry about that, please try to: diff --git a/ui/index.html b/ui/index.html index 2e89aaf4..404d88af 100644 --- a/ui/index.html +++ b/ui/index.html @@ -30,7 +30,7 @@

Easy Diffusion - v2.5.32 + v2.5.33

From bc142c9ecd676713350bc26fd5dae485d0150cd1 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:55:34 +0530 Subject: [PATCH 25/35] Fetch release notes only from the main or beta branches --- ui/plugins/ui/release-notes.plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/plugins/ui/release-notes.plugin.js b/ui/plugins/ui/release-notes.plugin.js index da7b79de..5a462008 100644 --- a/ui/plugins/ui/release-notes.plugin.js +++ b/ui/plugins/ui/release-notes.plugin.js @@ -51,9 +51,9 @@ } appConfig = await appConfig.json() - const updateBranch = appConfig.update_branch || 'main' + const notesBranch = (appConfig.update_branch !== "beta" ? "main" : "beta") - let releaseNotes = await fetch(`https://raw.githubusercontent.com/cmdr2/stable-diffusion-ui/${updateBranch}/CHANGES.md`) + let releaseNotes = await fetch(`https://raw.githubusercontent.com/cmdr2/stable-diffusion-ui/${notesBranch}/CHANGES.md`) if (!releaseNotes.ok) { console.error('[release-notes] Failed to get CHANGES.md.') return From cde57109e4674ffbe4f60c99d863be27d99179be Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 16:57:52 +0530 Subject: [PATCH 26/35] Revert "Fetch release notes only from the main or beta branches" This reverts commit bc142c9ecd676713350bc26fd5dae485d0150cd1. --- ui/plugins/ui/release-notes.plugin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/plugins/ui/release-notes.plugin.js b/ui/plugins/ui/release-notes.plugin.js index 5a462008..da7b79de 100644 --- a/ui/plugins/ui/release-notes.plugin.js +++ b/ui/plugins/ui/release-notes.plugin.js @@ -51,9 +51,9 @@ } appConfig = await appConfig.json() - const notesBranch = (appConfig.update_branch !== "beta" ? "main" : "beta") + const updateBranch = appConfig.update_branch || 'main' - let releaseNotes = await fetch(`https://raw.githubusercontent.com/cmdr2/stable-diffusion-ui/${notesBranch}/CHANGES.md`) + let releaseNotes = await fetch(`https://raw.githubusercontent.com/cmdr2/stable-diffusion-ui/${updateBranch}/CHANGES.md`) if (!releaseNotes.ok) { console.error('[release-notes] Failed to get CHANGES.md.') return From 76e379d7e17a98ad1e3730a68e91202c37d6fcdc Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 17:07:10 +0530 Subject: [PATCH 27/35] Don't install xformers, it downgrades the torch version. Still need to fix this --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 80d198e2..83208b28 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -23,7 +23,7 @@ modules_to_check = { "rich": "12.6.0", "uvicorn": "0.19.0", "fastapi": "0.85.1", - "xformers": "0.0.16", + # "xformers": "0.0.16", } From 670410b539568240f3d816937ca6b7d0a63dcf1f Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 17:42:12 +0530 Subject: [PATCH 28/35] sdkit 1.0.77 - fix inpainting bug on diffusers --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 83208b28..f1f22d32 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.76", + "sdkit": "1.0.77", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", From 023b78d1c9411ac93863aeaee0f94c47a28d18e1 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 17:46:34 +0530 Subject: [PATCH 29/35] Allow rocm5.2 --- scripts/check_modules.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index f1f22d32..89297d69 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -99,6 +99,7 @@ def include_cuda_versions(module_versions: tuple) -> tuple: allowed_versions = tuple(module_versions) allowed_versions += tuple(f"{v}+cu116" for v in module_versions) allowed_versions += tuple(f"{v}+cu117" for v in module_versions) + allowed_versions += tuple(f"{v}+rocm5.2" for v in module_versions) allowed_versions += tuple(f"{v}+rocm5.4.2" for v in module_versions) return allowed_versions From 526fc989c1ffd54f9c44080c34cd491d466f9031 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Thu, 20 Apr 2023 18:40:45 +0530 Subject: [PATCH 30/35] Allow any version of torch/torchvision --- scripts/check_modules.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 89297d69..7b3eb458 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -59,7 +59,15 @@ def init(): continue allowed_versions, latest_version = get_allowed_versions(module_name, allowed_versions) - if version(module_name) not in allowed_versions: + + requires_install = False + if module_name in ("torch", "torchvision"): + if version(module_name) is None: # allow any torch version + requires_install = True + elif version(module_name) not in allowed_versions: + requires_install = True + + if requires_install: try: install(module_name, latest_version) except: From 09215736443ffe22c3b2413be40b8daa0791f450 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 21 Apr 2023 15:11:26 +0530 Subject: [PATCH 31/35] sdkit 1.0.78 - fix the 'astype' error with the new diffusers version --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 7b3eb458..32692f50 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.77", + "sdkit": "1.0.78", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", From e1b6cc2a862d8bc1cbed5021fa93cdd1eb6c6a77 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 21 Apr 2023 15:13:29 +0530 Subject: [PATCH 32/35] typo --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 32692f50..891109c3 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.78", + "sdkit": "1.0.79", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", From fea77e97a0b49fa7062ad4c3d223b3d59e6ca00c Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 21 Apr 2023 15:26:14 +0530 Subject: [PATCH 33/35] actually fix the img2img error in the new diffusers version --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 891109c3..13ead165 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -18,7 +18,7 @@ os_name = platform.system() modules_to_check = { "torch": ("1.11.0", "1.13.1", "2.0.0"), "torchvision": ("0.12.0", "0.14.1", "0.15.1"), - "sdkit": "1.0.79", + "sdkit": "1.0.80", "stable-diffusion-sdkit": "2.1.4", "rich": "12.6.0", "uvicorn": "0.19.0", From 2e84a421f3e324dc891cb6b65a8126a3f251aeff Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 21 Apr 2023 15:49:38 +0530 Subject: [PATCH 34/35] Show sdkit installation progress during the first run --- scripts/check_modules.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_modules.py b/scripts/check_modules.py index 13ead165..775724b8 100644 --- a/scripts/check_modules.py +++ b/scripts/check_modules.py @@ -45,7 +45,7 @@ def install(module_name: str, module_version: str): install_cmd = f"python -m pip install --upgrade {module_name}=={module_version}" if index_url: install_cmd += f" --index-url {index_url}" - if module_name == "sdkit": + if module_name == "sdkit" and version("sdkit") is not None: install_cmd += " -q" print(">", install_cmd) From 0b19adba751f077ec469789ec8f8c91ee0a87258 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Fri, 21 Apr 2023 16:01:24 +0530 Subject: [PATCH 35/35] changelog --- CHANGES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index ed648dd4..7e61b5aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,7 +21,6 @@ Our focus continues to remain on an easy installation experience, and an easy user-interface. While still remaining pretty powerful, in terms of features and speed. ### Detailed changelog -* 2.5.33 - 20 Apr 2023 - Use `xformers` to speed up image generation. * 2.5.32 - 19 Apr 2023 - Automatically check for black images, and set full-precision if necessary (for attn). This means custom models based on Stable Diffusion v2.1 will just work, without needing special command-line arguments or editing of yaml config files. * 2.5.31 - 10 Apr 2023 - Reduce VRAM usage while upscaling. * 2.5.31 - 6 Apr 2023 - Allow seeds upto `4,294,967,295`. Thanks @ogmaresca.