Skip to content

Commit

Permalink
update launch script
Browse files Browse the repository at this point in the history
  • Loading branch information
ddPn08 committed Apr 29, 2023
1 parent 2fd2451 commit e70c4f8
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 40 deletions.
1 change: 0 additions & 1 deletion launch-user.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
set PYTHON=
set GIT=
set VENV_DIR=
set UVICORN_ARGS=--port 8000
set COMMANDLINE_ARGS=

call launch.bat
9 changes: 0 additions & 9 deletions launch-user.sh

This file was deleted.

19 changes: 2 additions & 17 deletions launch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ echo Couldn't install pip
goto :show_stdout_stderr

:start_venv
if ["%VENV_DIR%"] == ["-"] goto :skip_venv
if ["%SKIP_VENV%"] == ["1"] goto :skip_venv
if ["%VENV_DIR%"] == ["-"] goto :launch
if ["%SKIP_VENV%"] == ["1"] goto :launch

dir "%VENV_DIR%\Scripts\Python.exe" >tmp/stdout.txt 2>tmp/stderr.txt
if %ERRORLEVEL% == 0 goto :activate_venv
Expand All @@ -40,26 +40,11 @@ goto :show_stdout_stderr
set PYTHON="%VENV_DIR%\Scripts\Python.exe"
echo venv %PYTHON%

:skip_venv
if [%ACCELERATE%] == ["True"] goto :accelerate
goto :launch

:accelerate
echo Checking for accelerate
set ACCELERATE="%VENV_DIR%\Scripts\accelerate.exe"
if EXIST %ACCELERATE% goto :accelerate_launch

:launch
%PYTHON% launch.py %*
pause
exit /b

:accelerate_launch
echo Accelerating
%ACCELERATE% launch --num_cpu_threads_per_process=6 launch.py
pause
exit /b

:show_stdout_stderr

echo.
Expand Down
93 changes: 80 additions & 13 deletions launch.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
#!/usr/bin/env bash
#################################################
# Please do not make any changes to this file, #
# change the variables in webui-user.sh instead #
#################################################

# If run from macOS, load defaults from webui-macos-env.sh
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ -f webui-macos-env.sh ]]
then
source ./macos-env.sh
fi
fi

# Read variables from webui-user.sh
# shellcheck source=/dev/null
if [[ -f webui-user.sh ]]
then
source ./user-env.sh
fi

# python3 executable
if [[ -z "${python_cmd}" ]]
then
Expand All @@ -10,7 +31,7 @@ then
export GIT="git"
fi

# python3 venv without trailing slash
# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
if [[ -z "${venv_dir}" ]]
then
venv_dir="venv"
Expand All @@ -23,8 +44,62 @@ fi

# this script cannot be run as root by default
can_run_as_root=0

# read any command line flags to the webui.sh script
while getopts "f" flag > /dev/null 2>&1
do
case ${flag} in
f) can_run_as_root=1;;
*) break;;
esac
done

# Disable sentry logging
export ERROR_REPORTING=FALSE

# Do not reinstall existing pip packages on Debian/Ubuntu
export PIP_IGNORE_INSTALLED=0

# Pretty print
delimiter="################################################################"

# Do not run as root
if [[ $(id -u) -eq 0 && can_run_as_root -eq 0 ]]
then
printf "\n%s\n" "${delimiter}"
printf "\e[1m\e[31mERROR: This script must not be launched as root, aborting...\e[0m"
printf "\n%s\n" "${delimiter}"
exit 1
else
printf "\n%s\n" "${delimiter}"
printf "Running on \e[1m\e[32m%s\e[0m user" "$(whoami)"
printf "\n%s\n" "${delimiter}"
fi

if echo "$gpu_info" | grep -q "AMD" && [[ -z "${TORCH_COMMAND}" ]]
then
export TORCH_COMMAND="pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/rocm5.2"
fi

for preq in "${GIT}" "${python_cmd}"
do
if ! hash "${preq}" &>/dev/null
then
printf "\n%s\n" "${delimiter}"
printf "\e[1m\e[31mERROR: %s is not installed, aborting...\e[0m" "${preq}"
printf "\n%s\n" "${delimiter}"
exit 1
fi
done

if ! "${python_cmd}" -c "import venv" &>/dev/null
then
printf "\n%s\n" "${delimiter}"
printf "\e[1m\e[31mERROR: python3-venv is not installed, aborting...\e[0m"
printf "\n%s\n" "${delimiter}"
exit 1
fi

printf "\n%s\n" "${delimiter}"
printf "Create and activate python venv"
printf "\n%s\n" "${delimiter}"
Expand All @@ -44,15 +119,7 @@ else
exit 1
fi

if [[ ! -z "${ACCELERATE}" ]] && [ ${ACCELERATE}="True" ] && [ -x "$(command -v accelerate)" ]
then
printf "\n%s\n" "${delimiter}"
printf "Accelerating launch.py..."
printf "\n%s\n" "${delimiter}"
exec accelerate launch --num_cpu_threads_per_process=6 "${LAUNCH_SCRIPT}" "$@"
else
printf "\n%s\n" "${delimiter}"
printf "Launching launch.py..."
printf "\n%s\n" "${delimiter}"
exec "${python_cmd}" -u "${LAUNCH_SCRIPT}" "$@"
fi
printf "\n%s\n" "${delimiter}"
printf "Launching launch.py..."
printf "\n%s\n" "${delimiter}"
exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@"
16 changes: 16 additions & 0 deletions macos-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
####################################################################
# macOS defaults #
# Please modify webui-user.sh to change these instead of this file #
####################################################################

if [[ -x "$(command -v python3.10)" ]]
then
python_cmd="python3.10"
fi

export COMMANDLINE_ARGS="--skip-torch-cuda-test"
export TORCH_COMMAND="pip install torch torchvision torchaudio"
export PYTORCH_ENABLE_MPS_FALLBACK=1

####################################################################
13 changes: 13 additions & 0 deletions update.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off

if exist ".git" (
git fetch --prune
git reset --hard origin/main
) else (
git init
git remote add origin https://github.com/ddPn08/Radiata.git
git fetch --prune
git reset --hard origin/main
)

pause
27 changes: 27 additions & 0 deletions user-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
#########################################################
# Uncomment and change the variables below to your need:#
#########################################################

# Commandline arguments for webui.py, for example: export COMMANDLINE_ARGS="--medvram --opt-split-attention"
#export COMMANDLINE_ARGS=""

# python3 executable
#python_cmd="python3"

# git executable
#export GIT="git"

# python3 venv without trailing slash (defaults to ${install_dir}/${clone_dir}/venv)
#venv_dir="venv"

# script to launch to start the app
#export LAUNCH_SCRIPT="launch.py"

# install command for torch
#export TORCH_COMMAND="pip install torch --extra-index-url https://download.pytorch.org/whl/cu118"

# Requirements file to use for stable-diffusion-webui
#export REQS_FILE="requirements_versions.txt"

###########################################

0 comments on commit e70c4f8

Please sign in to comment.