Installer for WSL (#78)

This commit is contained in:
jllllll 2023-06-12 22:04:15 -05:00 committed by GitHub
parent 53496ffa80
commit c42f183d3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 200 additions and 3 deletions

74
INSTRUCTIONS-WSL.TXT Normal file
View File

@ -0,0 +1,74 @@
Thank you for downloading oobabooga/text-generation-webui.
# WSL setup
If you do not have WSL installed, see here:
https://learn.microsoft.com/en-us/windows/wsl/install
If you want to install Linux to a drive other than C
Open powershell and enter these commands:
cd D:\Path\To\Linux
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri <LinuxDistroURL> -OutFile Linux.appx -UseBasicParsing
mv Linux.appx Linux.zip
Then open Linux.zip and you should see several .appx files inside.
The one with _x64.appx contains the exe installer that you need.
Extract the contents of that _x64.appx file and run <distro>.exe to install.
Linux Distro URLs:
https://learn.microsoft.com/en-us/windows/wsl/install-manual#downloading-distributions
******************************************************************************
*ENSURE THAT THE WSL LINUX DISTRO THAT YOU WISH TO USE IS SET AS THE DEFAULT!*
******************************************************************************
Do this by using these commands:
wsl -l
wsl -s <DistroName>
# Web UI Installation
Run the "start" script. By default it will install the web UI in WSL:
/home/{username}/text-gen-install
To launch the web UI in the future after it is already installed, run
the same "start" script. Ensure that webui.py and wsl.sh are next to it!
# Updating the web UI
Run the "update" script. This will only install the updates, so it should
be much faster than the initial installation.
You can also run "wsl.sh update" in WSL.
# Adding flags like --chat, --notebook, etc
Edit the "webui.py" script using a text editor and add the desired flags
to the CMD_FLAGS variable at the top. It should look like this:
CMD_FLAGS = '--chat'
For instance, to add the --api flag, change it to
CMD_FLAGS = '--chat --api'
The "start" and "update" scripts will copy the edited "webui.py" to WSL
to be used by the web UI.
# Running an interactive shell
To run an interactive shell in the miniconda environment, run the "cmd"
script. This is useful for installing additional requirements manually.
You can also run "wsl.sh cmd" in WSL.
# Changing the default install location
To change this, you will need to edit the scripts as follows:
wsl.sh: line ~22 INSTALL_DIR="/path/to/install/dir"
Keep in mind that there is a long-standing bug in WSL that significantly
slows drive read/write speeds when using a physical drive as opposed to
the virtual one that Linux is installed in.

11
cmd_wsl.bat Normal file
View File

@ -0,0 +1,11 @@
@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
call wsl -e bash -lic "sed -i 's/\x0D$//' ./wsl.sh; source ./wsl.sh cmd"
:end
pause

View File

@ -1,5 +1,6 @@
mkdir oobabooga_{windows,linux,macos} mkdir oobabooga_{windows,linux,macos,wsl}
for p in windows macos linux; do for p in windows macos linux wsl; do
cp {*$p*\.*,webui.py,INSTRUCTIONS.TXT} oobabooga_$p; if [ "$p" == "wsl" ]; then cp {*$p*\.*,webui.py,INSTRUCTIONS-WSL.TXT} oobabooga_$p;
else cp {*$p*\.*,webui.py,INSTRUCTIONS.TXT} oobabooga_$p; fi
zip -r oobabooga_$p.zip oobabooga_$p; zip -r oobabooga_$p.zip oobabooga_$p;
done done

11
start_wsl.bat Normal file
View File

@ -0,0 +1,11 @@
@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
call wsl -e bash -lic "sed -i 's/\x0D$//' ./wsl.sh; source ./wsl.sh"
:end
pause

11
update_wsl.bat Normal file
View File

@ -0,0 +1,11 @@
@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 update"
:end
pause

89
wsl.sh Normal file
View File

@ -0,0 +1,89 @@
#!/bin/bash
# detect if build-essential is missing or broken
if ! dpkg-query -W -f'${Status}' "build-essential" 2>/dev/null | grep -q "ok installed"; then
echo "build-essential not found or broken!
A C++ compiler is required to build needed Python packages!
To install one, run cmd_wsl.bat and enter these commands:
sudo apt-get update
sudo apt-get install build-essential
"
read -n1 -p "Continue the installer anyway? [y,n]" EXIT_PROMPT
# only continue if user inputs 'y' else exit
if ! [[ $EXIT_PROMPT == "Y" || $EXIT_PROMPT == "y" ]]; then exit; fi
fi
# deactivate any currently active conda env
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"
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.1.0-1-Linux-x86_64.sh"
conda_exists="F"
# environment isolation
export PYTHONNOUSERSITE=1
unset PYTHONPATH
unset PYTHONHOME
export CUDA_PATH="$INSTALL_ENV_DIR"
export CUDA_HOME="$CUDA_PATH"
# /usr/lib/wsl/lib needs to be added to LD_LIBRARY_PATH to fix years-old bug in WSL where GPU drivers aren't linked properly
export LD_LIBRARY_PATH="$CUDA_HOME/lib:/usr/lib/wsl/lib:$LD_LIBRARY_PATH"
# open bash cli if called with 'wsl.sh cmd' with workarounds for existing conda
if [ "$1" == "cmd" ]; then
exec bash --init-file <(echo ". ~/.bashrc; conda deactivate 2> /dev/null; cd $INSTALL_DIR || cd $HOME; source $CONDA_ROOT_PREFIX/etc/profile.d/conda.sh; conda activate $INSTALL_ENV_DIR")
exit
fi
if [[ "$INSTALL_DIR" =~ " " ]]; then echo This script relies on Miniconda which can not be silently installed under a path with spaces. && exit; fi
# create install dir if missing and copy webui.py to install dir to maintain functionality without edit
if [ ! -d "$INSTALL_DIR" ]; then mkdir -p "$INSTALL_DIR" || exit; fi
cp -u "./webui.py" "$INSTALL_DIR"
# figure out whether git and conda needs to be installed
if "$CONDA_ROOT_PREFIX/bin/conda" --version &>/dev/null; then conda_exists="T"; fi
# (if necessary) install git and conda into a contained environment
# download miniconda
if [ "$conda_exists" == "F" ]; then
echo "Downloading Miniconda from $MINICONDA_DOWNLOAD_URL to $INSTALL_DIR/miniconda_installer.sh"
curl -Lk "$MINICONDA_DOWNLOAD_URL" > "$INSTALL_DIR/miniconda_installer.sh"
chmod u+x "$INSTALL_DIR/miniconda_installer.sh"
bash "$INSTALL_DIR/miniconda_installer.sh" -b -p $CONDA_ROOT_PREFIX
# test the conda binary
echo "Miniconda version:"
"$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
fi
# check if conda environment was actually created
if [ ! -e "$INSTALL_ENV_DIR/bin/python" ]; then
echo "Conda environment is empty."
exit
fi
# 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"
# setup installer env update env if called with 'wsl.sh update'
case "$1" in
("update") python webui.py --update;;
(*) python webui.py;;
esac