2021-11-27 03:44:08 +01:00
|
|
|
#!/bin/bash
|
2022-01-17 19:54:33 +01:00
|
|
|
# KoboldAI Easy Colab Deployment Script by Henk717
|
2021-11-27 03:44:08 +01:00
|
|
|
|
|
|
|
# read the options
|
2022-03-13 11:22:44 +01:00
|
|
|
TEMP=`getopt -o m:i:p:c:d:x:a:l:z:g:t:n:b:s: --long model:,init:,path:,configname:,download:,aria2:,dloc:xloc:7z:git:tar:ngrok:branch:savemodel: -- "$@"`
|
2021-11-27 03:44:08 +01:00
|
|
|
eval set -- "$TEMP"
|
|
|
|
|
|
|
|
# extract options and their arguments into variables.
|
|
|
|
while true ; do
|
|
|
|
case "$1" in
|
|
|
|
-m|--model)
|
|
|
|
model=" --model $2" ; shift 2 ;;
|
|
|
|
-i|--init)
|
|
|
|
init=$2 ; shift 2 ;;
|
|
|
|
-p|--path)
|
2022-01-11 14:16:57 +01:00
|
|
|
mpath="$2" ; shift 2 ;;
|
2021-11-27 03:44:08 +01:00
|
|
|
-c|--configname)
|
|
|
|
configname=" --configname $2" ; shift 2 ;;
|
2021-11-29 18:12:45 +01:00
|
|
|
-n|--ngrok)
|
|
|
|
configname=" --ngrok" ; shift 2 ;;
|
2021-11-27 03:44:08 +01:00
|
|
|
-d|--download)
|
|
|
|
download="$2" ; shift 2 ;;
|
|
|
|
-a|--aria2)
|
|
|
|
aria2="$2" ; shift 2 ;;
|
|
|
|
-l|--dloc)
|
|
|
|
dloc="$2" ; shift 2 ;;
|
2022-01-11 13:37:30 +01:00
|
|
|
-x|--xloc)
|
2022-01-11 14:32:53 +01:00
|
|
|
xloc="$2" ; shift 2 ;;
|
2021-11-27 03:44:08 +01:00
|
|
|
-z|--7z)
|
|
|
|
z7="$2" ; shift 2 ;;
|
|
|
|
-t|--tar)
|
|
|
|
tar="$2" ; shift 2 ;;
|
|
|
|
-g|--git)
|
|
|
|
git="$2" ; shift 2 ;;
|
2022-01-17 19:54:33 +01:00
|
|
|
-b|--branch)
|
|
|
|
branch="$2" ; shift 2 ;;
|
2022-03-13 11:22:44 +01:00
|
|
|
-s|--savemodel)
|
|
|
|
savemodel=" --savemodel" ; shift 2 ;;
|
2021-11-27 03:44:08 +01:00
|
|
|
--) shift ; break ;;
|
|
|
|
*) echo "Internal error!" ; exit 1 ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Create the Launch function so we can run KoboldAI at different places in the script
|
|
|
|
function launch
|
|
|
|
{
|
|
|
|
#End the script if "--init only" was specified.
|
|
|
|
if [ "$init" == "only" ]; then
|
|
|
|
echo Initialization complete...
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
cd /content/KoboldAI-Client
|
2022-03-13 11:22:44 +01:00
|
|
|
echo "Launching KoboldAI with the following options : python3 aiserver.py$model$kmpath$configname$ngrok$savemodel --colab"
|
|
|
|
python3 aiserver.py$model$kmpath$configname$ngrok$savemodel --colab
|
2021-11-27 03:44:08 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:54:33 +01:00
|
|
|
git_default_branch() {
|
|
|
|
(git remote show $git | grep 'HEAD branch' | cut -d' ' -f5) 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2021-11-27 03:44:08 +01:00
|
|
|
# Don't allow people to mess up their system
|
|
|
|
if [[ ! -d "/content" ]]; then
|
|
|
|
echo You can only use this script on Google Colab
|
|
|
|
echo Use aiserver.py to play KoboldAI locally.
|
|
|
|
echo Check our Readme for Colab links if you wish to play on Colab.
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Redefine the download location
|
|
|
|
if [ "$dloc" == "colab" ]; then
|
|
|
|
dloc="/content"
|
|
|
|
else
|
|
|
|
dloc="/content/drive/MyDrive/KoboldAI/models"
|
|
|
|
fi
|
|
|
|
|
2022-01-11 13:37:30 +01:00
|
|
|
# Redefine the extraction location
|
|
|
|
if [ "$xloc" == "drive" ]; then
|
|
|
|
xloc="/content/drive/MyDrive/KoboldAI/models/"
|
2022-01-11 15:04:31 +01:00
|
|
|
dloc="/content"
|
2022-01-11 13:37:30 +01:00
|
|
|
else
|
|
|
|
xloc="/content/"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Redefine the Path to be in the relevant location
|
2022-01-11 14:20:26 +01:00
|
|
|
if [[ -v mpath ]];then
|
2022-01-11 14:09:44 +01:00
|
|
|
mpath="$xloc$mpath"
|
2022-01-11 14:20:26 +01:00
|
|
|
kmpath=" --path $mpath"
|
2022-01-11 14:16:57 +01:00
|
|
|
fi
|
2022-01-11 13:37:30 +01:00
|
|
|
|
2022-01-20 11:17:01 +01:00
|
|
|
# Create folders on Google Drive
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/stories/
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/models/
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/settings/
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/softprompts/
|
|
|
|
mkdir /content/drive/MyDrive/KoboldAI/userscripts/
|
|
|
|
if [ "$init" == "drive" ]; then
|
|
|
|
echo Google Drive folders created.
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Install and/or Update KoboldAI
|
2021-11-27 03:44:08 +01:00
|
|
|
if [ "$init" != "skip" ]; then
|
|
|
|
cd /content
|
2021-12-05 18:36:54 +01:00
|
|
|
if [ ! -z ${git+x} ]; then
|
2022-01-17 05:22:29 +01:00
|
|
|
if [ "$git" == "Official" ]; then
|
2022-01-17 19:54:33 +01:00
|
|
|
git=https://github.com/koboldai/KoboldAI-Client
|
2022-01-17 05:16:03 +01:00
|
|
|
fi
|
|
|
|
if [ "$git" == "United" ]; then
|
2022-01-17 19:54:33 +01:00
|
|
|
git=https://github.com/henk717/KoboldAI-Client
|
2021-11-27 03:44:08 +01:00
|
|
|
fi
|
2022-01-17 05:22:29 +01:00
|
|
|
if [ "$git" == "united" ]; then
|
2022-01-17 19:54:33 +01:00
|
|
|
git=https://github.com/henk717/KoboldAI-Client
|
2022-01-17 05:22:29 +01:00
|
|
|
fi
|
2021-11-27 03:44:08 +01:00
|
|
|
else
|
2022-01-17 19:54:33 +01:00
|
|
|
git=https://github.com/koboldai/KoboldAI-Client
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir /content/KoboldAI-Client
|
|
|
|
cd /content/KoboldAI-Client
|
|
|
|
|
|
|
|
git init
|
|
|
|
git remote remove origin
|
|
|
|
git remote add origin $git
|
|
|
|
git fetch --all
|
|
|
|
|
|
|
|
if [ ! -z ${branch+x} ]; then
|
|
|
|
git checkout $branch -f
|
|
|
|
git reset --hard origin/$branch
|
|
|
|
else
|
|
|
|
git checkout $(git_default_branch) -f
|
|
|
|
git reset --hard origin/$(git_default_branch)
|
2021-11-27 03:44:08 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd /content/KoboldAI-Client
|
2022-01-01 19:45:32 +01:00
|
|
|
|
2022-02-22 02:35:27 +01:00
|
|
|
cp -rn stories/* /content/drive/MyDrive/KoboldAI/stories/
|
|
|
|
cp -rn userscripts/* /content/drive/MyDrive/KoboldAI/userscripts/
|
|
|
|
cp -rn softprompts/* /content/drive/MyDrive/KoboldAI/softprompts/
|
2021-11-27 03:44:08 +01:00
|
|
|
rm stories
|
|
|
|
rm -rf stories/
|
2022-01-01 19:45:32 +01:00
|
|
|
rm userscripts
|
|
|
|
rm -rf userscripts/
|
|
|
|
rm softprompts
|
|
|
|
rm -rf softprompts/
|
2022-02-22 02:35:27 +01:00
|
|
|
rm models
|
|
|
|
rm -rf models/
|
2021-11-27 03:44:08 +01:00
|
|
|
ln -s /content/drive/MyDrive/KoboldAI/stories/ stories
|
|
|
|
ln -s /content/drive/MyDrive/KoboldAI/settings/ settings
|
|
|
|
ln -s /content/drive/MyDrive/KoboldAI/softprompts/ softprompts
|
2021-12-14 02:51:39 +01:00
|
|
|
ln -s /content/drive/MyDrive/KoboldAI/userscripts/ userscripts
|
2022-02-22 02:35:27 +01:00
|
|
|
ln -s /content/drive/MyDrive/KoboldAI/models/ models
|
2021-11-27 03:44:08 +01:00
|
|
|
|
2022-03-05 19:47:51 +01:00
|
|
|
if [ -n "${COLAB_TPU_ADDR+set}" ]; then
|
2021-11-27 03:44:08 +01:00
|
|
|
pip install -r requirements_mtj.txt
|
|
|
|
else
|
|
|
|
pip install -r requirements.txt
|
|
|
|
fi
|
2021-12-14 04:02:33 +01:00
|
|
|
|
2022-01-17 19:54:33 +01:00
|
|
|
# Make sure Colab has netbase
|
|
|
|
sudo apt install netbase -y
|
2021-11-27 03:44:08 +01:00
|
|
|
fi
|
|
|
|
|
2021-12-10 21:34:41 +01:00
|
|
|
cd /content
|
|
|
|
|
2021-11-27 03:44:08 +01:00
|
|
|
# Models extracted? Then we skip anything beyond this point for faster loading.
|
|
|
|
if [ -f "/content/extracted" ]; then
|
|
|
|
launch
|
|
|
|
fi
|
|
|
|
|
2022-01-11 15:04:31 +01:00
|
|
|
# Is the model extracted on Google Drive? Skip the download and extraction
|
|
|
|
# Only on Google Drive since it has a big impact there if we don't, and locally we have better checks in place
|
2022-01-11 15:08:03 +01:00
|
|
|
if [ "$xloc" == "/content/drive/MyDrive/KoboldAI/models/" ] && [[ -d $mpath ]];then
|
2022-01-11 15:04:31 +01:00
|
|
|
launch
|
|
|
|
fi
|
|
|
|
|
2021-11-27 03:44:08 +01:00
|
|
|
#Download routine for regular Downloads
|
|
|
|
if [ ! -z ${download+x} ]; then
|
|
|
|
wget -c $download -P $dloc
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Download routine for Aria2c scripts
|
|
|
|
if [ ! -z ${aria2+x} ]; then
|
|
|
|
apt install aria2 -y
|
2022-01-17 06:12:53 +01:00
|
|
|
curl -L $aria2 | aria2c -c -i- -d$dloc --user-agent=KoboldAI --file-allocation=none
|
2021-11-27 03:44:08 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
#Extract the model with 7z
|
|
|
|
if [ ! -z ${z7+x} ]; then
|
2022-01-11 14:54:51 +01:00
|
|
|
7z x -o$xloc $dloc/$z7 -aos
|
2021-11-27 03:44:08 +01:00
|
|
|
touch /content/extracted
|
|
|
|
fi
|
|
|
|
|
|
|
|
#Extract the model in a ZSTD Tar file
|
|
|
|
if [ ! -z ${tar+x} ]; then
|
|
|
|
git clone https://github.com/VE-FORBRYDERNE/pv
|
|
|
|
cd pv
|
|
|
|
./configure
|
|
|
|
make
|
|
|
|
make install
|
|
|
|
cd ..
|
|
|
|
apt install zstd -y
|
2022-01-11 13:37:30 +01:00
|
|
|
pv $dloc/$tar | tar -I zstd -C $xloc -x
|
2021-11-27 03:44:08 +01:00
|
|
|
touch /content/extracted
|
|
|
|
fi
|
|
|
|
|
|
|
|
launch
|