From 6bbfc40d10a7d2e671558a2f928285b6744c4a3c Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:51:58 -0500 Subject: [PATCH 1/6] Add .git creation to installer --- webui.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 8707e7f7..f30c59a0 100644 --- a/webui.py +++ b/webui.py @@ -117,7 +117,12 @@ def install_dependencies(): def update_dependencies(initial_installation=False): - # run_cmd("git pull", assert_success=True, environment=True) # TODO uncomment before merging (is there a better way?) + # Create .git directory if missing + if not os.path.isdir(os.path.join(script_dir, ".git")): + git_creation_cmd = 'git init -b main && git remote add origin https://github.com/oobabooga/text-generation-webui && git fetch && git remote set-head origin -a && git reset origin/HEAD && git branch --set-upstream-to=origin/HEAD' + run_cmd(git_creation_cmd, environment=True, assert_success=True) + + run_cmd("git pull", assert_success=True, environment=True) # TODO is there a better way? # Install the extensions dependencies (only on the first install) if initial_installation: From cd1049ededa4dc694c360b53801d12fdcaa0bb3d Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Thu, 21 Sep 2023 21:52:29 -0500 Subject: [PATCH 2/6] Add Conda env deactivation to installer scripts Avoids conflicts with existing Conda installations --- cmd_linux.sh | 3 +++ cmd_macos.sh | 4 ++-- cmd_windows.bat | 3 +++ start_linux.sh | 3 +++ start_macos.sh | 3 +++ start_windows.bat | 3 +++ update_linux.sh | 3 +++ update_macos.sh | 3 +++ update_windows.bat | 3 +++ wsl.sh | 4 ++-- 10 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmd_linux.sh b/cmd_linux.sh index 0a4ef620..1685050a 100755 --- a/cmd_linux.sh +++ b/cmd_linux.sh @@ -4,6 +4,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null + # config CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" diff --git a/cmd_macos.sh b/cmd_macos.sh index 0cec16e9..1b052e5c 100755 --- a/cmd_macos.sh +++ b/cmd_macos.sh @@ -4,8 +4,8 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi -# deactivate existing env if needed -conda deactivate 2> /dev/null +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null # config CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" diff --git a/cmd_windows.bat b/cmd_windows.bat index 606ff485..b219cf66 100755 --- a/cmd_windows.bat +++ b/cmd_windows.bat @@ -10,6 +10,9 @@ echo "%CD%"| findstr /C:" " >nul && echo This script relies on Miniconda which c set TMP=%cd%\installer_files set TEMP=%cd%\installer_files +@rem deactivate existing conda envs as needed to avoid conflicts +(conda deactivate && conda deactivate && conda deactivate) 2>null + @rem config set CONDA_ROOT_PREFIX=%cd%\installer_files\conda set INSTALL_ENV_DIR=%cd%\installer_files\env diff --git a/start_linux.sh b/start_linux.sh index dc37f612..1de8ccdf 100755 --- a/start_linux.sh +++ b/start_linux.sh @@ -4,6 +4,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null + OS_ARCH=$(uname -m) case "${OS_ARCH}" in x86_64*) OS_ARCH="x86_64";; diff --git a/start_macos.sh b/start_macos.sh index a813edb3..131a8af5 100755 --- a/start_macos.sh +++ b/start_macos.sh @@ -4,6 +4,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null + # M Series or Intel OS_ARCH=$(uname -m) case "${OS_ARCH}" in diff --git a/start_windows.bat b/start_windows.bat index 4f5b0ba5..3140f70f 100755 --- a/start_windows.bat +++ b/start_windows.bat @@ -17,6 +17,9 @@ set SPCHARMESSAGE= set TMP=%cd%\installer_files set TEMP=%cd%\installer_files +@rem deactivate existing conda envs as needed to avoid conflicts +(conda deactivate && conda deactivate && conda deactivate) 2>null + @rem config set INSTALL_DIR=%cd%\installer_files set CONDA_ROOT_PREFIX=%cd%\installer_files\conda diff --git a/update_linux.sh b/update_linux.sh index f7be8440..e641fafb 100755 --- a/update_linux.sh +++ b/update_linux.sh @@ -4,6 +4,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null + # config CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" diff --git a/update_macos.sh b/update_macos.sh index f7be8440..e641fafb 100755 --- a/update_macos.sh +++ b/update_macos.sh @@ -4,6 +4,9 @@ cd "$(dirname "${BASH_SOURCE[0]}")" if [[ "$(pwd)" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null + # config CONDA_ROOT_PREFIX="$(pwd)/installer_files/conda" INSTALL_ENV_DIR="$(pwd)/installer_files/env" diff --git a/update_windows.bat b/update_windows.bat index a44e2188..6f01ee03 100755 --- a/update_windows.bat +++ b/update_windows.bat @@ -10,6 +10,9 @@ echo "%CD%"| findstr /C:" " >nul && echo This script relies on Miniconda which c set TMP=%cd%\installer_files set TEMP=%cd%\installer_files +@rem deactivate existing conda envs as needed to avoid conflicts +(conda deactivate && conda deactivate && conda deactivate) 2>null + @rem config set CONDA_ROOT_PREFIX=%cd%\installer_files\conda set INSTALL_ENV_DIR=%cd%\installer_files\env diff --git a/wsl.sh b/wsl.sh index 50b8d77d..73a20a86 100755 --- a/wsl.sh +++ b/wsl.sh @@ -15,8 +15,8 @@ read -n1 -p "Continue the installer anyway? [y,n]" EXIT_PROMPT if ! [[ $EXIT_PROMPT == "Y" || $EXIT_PROMPT == "y" ]]; then exit; fi fi -# deactivate any currently active conda env -conda deactivate 2> /dev/null +# deactivate existing conda envs as needed to avoid conflicts +{ conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null # config unlike other scripts, can't use current directory due to file IO bug in WSL, needs to be in virtual drive INSTALL_DIR="$HOME/text-gen-install" From 498552a92bf9b40eaea0fdae028ce1c940a157cc Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Thu, 21 Sep 2023 22:12:16 -0500 Subject: [PATCH 3/6] More robust installation check for installer --- webui.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index f30c59a0..0fcdaabd 100644 --- a/webui.py +++ b/webui.py @@ -2,6 +2,7 @@ import argparse import glob import os import subprocess +import site import sys script_dir = os.getcwd() @@ -77,6 +78,16 @@ def clear_cache(): run_cmd("conda clean -a -y", environment=True) run_cmd("python -m pip cache purge", environment=True) +def is_installed(): + for sitedir in site.getsitepackages(): + if "site-packages" in sitedir and conda_env_path in sitedir: + site_packages_path = sitedir + break + + if site_packages_path: + return os.path.isfile(os.path.join(site_packages_path, 'torch', '__init__.py')) + else: + return os.path.isdir(conda_env_path) def install_dependencies(): # Select your GPU or, choose to run in CPU mode @@ -235,8 +246,7 @@ if __name__ == "__main__": update_dependencies() else: # If webui has already been installed, skip and run - # if not os.path.exists("text-generation-webui/"): - if True: # TODO implement a new installation check + if not is_installed(): install_dependencies() os.chdir(script_dir) From 9054c98ecac8c7b2d40c84262e92cfe6cd6a1e5a Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Thu, 21 Sep 2023 23:00:33 -0500 Subject: [PATCH 4/6] Use --autostash on git pull --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 0fcdaabd..19847879 100644 --- a/webui.py +++ b/webui.py @@ -133,7 +133,7 @@ def update_dependencies(initial_installation=False): git_creation_cmd = 'git init -b main && git remote add origin https://github.com/oobabooga/text-generation-webui && git fetch && git remote set-head origin -a && git reset origin/HEAD && git branch --set-upstream-to=origin/HEAD' run_cmd(git_creation_cmd, environment=True, assert_success=True) - run_cmd("git pull", assert_success=True, environment=True) # TODO is there a better way? + run_cmd("git pull --autostash", assert_success=True, environment=True) # TODO is there a better way? # Install the extensions dependencies (only on the first install) if initial_installation: From 060bb76aa077fc03c0278eb9b77005239f12be19 Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:10:30 -0500 Subject: [PATCH 5/6] Update WSL installer --- wsl.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/wsl.sh b/wsl.sh index 73a20a86..6660bc2e 100755 --- a/wsl.sh +++ b/wsl.sh @@ -19,7 +19,11 @@ fi { conda deactivate && conda deactivate && conda deactivate; } 2> /dev/null # config unlike other scripts, can't use current directory due to file IO bug in WSL, needs to be in virtual drive -INSTALL_DIR="$HOME/text-gen-install" +INSTALL_DIR_PREFIX="$HOME/text-gen-install" +if [[ ! $(realpath "$(pwd)/..") = /mnt/* ]]; then + INSTALL_DIR_PREFIX="$(realpath "$(pwd)/..")" && INSTALL_INPLACE=1 +fi +INSTALL_DIR="$INSTALL_DIR_PREFIX/text-generation-webui" CONDA_ROOT_PREFIX="$INSTALL_DIR/installer_files/conda" INSTALL_ENV_DIR="$INSTALL_DIR/installer_files/env" MINICONDA_DOWNLOAD_URL="https://repo.anaconda.com/miniconda/Miniconda3-py310_23.3.1-0-Linux-x86_64.sh" @@ -66,11 +70,9 @@ if [ "$conda_exists" == "F" ]; then "$CONDA_ROOT_PREFIX/bin/conda" --version fi -cd $INSTALL_DIR - # create the installer env if [ ! -e "$INSTALL_ENV_DIR" ]; then - "$CONDA_ROOT_PREFIX/bin/conda" create -y -k --prefix "$INSTALL_ENV_DIR" python=3.10 + "$CONDA_ROOT_PREFIX/bin/conda" create -y -k --prefix "$INSTALL_ENV_DIR" python=3.10 git fi # check if conda environment was actually created @@ -83,6 +85,24 @@ fi source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains about 'shell not initialized' (needed when running in a script) conda activate "$INSTALL_ENV_DIR" +# copy webui.py and CMD_FLAGS.txt to install dir to allow edits within Windows +if [[ $INSTALL_INPLACE != 1 ]]; then + cp -u "./webui.py" "$INSTALL_DIR" + if [ -f "./CMD_FLAGS.txt" ]; then cp -u "./CMD_FLAGS.txt" "$INSTALL_DIR"; fi +fi + +cd $INSTALL_DIR + +if [ ! -f "./server.py" ]; then + git init -b main + git remote add origin https://github.com/oobabooga/text-generation-webui + git fetch + git remote set-head origin -a + git reset origin/HEAD --hard + git branch --set-upstream-to=origin/HEAD + git restore -- . :!./webui.py :!./CMD_FLAGS.txt +fi + # setup installer env update env if called with 'wsl.sh update' case "$1" in ("update") python webui.py --update;; From 69b0aedd95d96cb0f1a0f7869e2b8a00df9aeaf8 Mon Sep 17 00:00:00 2001 From: jllllll <3887729+jllllll@users.noreply.github.com> Date: Fri, 22 Sep 2023 01:12:08 -0500 Subject: [PATCH 6/6] Fix missing models warning --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 19847879..d5071c80 100644 --- a/webui.py +++ b/webui.py @@ -251,7 +251,7 @@ if __name__ == "__main__": os.chdir(script_dir) # Check if a model has been downloaded yet - if len([item for item in glob.glob('text-generation-webui/models/*') if not item.endswith(('.txt', '.yaml'))]) == 0: + if len([item for item in glob.glob('models/*') if not item.endswith(('.txt', '.yaml'))]) == 0: print_big_message("WARNING: You haven't downloaded any model yet.\nOnce the web UI launches, head over to the \"Model\" tab and download one.") # Workaround for llama-cpp-python loading paths in CUDA env vars even if they do not exist