mirror of https://github.com/bmaltais/kohya_ss
Improve setup. Add --headless option
parent
890e521b1b
commit
b27d0694c4
|
|
@ -21,10 +21,6 @@ fi
|
||||||
echo "Activating venv..."
|
echo "Activating venv..."
|
||||||
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
|
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
|
||||||
|
|
||||||
# Install packaging
|
|
||||||
echo "Installing the python packaging module..."
|
|
||||||
pip install packaging
|
|
||||||
|
|
||||||
# Run setup_linux.py script with platform requirements
|
# Run setup_linux.py script with platform requirements
|
||||||
echo "Running setup_linux.py..."
|
echo "Running setup_linux.py..."
|
||||||
python "$SCRIPT_DIR/setup/setup_linux.py" --platform-requirements-file=requirements_runpod.txt --show_stdout --no_run_accelerate
|
python "$SCRIPT_DIR/setup/setup_linux.py" --platform-requirements-file=requirements_runpod.txt --show_stdout --no_run_accelerate
|
||||||
|
|
|
||||||
18
setup.bat
18
setup.bat
|
|
@ -1,13 +1,5 @@
|
||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
set PYTHON_VER=3.10.9
|
|
||||||
|
|
||||||
:: Check if Python version meets the recommended version
|
|
||||||
python --version 2>nul | findstr /b /c:"Python %PYTHON_VER%" >nul
|
|
||||||
if errorlevel 1 (
|
|
||||||
echo Warning: Python version %PYTHON_VER% is required. Kohya_ss GUI will most likely fail to run.
|
|
||||||
)
|
|
||||||
|
|
||||||
IF NOT EXIST venv (
|
IF NOT EXIST venv (
|
||||||
echo Creating venv...
|
echo Creating venv...
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
|
|
@ -16,24 +8,18 @@ IF NOT EXIST venv (
|
||||||
:: Create the directory if it doesn't exist
|
:: Create the directory if it doesn't exist
|
||||||
mkdir ".\logs\setup" > nul 2>&1
|
mkdir ".\logs\setup" > nul 2>&1
|
||||||
|
|
||||||
:: Deactivate the virtual environment
|
:: Deactivate the virtual environment to prevent error
|
||||||
call .\venv\Scripts\deactivate.bat
|
call .\venv\Scripts\deactivate.bat
|
||||||
|
|
||||||
:: Calling external python program to check for local modules
|
|
||||||
:: python .\setup\check_local_modules.py
|
|
||||||
|
|
||||||
call .\venv\Scripts\activate.bat
|
call .\venv\Scripts\activate.bat
|
||||||
|
|
||||||
echo "Installing packaging python module..."
|
|
||||||
pip install packaging
|
|
||||||
|
|
||||||
REM Check if the batch was started via double-click
|
REM Check if the batch was started via double-click
|
||||||
IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" (
|
IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" (
|
||||||
REM echo This script was started by double clicking.
|
REM echo This script was started by double clicking.
|
||||||
cmd /k python .\setup\setup_windows.py
|
cmd /k python .\setup\setup_windows.py
|
||||||
) ELSE (
|
) ELSE (
|
||||||
REM echo This script was started from a command prompt.
|
REM echo This script was started from a command prompt.
|
||||||
python .\setup\setup_windows.py
|
python .\setup\setup_windows.py %*
|
||||||
)
|
)
|
||||||
|
|
||||||
:: Deactivate the virtual environment
|
:: Deactivate the virtual environment
|
||||||
|
|
|
||||||
15
setup.ps1
15
setup.ps1
|
|
@ -1,10 +1,3 @@
|
||||||
|
|
||||||
# Check if Python version meets the recommended version
|
|
||||||
$pythonVersion = & .\venv\Scripts\python.exe --version 2>$null
|
|
||||||
if ($pythonVersion -notmatch "^Python $PYTHON_VER") {
|
|
||||||
Write-Host "Warning: Python version $PYTHON_VER is recommended."
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not (Test-Path -Path "venv")) {
|
if (-not (Test-Path -Path "venv")) {
|
||||||
Write-Host "Creating venv..."
|
Write-Host "Creating venv..."
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
|
|
@ -16,15 +9,9 @@ $null = New-Item -ItemType Directory -Force -Path ".\logs\setup"
|
||||||
# Deactivate the virtual environment
|
# Deactivate the virtual environment
|
||||||
& .\venv\Scripts\deactivate.bat
|
& .\venv\Scripts\deactivate.bat
|
||||||
|
|
||||||
# Calling external python program to check for local modules
|
|
||||||
# & .\venv\Scripts\python.exe .\setup\check_local_modules.py
|
|
||||||
|
|
||||||
& .\venv\Scripts\activate.bat
|
& .\venv\Scripts\activate.bat
|
||||||
|
|
||||||
Write-Host "Installing python packaging module..."
|
& .\venv\Scripts\python.exe .\setup\setup_windows.py $args
|
||||||
& pip install packaging
|
|
||||||
|
|
||||||
& .\venv\Scripts\python.exe .\setup\setup_windows.py
|
|
||||||
|
|
||||||
# Deactivate the virtual environment
|
# Deactivate the virtual environment
|
||||||
& .\venv\Scripts\deactivate.bat
|
& .\venv\Scripts\deactivate.bat
|
||||||
|
|
|
||||||
4
setup.sh
4
setup.sh
|
|
@ -201,10 +201,6 @@ install_python_dependencies() {
|
||||||
source "$DIR/venv/bin/activate"
|
source "$DIR/venv/bin/activate"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install packaging
|
|
||||||
echo "Installing the python packaging module..."
|
|
||||||
pip install packaging
|
|
||||||
|
|
||||||
case "$OSTYPE" in
|
case "$OSTYPE" in
|
||||||
"lin"*)
|
"lin"*)
|
||||||
if [ "$RUNPOD" = true ]; then
|
if [ "$RUNPOD" = true ]; then
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,11 @@ import subprocess
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
import filecmp
|
|
||||||
import logging
|
import logging
|
||||||
import shutil
|
import shutil
|
||||||
import sysconfig
|
|
||||||
import datetime
|
import datetime
|
||||||
import platform
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from packaging import version
|
|
||||||
|
|
||||||
errors = 0 # Define the 'errors' variable before using it
|
errors = 0 # Define the 'errors' variable before using it
|
||||||
log = logging.getLogger('sd')
|
log = logging.getLogger('sd')
|
||||||
|
|
||||||
|
|
@ -25,6 +20,8 @@ def check_python_version():
|
||||||
min_version = (3, 10, 9)
|
min_version = (3, 10, 9)
|
||||||
max_version = (3, 11, 0)
|
max_version = (3, 11, 0)
|
||||||
|
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_version = sys.version_info
|
current_version = sys.version_info
|
||||||
log.info(f"Python version is {sys.version}")
|
log.info(f"Python version is {sys.version}")
|
||||||
|
|
@ -584,42 +581,19 @@ def ensure_base_requirements():
|
||||||
import rich # pylint: disable=unused-import
|
import rich # pylint: disable=unused-import
|
||||||
except ImportError:
|
except ImportError:
|
||||||
install('--upgrade rich', 'rich')
|
install('--upgrade rich', 'rich')
|
||||||
|
|
||||||
|
try:
|
||||||
|
import packaging
|
||||||
|
except ImportError:
|
||||||
|
install('packaging')
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(run_cmd):
|
def run_cmd(run_cmd):
|
||||||
try:
|
try:
|
||||||
subprocess.run(run_cmd, shell=True, check=False, env=os.environ)
|
subprocess.run(run_cmd, shell=True, check=False, env=os.environ)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f'Error occurred while running command: {run_cmd}')
|
log.error(f'Error occurred while running command: {run_cmd}')
|
||||||
print(f'Error: {e}')
|
log.error(f'Error: {e}')
|
||||||
|
|
||||||
|
|
||||||
# check python version
|
|
||||||
def check_python(ignore=True, skip_git=False):
|
|
||||||
#
|
|
||||||
# This function was adapted from code written by vladimandic: https://github.com/vladmandic/automatic/commits/master
|
|
||||||
#
|
|
||||||
|
|
||||||
supported_minors = [9, 10]
|
|
||||||
log.info(f'Python {platform.python_version()} on {platform.system()}')
|
|
||||||
if not (
|
|
||||||
int(sys.version_info.major) == 3
|
|
||||||
and int(sys.version_info.minor) in supported_minors
|
|
||||||
):
|
|
||||||
log.error(
|
|
||||||
f'Incompatible Python version: {sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro} required 3.{supported_minors}'
|
|
||||||
)
|
|
||||||
if not ignore:
|
|
||||||
sys.exit(1)
|
|
||||||
if not skip_git:
|
|
||||||
git_cmd = os.environ.get('GIT', 'git')
|
|
||||||
if shutil.which(git_cmd) is None:
|
|
||||||
log.error('Git not found')
|
|
||||||
if not ignore:
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
git_version = git('--version', folder=None, ignore=False)
|
|
||||||
log.debug(f'Git {git_version.replace("git version", "").strip()}')
|
|
||||||
|
|
||||||
|
|
||||||
def delete_file(file_path):
|
def delete_file(file_path):
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ def main_menu(platform_requirements_file, show_stdout: bool = False, no_run_acce
|
||||||
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
|
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
|
||||||
|
|
||||||
setup_common.check_repo_version()
|
setup_common.check_repo_version()
|
||||||
setup_common.check_python()
|
# setup_common.check_python()
|
||||||
|
|
||||||
# Upgrade pip if needed
|
# Upgrade pip if needed
|
||||||
setup_common.install('pip')
|
setup_common.install('pip')
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ def main_menu(platform_requirements_file):
|
||||||
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
|
log.info("If this operation ever runs too long, you can rerun this script in verbose mode to check.")
|
||||||
|
|
||||||
setup_common.check_repo_version()
|
setup_common.check_repo_version()
|
||||||
setup_common.check_python()
|
# setup_common.check_python()
|
||||||
|
|
||||||
# Upgrade pip if needed
|
# Upgrade pip if needed
|
||||||
setup_common.install('pip')
|
setup_common.install('pip')
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import logging
|
||||||
import shutil
|
import shutil
|
||||||
import sysconfig
|
import sysconfig
|
||||||
import setup_common
|
import setup_common
|
||||||
|
import argparse
|
||||||
|
|
||||||
errors = 0 # Define the 'errors' variable before using it
|
errors = 0 # Define the 'errors' variable before using it
|
||||||
log = logging.getLogger("sd")
|
log = logging.getLogger("sd")
|
||||||
|
|
@ -105,9 +106,9 @@ def sync_bits_and_bytes_files():
|
||||||
log.error(f"An unexpected error occurred: {e}")
|
log.error(f"An unexpected error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
def install_kohya_ss_torch2():
|
def install_kohya_ss_torch2(headless: bool = False):
|
||||||
setup_common.check_repo_version()
|
setup_common.check_repo_version()
|
||||||
setup_common.check_python()
|
setup_common.check_python_version()
|
||||||
|
|
||||||
setup_common.update_submodule()
|
setup_common.update_submodule()
|
||||||
|
|
||||||
|
|
@ -117,12 +118,9 @@ def install_kohya_ss_torch2():
|
||||||
setup_common.install_requirements(
|
setup_common.install_requirements(
|
||||||
"requirements_windows_torch2.txt", check_no_verify_flag=False
|
"requirements_windows_torch2.txt", check_no_verify_flag=False
|
||||||
)
|
)
|
||||||
|
|
||||||
# sync_bits_and_bytes_files()
|
|
||||||
|
|
||||||
setup_common.configure_accelerate(run_accelerate=True)
|
if not headless:
|
||||||
|
setup_common.configure_accelerate(run_accelerate=True)
|
||||||
# run_cmd(f'accelerate config')
|
|
||||||
|
|
||||||
|
|
||||||
def install_bitsandbytes_0_35_0():
|
def install_bitsandbytes_0_35_0():
|
||||||
|
|
@ -158,79 +156,90 @@ def install_bitsandbytes_0_41_2():
|
||||||
reinstall=True,
|
reinstall=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
def main_menu():
|
def main_menu(headless: bool = False):
|
||||||
setup_common.clear_screen()
|
setup_common.ensure_base_requirements()
|
||||||
while True:
|
|
||||||
print("\nKohya_ss GUI setup menu:\n")
|
if headless:
|
||||||
print("1. Install kohya_ss gui")
|
install_kohya_ss_torch2(headless=headless)
|
||||||
print("2. (Optional) Install cudnn files (if you want to use latest supported cudnn version)")
|
else:
|
||||||
print("3. (Optional) Install specific bitsandbytes versions")
|
setup_common.clear_screen()
|
||||||
print("4. (Optional) Manually configure accelerate")
|
while True:
|
||||||
print("5. (Optional) Start Kohya_ss GUI in browser")
|
print("\nKohya_ss GUI setup menu:\n")
|
||||||
print("6. Quit")
|
print("1. Install kohya_ss gui")
|
||||||
|
print("2. (Optional) Install cudnn files (if you want to use latest supported cudnn version)")
|
||||||
|
print("3. (Optional) Install specific bitsandbytes versions")
|
||||||
|
print("4. (Optional) Manually configure accelerate")
|
||||||
|
print("5. (Optional) Start Kohya_ss GUI in browser")
|
||||||
|
print("6. Quit")
|
||||||
|
|
||||||
choice = input("\nEnter your choice: ")
|
choice = input("\nEnter your choice: ")
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
if choice == "1":
|
if choice == "1":
|
||||||
install_kohya_ss_torch2()
|
install_kohya_ss_torch2()
|
||||||
elif choice == "2":
|
elif choice == "2":
|
||||||
cudnn_install()
|
cudnn_install()
|
||||||
elif choice == "3":
|
elif choice == "3":
|
||||||
while True:
|
while True:
|
||||||
print("1. (Optional) Force installation of bitsandbytes 0.35.0")
|
print("1. (Optional) Force installation of bitsandbytes 0.35.0")
|
||||||
print(
|
print(
|
||||||
"2. (Optional) Force installation of bitsandbytes 0.40.1 for new optimizer options support and pre-bugfix results"
|
"2. (Optional) Force installation of bitsandbytes 0.40.1 for new optimizer options support and pre-bugfix results"
|
||||||
)
|
|
||||||
print(
|
|
||||||
"3. (Optional) Force installation of bitsandbytes 0.41.1 for new optimizer options support"
|
|
||||||
)
|
|
||||||
print(
|
|
||||||
"4. (Recommended) Force installation of bitsandbytes 0.41.2 for new optimizer options support"
|
|
||||||
)
|
|
||||||
print(
|
|
||||||
"5. (Danger) Install bitsandbytes-windows (this package has been reported to cause issues for most... avoid...)"
|
|
||||||
)
|
|
||||||
print("6. Exit")
|
|
||||||
choice_torch = input("\nEnter your choice: ")
|
|
||||||
print("")
|
|
||||||
|
|
||||||
if choice_torch == "1":
|
|
||||||
install_bitsandbytes_0_35_0()
|
|
||||||
break
|
|
||||||
elif choice_torch == "2":
|
|
||||||
install_bitsandbytes_0_40_1()
|
|
||||||
break
|
|
||||||
elif choice_torch == "3":
|
|
||||||
install_bitsandbytes_0_41_1()
|
|
||||||
break
|
|
||||||
elif choice_torch == "3":
|
|
||||||
install_bitsandbytes_0_41_2()
|
|
||||||
break
|
|
||||||
elif choice_torch == "5":
|
|
||||||
setup_common.install(
|
|
||||||
"--upgrade bitsandbytes-windows", reinstall=True
|
|
||||||
)
|
)
|
||||||
break
|
print(
|
||||||
elif choice_torch == "6":
|
"3. (Optional) Force installation of bitsandbytes 0.41.1 for new optimizer options support"
|
||||||
break
|
)
|
||||||
else:
|
print(
|
||||||
print("Invalid choice. Please enter a number between 1-3.")
|
"4. (Recommended) Force installation of bitsandbytes 0.41.2 for new optimizer options support"
|
||||||
elif choice == "4":
|
)
|
||||||
setup_common.run_cmd("accelerate config")
|
print(
|
||||||
elif choice == "5":
|
"5. (Danger) Install bitsandbytes-windows (this package has been reported to cause issues for most... avoid...)"
|
||||||
subprocess.Popen(
|
)
|
||||||
"start cmd /k .\gui.bat --inbrowser", shell=True
|
print("6. Exit")
|
||||||
) # /k keep the terminal open on quit. /c would close the terminal instead
|
choice_torch = input("\nEnter your choice: ")
|
||||||
elif choice == "6":
|
print("")
|
||||||
print("Quitting the program.")
|
|
||||||
break
|
if choice_torch == "1":
|
||||||
else:
|
install_bitsandbytes_0_35_0()
|
||||||
print("Invalid choice. Please enter a number between 1-5.")
|
break
|
||||||
|
elif choice_torch == "2":
|
||||||
|
install_bitsandbytes_0_40_1()
|
||||||
|
break
|
||||||
|
elif choice_torch == "3":
|
||||||
|
install_bitsandbytes_0_41_1()
|
||||||
|
break
|
||||||
|
elif choice_torch == "3":
|
||||||
|
install_bitsandbytes_0_41_2()
|
||||||
|
break
|
||||||
|
elif choice_torch == "5":
|
||||||
|
setup_common.install(
|
||||||
|
"--upgrade bitsandbytes-windows", reinstall=True
|
||||||
|
)
|
||||||
|
break
|
||||||
|
elif choice_torch == "6":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid choice. Please enter a number between 1-3.")
|
||||||
|
elif choice == "4":
|
||||||
|
setup_common.run_cmd("accelerate config")
|
||||||
|
elif choice == "5":
|
||||||
|
subprocess.Popen(
|
||||||
|
"start cmd /k .\gui.bat --inbrowser", shell=True
|
||||||
|
) # /k keep the terminal open on quit. /c would close the terminal instead
|
||||||
|
elif choice == "6":
|
||||||
|
print("Quitting the program.")
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid choice. Please enter a number between 1-5.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
python_ver = setup_common.check_python_version()
|
|
||||||
setup_common.ensure_base_requirements()
|
|
||||||
setup_common.setup_logging()
|
setup_common.setup_logging()
|
||||||
main_menu()
|
|
||||||
|
# Setup argument parser
|
||||||
|
parser = argparse.ArgumentParser(description="Your Script Description")
|
||||||
|
parser.add_argument('--headless', action='store_true', help='Run in headless mode')
|
||||||
|
|
||||||
|
# Parse arguments
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main_menu(headless=args.headless)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue