Create an update wizard (#5623)

This commit is contained in:
oobabooga 2024-03-04 15:52:24 -03:00 committed by GitHub
parent 6adf222599
commit 97dc3602fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 57 additions and 130 deletions

View File

@ -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. 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`.
<details> <details>
<summary> <summary>
@ -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`. 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. * 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 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`. * 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`.

View File

@ -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!"

View File

@ -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!"

View File

@ -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

View File

@ -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

View File

@ -32,7 +32,7 @@ if os.path.exists(cmd_flags_path):
else: else:
CMD_FLAGS = '' 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): def signal_handler(sig, frame):
@ -200,6 +200,24 @@ def run_cmd(cmd, assert_success=False, environment=False, capture_output=False,
return result 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(): def install_webui():
# Ask the user for the GPU vendor # Ask the user for the GPU vendor
@ -207,20 +225,16 @@ def install_webui():
choice = os.environ["GPU_CHOICE"].upper() choice = os.environ["GPU_CHOICE"].upper()
print_big_message(f"Selected GPU choice \"{choice}\" based on the GPU_CHOICE environment variable.") print_big_message(f"Selected GPU choice \"{choice}\" based on the GPU_CHOICE environment variable.")
else: else:
print() choice = get_user_choice(
print("What is your GPU?") "What is your GPU?",
print() {
print("A) NVIDIA") 'A': 'NVIDIA',
print("B) AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)") 'B': 'AMD (Linux/MacOS only. Requires ROCm SDK 5.6 on Linux)',
print("C) Apple M Series") 'C': 'Apple M Series',
print("D) Intel Arc (IPEX)") 'D': 'Intel Arc (IPEX)',
print("N) None (I want to run models in CPU mode)") '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()
gpu_choice_to_name = { gpu_choice_to_name = {
"A": "NVIDIA", "A": "NVIDIA",
@ -395,15 +409,29 @@ if __name__ == "__main__":
check_env() check_env()
parser = argparse.ArgumentParser(add_help=False) parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--update', action='store_true', help='Update the web UI.') parser.add_argument('--update-wizard', action='store_true', help='Launch a menu with update options.')
parser.add_argument('--install-extensions', action='store_true', help='Install extensions requirements.')
args, _ = parser.parse_known_args() args, _ = parser.parse_known_args()
if args.update: if args.update_wizard:
update_requirements() choice = get_user_choice(
elif args.install_extensions: "What would you like to do?",
install_extensions_requirements() {
update_requirements() '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: else:
if not is_installed(): if not is_installed():
install_webui() install_webui()

View File

@ -23,4 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a
conda activate "$INSTALL_ENV_DIR" conda activate "$INSTALL_ENV_DIR"
# update installer env # update installer env
python one_click.py --update && echo -e "\nDone!" python one_click.py --update-wizard && echo -e "\nDone!"

View File

@ -23,4 +23,4 @@ source "$CONDA_ROOT_PREFIX/etc/profile.d/conda.sh" # otherwise conda complains a
conda activate "$INSTALL_ENV_DIR" conda activate "$INSTALL_ENV_DIR"
# update installer env # update installer env
python one_click.py --update && echo -e "\nDone!" python one_click.py --update-wizard && echo -e "\nDone!"

View File

@ -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 ) call "%CONDA_ROOT_PREFIX%\condabin\conda.bat" activate "%INSTALL_ENV_DIR%" || ( echo. && echo Miniconda hook not found. && goto end )
@rem update installer env @rem update installer env
call python one_click.py --update && ( call python one_click.py --update-wizard && (
echo. echo.
echo Done! echo Done!
) )

View File

@ -5,7 +5,7 @@ cd /D "%~dp0"
set PATH=%PATH%;%SystemRoot%\system32 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 @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 :end
pause pause

3
wsl.sh
View File

@ -110,7 +110,6 @@ fi
# setup installer env update env if called with 'wsl.sh update' # setup installer env update env if called with 'wsl.sh update'
case "$1" in case "$1" in
("update") python one_click.py --update;; ("update-wizard") python one_click.py --update-wizard;;
("install-extensions") python one_click.py --install-extensions;;
(*) python one_click.py $@;; (*) python one_click.py $@;;
esac esac