diff --git a/.release b/.release index f98ff443b..1c8eca7ea 100644 --- a/.release +++ b/.release @@ -1 +1 @@ -v23.0.8 \ No newline at end of file +v23.0.9 \ No newline at end of file diff --git a/README.md b/README.md index 092917941..ca6c486e0 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,9 @@ The GUI allows you to set the training parameters and generate and run the requi - [No module called tkinter](#no-module-called-tkinter) - [SDXL training](#sdxl-training) - [Change History](#change-history) - - [2024/03/11 (v23.0.8)](#20240311-v2308) - - [2024/03/11 (v23.0.7)](#20240311-v2307) + - [2024/03/13 (v23.0.9)](#20240313-v2309) + - [2024/03/12 (v23.0.8)](#20240312-v2308) + - [2024/03/12 (v23.0.7)](#20240312-v2307) - [2024/03/11 (v23.0.6)](#20240311-v2306) - [2024/03/11 (v23.0.5)](#20240311-v2305) - [2024/03/10 (v23.0.4)](#20240310-v2304) @@ -367,11 +368,16 @@ The documentation in this section will be moved to a separate document later. ## Change History -### 2024/03/11 (v23.0.8) +### 2024/03/13 (v23.0.9) + +- Reworked how setup can be run to improve Stability Matrix support +- Add support for huggingface based vea path + +### 2024/03/12 (v23.0.8) - Add the ability to create outout and logs folder if it does not exist -### 2024/03/11 (v23.0.7) +### 2024/03/12 (v23.0.7) - Fix minor issues related to functions and file path diff --git a/kohya_gui/common_gui.py b/kohya_gui/common_gui.py index 1357bd8ed..0998848b4 100644 --- a/kohya_gui/common_gui.py +++ b/kohya_gui/common_gui.py @@ -1374,7 +1374,11 @@ def validate_paths(headless:bool = False, **kwargs): if vae != None: if vae != "": log.info(f"Validating VAE file path {vae} existence...") - if not os.path.exists(vae): + + # Check if it matches the Hugging Face model pattern + if re.match(r'^[\w-]+\/[\w-]+$', vae): + log.info("...huggingface.co vae model provided") + elif not os.path.exists(vae): log.error("...vae path is invalid") return False else: diff --git a/setup-runpod.sh b/setup-runpod.sh index 56052cca9..4654248b2 100755 --- a/setup-runpod.sh +++ b/setup-runpod.sh @@ -21,10 +21,6 @@ fi echo "Activating venv..." 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 echo "Running setup_linux.py..." python "$SCRIPT_DIR/setup/setup_linux.py" --platform-requirements-file=requirements_runpod.txt --show_stdout --no_run_accelerate diff --git a/setup.bat b/setup.bat index 79ff65cc3..2b95e2793 100644 --- a/setup.bat +++ b/setup.bat @@ -1,13 +1,5 @@ @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 ( echo Creating venv... python -m venv venv @@ -16,24 +8,18 @@ IF NOT EXIST venv ( :: Create the directory if it doesn't exist mkdir ".\logs\setup" > nul 2>&1 -:: Deactivate the virtual environment +:: Deactivate the virtual environment to prevent error 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 -echo "Installing packaging python module..." -pip install packaging - REM Check if the batch was started via double-click IF /i "%comspec% /c %~0 " equ "%cmdcmdline:"=%" ( REM echo This script was started by double clicking. cmd /k python .\setup\setup_windows.py ) ELSE ( REM echo This script was started from a command prompt. - python .\setup\setup_windows.py + python .\setup\setup_windows.py %* ) :: Deactivate the virtual environment diff --git a/setup.ps1 b/setup.ps1 index 5459b5fb1..82376432a 100644 --- a/setup.ps1 +++ b/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")) { Write-Host "Creating venv..." python -m venv venv @@ -16,15 +9,9 @@ $null = New-Item -ItemType Directory -Force -Path ".\logs\setup" # Deactivate the virtual environment & .\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 -Write-Host "Installing python packaging module..." -& pip install packaging - -& .\venv\Scripts\python.exe .\setup\setup_windows.py +& .\venv\Scripts\python.exe .\setup\setup_windows.py $args # Deactivate the virtual environment & .\venv\Scripts\deactivate.bat diff --git a/setup.sh b/setup.sh index 70db7a167..3df651d84 100755 --- a/setup.sh +++ b/setup.sh @@ -201,10 +201,6 @@ install_python_dependencies() { source "$DIR/venv/bin/activate" fi - # Install packaging - echo "Installing the python packaging module..." - pip install packaging - case "$OSTYPE" in "lin"*) if [ "$RUNPOD" = true ]; then diff --git a/setup/setup_common.py b/setup/setup_common.py index 52f48943f..15173bdb9 100644 --- a/setup/setup_common.py +++ b/setup/setup_common.py @@ -2,16 +2,11 @@ import os import re import sys -import filecmp import logging import shutil -import sysconfig import datetime -import platform import pkg_resources -from packaging import version - errors = 0 # Define the 'errors' variable before using it log = logging.getLogger('sd') @@ -25,6 +20,8 @@ def check_python_version(): min_version = (3, 10, 9) max_version = (3, 11, 0) + from packaging import version + try: current_version = sys.version_info log.info(f"Python version is {sys.version}") @@ -584,42 +581,19 @@ def ensure_base_requirements(): import rich # pylint: disable=unused-import except ImportError: install('--upgrade rich', 'rich') + + try: + import packaging + except ImportError: + install('packaging') def run_cmd(run_cmd): try: subprocess.run(run_cmd, shell=True, check=False, env=os.environ) except subprocess.CalledProcessError as e: - print(f'Error occurred while running command: {run_cmd}') - print(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()}') + log.error(f'Error occurred while running command: {run_cmd}') + log.error(f'Error: {e}') def delete_file(file_path): diff --git a/setup/setup_linux.py b/setup/setup_linux.py index 6d35cdbea..9698382cc 100644 --- a/setup/setup_linux.py +++ b/setup/setup_linux.py @@ -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.") setup_common.check_repo_version() - setup_common.check_python() + # setup_common.check_python() # Upgrade pip if needed setup_common.install('pip') diff --git a/setup/setup_runpod.py b/setup/setup_runpod.py index ee5707677..3cf38cec8 100644 --- a/setup/setup_runpod.py +++ b/setup/setup_runpod.py @@ -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.") setup_common.check_repo_version() - setup_common.check_python() + # setup_common.check_python() # Upgrade pip if needed setup_common.install('pip') diff --git a/setup/setup_windows.py b/setup/setup_windows.py index ab766d71a..ecd3530a8 100644 --- a/setup/setup_windows.py +++ b/setup/setup_windows.py @@ -5,6 +5,7 @@ import shutil import sysconfig import setup_common +import argparse errors = 0 # Define the 'errors' variable before using it log = logging.getLogger("sd") @@ -105,9 +106,9 @@ def sync_bits_and_bytes_files(): 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_python() + setup_common.check_python_version() setup_common.update_submodule() @@ -117,12 +118,8 @@ def install_kohya_ss_torch2(): setup_common.install_requirements( "requirements_windows_torch2.txt", check_no_verify_flag=False ) - - # sync_bits_and_bytes_files() - setup_common.configure_accelerate(run_accelerate=True) - - # run_cmd(f'accelerate config') + setup_common.configure_accelerate(run_accelerate=not headless) # False if headless is True and vice versa def install_bitsandbytes_0_35_0(): @@ -158,79 +155,90 @@ def install_bitsandbytes_0_41_2(): reinstall=True, ) -def main_menu(): - setup_common.clear_screen() - while True: - print("\nKohya_ss GUI setup menu:\n") - 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: ") - print("") - - if choice == "1": - install_kohya_ss_torch2() - elif choice == "2": - cudnn_install() - elif choice == "3": - while True: - print("1. (Optional) Force installation of bitsandbytes 0.35.0") - print( - "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 +def main_menu(headless: bool = False): + setup_common.ensure_base_requirements() + + if headless: + install_kohya_ss_torch2(headless=headless) + else: + setup_common.clear_screen() + while True: + print("\nKohya_ss GUI setup menu:\n") + 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: ") + print("") + + if choice == "1": + install_kohya_ss_torch2() + elif choice == "2": + cudnn_install() + elif choice == "3": + while True: + print("1. (Optional) Force installation of bitsandbytes 0.35.0") + print( + "2. (Optional) Force installation of bitsandbytes 0.40.1 for new optimizer options support and pre-bugfix results" ) - 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.") + 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 + 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__": - python_ver = setup_common.check_python_version() - setup_common.ensure_base_requirements() 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)