From e70c4f82a5ad27d90e6ded377d396e4c20e29b34 Mon Sep 17 00:00:00 2001 From: ddPn08 Date: Sat, 29 Apr 2023 21:46:56 +0900 Subject: [PATCH] update launch script --- launch-user.bat | 1 - launch-user.sh | 9 ----- launch.bat | 19 ++-------- launch.sh | 93 ++++++++++++++++++++++++++++++++++++++++++------- macos-env.sh | 16 +++++++++ update.bat | 13 +++++++ user-env.sh | 27 ++++++++++++++ 7 files changed, 138 insertions(+), 40 deletions(-) delete mode 100644 launch-user.sh create mode 100644 macos-env.sh create mode 100644 update.bat create mode 100644 user-env.sh diff --git a/launch-user.bat b/launch-user.bat index 7892681c..ffab1e39 100644 --- a/launch-user.bat +++ b/launch-user.bat @@ -3,7 +3,6 @@ set PYTHON= set GIT= set VENV_DIR= -set UVICORN_ARGS=--port 8000 set COMMANDLINE_ARGS= call launch.bat \ No newline at end of file diff --git a/launch-user.sh b/launch-user.sh deleted file mode 100644 index f15028c0..00000000 --- a/launch-user.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -# python_cmd="python3" -# export GIT="git" -# venv_dir="venv" -export UVICORN_ARGS="--port 8000" -# export COMMANDLINE_ARGS="" - -exec ./launch.sh \ No newline at end of file diff --git a/launch.bat b/launch.bat index 2d28228c..65051b1d 100644 --- a/launch.bat +++ b/launch.bat @@ -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 @@ -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. diff --git a/launch.sh b/launch.sh index c29e254d..ea8cc603 100755 --- a/launch.sh +++ b/launch.sh @@ -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 @@ -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" @@ -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}" @@ -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 \ No newline at end of file +printf "\n%s\n" "${delimiter}" +printf "Launching launch.py..." +printf "\n%s\n" "${delimiter}" +exec "${python_cmd}" "${LAUNCH_SCRIPT}" "$@" \ No newline at end of file diff --git a/macos-env.sh b/macos-env.sh new file mode 100644 index 00000000..26a32da4 --- /dev/null +++ b/macos-env.sh @@ -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 + +#################################################################### \ No newline at end of file diff --git a/update.bat b/update.bat new file mode 100644 index 00000000..1f96cac7 --- /dev/null +++ b/update.bat @@ -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 \ No newline at end of file diff --git a/user-env.sh b/user-env.sh new file mode 100644 index 00000000..3061cbb6 --- /dev/null +++ b/user-env.sh @@ -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" + +########################################### \ No newline at end of file