From 97dc3602fcdffdc5efc69e902ce008d2cc0cdef6 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:52:24 -0300 Subject: [PATCH] Create an update wizard (#5623) --- README.md | 4 +- extensions_reqs_linux.sh | 26 ------- extensions_reqs_macos.sh | 26 ------- extensions_reqs_windows.bat | 37 ---------- extensions_reqs_wsl.sh | 11 --- one_click.py | 72 +++++++++++++------ update_macos.sh => update_wizard_linux.sh | 2 +- update_linux.sh => update_wizard_macos.sh | 2 +- ...te_windows.bat => update_wizard_windows.sh | 2 +- update_wsl.bat => update_wizard_wsl.sh | 2 +- wsl.sh | 3 +- 11 files changed, 57 insertions(+), 130 deletions(-) delete mode 100755 extensions_reqs_linux.sh delete mode 100755 extensions_reqs_macos.sh delete mode 100755 extensions_reqs_windows.bat delete mode 100755 extensions_reqs_wsl.sh rename update_macos.sh => update_wizard_linux.sh (93%) rename update_linux.sh => update_wizard_macos.sh (93%) rename update_windows.bat => update_wizard_windows.sh (95%) rename update_wsl.bat => update_wizard_wsl.sh (93%) diff --git a/README.md b/README.md index 09216397..71a5c105 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ To restart the web UI in the future, just run the `start_` script again. This sc The script accepts command-line flags. Alternatively, you can edit the `CMD_FLAGS.txt` file with a text editor and add your flags there. -To get updates in the future, run `update_linux.sh`, `update_windows.bat`, `update_macos.sh`, or `update_wsl.bat`. +To get updates in the future, run `update_wizard_linux.sh`, `update_wizard_windows.bat`, `update_wizard_macos.sh`, or `update_wizard_wsl.bat`.
@@ -45,7 +45,7 @@ The script uses Miniconda to set up a Conda environment in the `installer_files` If you ever need to install something manually in the `installer_files` environment, you can launch an interactive shell using the cmd script: `cmd_linux.sh`, `cmd_windows.bat`, `cmd_macos.sh`, or `cmd_wsl.bat`. -* There is no need to run any of those scripts (`start_`, `update_`, or `cmd_`) as admin/root. +* There is no need to run any of those scripts (`start_`, `update_wizard_`, or `cmd_`) as admin/root. * To install the requirements for extensions, you can use the `extensions_reqs` script for your OS. At the end, this script will install the main requirements for the project to make sure that they take precedence in case of version conflicts. * For additional instructions about AMD and WSL setup, consult [the documentation](https://github.com/oobabooga/text-generation-webui/wiki). * For automated installation, you can use the `GPU_CHOICE`, `USE_CUDA118`, and `LAUNCH_AFTER_INSTALL` environment variables. For instance: `GPU_CHOICE=A USE_CUDA118=FALSE LAUNCH_AFTER_INSTALL=FALSE ./start_linux.sh`. diff --git a/extensions_reqs_linux.sh b/extensions_reqs_linux.sh deleted file mode 100755 index ea0c3773..00000000 --- a/extensions_reqs_linux.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -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" - -# environment isolation -export PYTHONNOUSERSITE=1 -unset PYTHONPATH -unset PYTHONHOME -export CUDA_PATH="$INSTALL_ENV_DIR" -export CUDA_HOME="$CUDA_PATH" - -# activate installer env -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" - -# update installer env -python one_click.py --install-extensions && echo -e "\nDone!" diff --git a/extensions_reqs_macos.sh b/extensions_reqs_macos.sh deleted file mode 100755 index ea0c3773..00000000 --- a/extensions_reqs_macos.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -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" - -# environment isolation -export PYTHONNOUSERSITE=1 -unset PYTHONPATH -unset PYTHONHOME -export CUDA_PATH="$INSTALL_ENV_DIR" -export CUDA_HOME="$CUDA_PATH" - -# activate installer env -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" - -# update installer env -python one_click.py --install-extensions && echo -e "\nDone!" diff --git a/extensions_reqs_windows.bat b/extensions_reqs_windows.bat deleted file mode 100755 index a3fb1f65..00000000 --- a/extensions_reqs_windows.bat +++ /dev/null @@ -1,37 +0,0 @@ -@echo off - -cd /D "%~dp0" - -set PATH=%PATH%;%SystemRoot%\system32 - -echo "%CD%"| findstr /C:" " >nul && echo This script relies on Miniconda which can not be silently installed under a path with spaces. && goto end - -@rem fix failed install when installing to a separate drive -set TMP=%cd%\installer_files -set TEMP=%cd%\installer_files - -@rem deactivate existing conda envs as needed to avoid conflicts -(call conda deactivate && call conda deactivate && call conda deactivate) 2>nul - -@rem config -set CONDA_ROOT_PREFIX=%cd%\installer_files\conda -set INSTALL_ENV_DIR=%cd%\installer_files\env - -@rem environment isolation -set PYTHONNOUSERSITE=1 -set PYTHONPATH= -set PYTHONHOME= -set "CUDA_PATH=%INSTALL_ENV_DIR%" -set "CUDA_HOME=%CUDA_PATH%" - -@rem activate installer env -call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end ) - -@rem update installer env -call python one_click.py --install-extensions && ( - echo. - echo Done! -) - -:end -pause diff --git a/extensions_reqs_wsl.sh b/extensions_reqs_wsl.sh deleted file mode 100755 index 450c8abb..00000000 --- a/extensions_reqs_wsl.sh +++ /dev/null @@ -1,11 +0,0 @@ -@echo off - -cd /D "%~dp0" - -set PATH=%PATH%;%SystemRoot%\system32 - -@rem sed -i 's/\x0D$//' ./wsl.sh converts newlines to unix format in the wsl script calling wsl.sh with 'update' will run updater -call wsl -e bash -lic "sed -i 's/\x0D$//' ./wsl.sh; source ./wsl.sh install-extensions" - -:end -pause diff --git a/one_click.py b/one_click.py index 67b01982..58f2296a 100644 --- a/one_click.py +++ b/one_click.py @@ -32,7 +32,7 @@ if os.path.exists(cmd_flags_path): else: CMD_FLAGS = '' -flags = f"{' '.join([flag for flag in sys.argv[1:] if flag != '--update'])} {CMD_FLAGS}" +flags = f"{' '.join([flag for flag in sys.argv[1:] if flag != '--update-wizard'])} {CMD_FLAGS}" def signal_handler(sig, frame): @@ -200,6 +200,24 @@ def run_cmd(cmd, assert_success=False, environment=False, capture_output=False, return result +def get_user_choice(question, options_dict): + print() + print(question) + print() + + for key, value in options_dict.items(): + print(f"{key}) {value}") + + print() + + choice = input("Input> ").upper() + while choice not in options_dict.keys(): + print("Invalid choice. Please try again.") + choice = input("Input> ").upper() + + return choice + + def install_webui(): # Ask the user for the GPU vendor @@ -207,20 +225,16 @@ def install_webui(): choice = os.environ["GPU_CHOICE"].upper() print_big_message(f"Selected GPU choice \"{choice}\" based on the GPU_CHOICE environment variable.") else: - print() - print("What is your GPU?") - print() - print("A) NVIDIA") - print("B) AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)") - print("C) Apple M Series") - print("D) Intel Arc (IPEX)") - print("N) None (I want to run models in CPU mode)") - print() - - choice = input("Input> ").upper() - while choice not in 'ABCDN': - print("Invalid choice. Please try again.") - choice = input("Input> ").upper() + choice = get_user_choice( + "What is your GPU?", + { + 'A': 'NVIDIA', + 'B': 'AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)', + 'C': 'Apple M Series', + 'D': 'Intel Arc (IPEX)', + 'N': 'None (I want to run models in CPU mode)' + }, + ) gpu_choice_to_name = { "A": "NVIDIA", @@ -395,15 +409,29 @@ if __name__ == "__main__": check_env() parser = argparse.ArgumentParser(add_help=False) - parser.add_argument('--update', action='store_true', help='Update the web UI.') - parser.add_argument('--install-extensions', action='store_true', help='Install extensions requirements.') + parser.add_argument('--update-wizard', action='store_true', help='Launch a menu with update options.') args, _ = parser.parse_known_args() - if args.update: - update_requirements() - elif args.install_extensions: - install_extensions_requirements() - update_requirements() + if args.update_wizard: + choice = get_user_choice( + "What would you like to do?", + { + 'A': 'Update the web UI', + 'B': 'Install/update extensions requirements', + 'C': 'Revert local changes to repository files with \"git reset --hard\"', + 'N': 'Nothing (exit).' + }, + ) + + if choice == 'A': + update_requirements() + elif choice == 'B': + install_extensions_requirements() + update_requirements() + elif choice == 'C': + run_cmd("git reset --hard", assert_success=True, environment=True) + elif choice == 'N': + sys.exit() else: if not is_installed(): install_webui() diff --git a/update_macos.sh b/update_wizard_linux.sh similarity index 93% rename from update_macos.sh rename to update_wizard_linux.sh index 371db554..c5add61e 100755 --- a/update_macos.sh +++ b/update_wizard_linux.sh @@ -23,4 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a conda activate "$INSTALL_ENV_DIR" # update installer env -python one_click.py --update && echo -e "\nDone!" +python one_click.py --update-wizard && echo -e "\nDone!" diff --git a/update_linux.sh b/update_wizard_macos.sh similarity index 93% rename from update_linux.sh rename to update_wizard_macos.sh index 371db554..c5add61e 100755 --- a/update_linux.sh +++ b/update_wizard_macos.sh @@ -23,4 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a conda activate "$INSTALL_ENV_DIR" # update installer env -python one_click.py --update && echo -e "\nDone!" +python one_click.py --update-wizard && echo -e "\nDone!" diff --git a/update_windows.bat b/update_wizard_windows.sh similarity index 95% rename from update_windows.bat rename to update_wizard_windows.sh index 0d8f8152..2b23f322 100755 --- a/update_windows.bat +++ b/update_wizard_windows.sh @@ -28,7 +28,7 @@ set "CUDA_HOME=%CUDA_PATH%" call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end ) @rem update installer env -call python one_click.py --update && ( +call python one_click.py --update-wizard && ( echo. echo Done! ) diff --git a/update_wsl.bat b/update_wizard_wsl.sh similarity index 93% rename from update_wsl.bat rename to update_wizard_wsl.sh index 36d019a8..35f0a349 100755 --- a/update_wsl.bat +++ b/update_wizard_wsl.sh @@ -5,7 +5,7 @@ cd /D "%~dp0" set PATH=%PATH%;%SystemRoot%\system32 @rem sed -i 's/\x0D$//' ./wsl.sh converts newlines to unix format in the wsl script calling wsl.sh with 'update' will run updater -call wsl -e bash -lic "sed -i 's/\x0D$//' ./wsl.sh; source ./wsl.sh update" +call wsl -e bash -lic "sed -i 's/\x0D$//' ./wsl.sh; source ./wsl.sh update-wizard" :end pause diff --git a/wsl.sh b/wsl.sh index 0b744455..7b17132f 100755 --- a/wsl.sh +++ b/wsl.sh @@ -110,7 +110,6 @@ fi # setup installer env update env if called with 'wsl.sh update' case "$1" in -("update") python one_click.py --update;; -("install-extensions") python one_click.py --install-extensions;; +("update-wizard") python one_click.py --update-wizard;; (*) python one_click.py $@;; esac