Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v21.7.12 #1055

Merged
merged 27 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ test/output
test/logs
test/*.json
test/ft
requirements_tmp_for_setup.txt
0.13.3
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ RUN python3 -m pip install wheel
## RUN python3 -m pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers

# Install requirements
COPY requirements_unix.txt setup.py ./
RUN python3 -m pip install --use-pep517 -r requirements_unix.txt xformers
COPY requirements_linux.txt ./setup/setup.py ./
RUN python3 -m pip install --use-pep517 -r requirements_linux.txt xformers

# Replace pillow with pillow-simd
RUN python3 -m pip uninstall -y pillow && \
Expand Down
50 changes: 27 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@
## Installation

### Runpod
Follow the instructions found in this discussion: https://github.com/bmaltais/kohya_ss/discussions/379
- Select the pytorch 2.0.1 template
- ssh into the runpod

```
cd /workspace
git clone https://github.com/bmaltais/kohya_ss.git
git checkout dev2
./setup.sh -p
```

Connect to the public URL displayed

### Docker
Docker is supported on Windows and Linux distributions. However this method currently only supports Nvidia GPUs.
Expand Down Expand Up @@ -102,7 +112,11 @@

venv support need to be pre-installed. Can be done on ubuntu 22.04 with `apt install python3.10-venv`

Make sure to use a version of python >= 3.10.6 and < 3.11.0
Install the cudaNN drivers following the instructions from: `https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64`

Use a version of python >= 3.10.6 and < 3.11.0

On WSL2, make sure to `export LD_LIBRARY_PATH=/usr/lib/wsl/lib/` or else AdamW8bit will not work.

#### Setup

Expand Down Expand Up @@ -170,11 +184,6 @@
.\setup.bat
```

If this is a 1st install answer No when asked `Do you want to uninstall previous versions of torch and associated files before installing`.


Then configure accelerate with the same answers as in the MacOS instructions when prompted.

### Optional: CUDNN 8.6

This step is optional but can improve the learning speed for NVIDIA 30X0/40X0 owners. It allows for larger training batch size and faster training speed.
Expand All @@ -196,26 +205,20 @@
## Upgrading

The following commands will work from the root directory of the project if you'd prefer to not run scripts.
These commands will work on any OS.
```bash
git pull

.\venv\Scripts\activate

pip install --use-pep517 --upgrade -r requirements.txt
```

### Windows Upgrade
When a new release comes out, you can upgrade your repo with the following commands in the root directory:

```powershell
upgrade.bat
git pull
.\setup.bat
```

### Linux and macOS Upgrade
You can cd into the root directory and simply run

```bash
git pull
# Refresh and update everything
./setup.sh

Expand Down Expand Up @@ -279,13 +282,7 @@

## LoRA

Training a LoRA currently uses the `train_network.py` code. You can create a LoRA network by using the all-in-one `gui.cmd` or by running the dedicated LoRA training GUI with:

```
.\venv\Scripts\activate

python lora_gui.py
```
Training a LoRA currently uses the `train_network.py` code. You can create a LoRA network by using the all-in-one gui.

Once you have created the LoRA network, you can generate images via auto1111 by installing [this extension](https://github.com/kohya-ss/sd-webui-additional-networks).

Expand Down Expand Up @@ -353,8 +350,15 @@

## Change History

* 2023/06/24 (v21.7.12)
- Significantly improved the setup process on all platforms
- Better support for runpod
* 2023/06/23 (v21.7.11)
- This is a significant update to how setup work across different platform. It might be causing issues... especially for linux env like runpod. If you encounter problems please report them in the issues so I can try to address them. You can revert to the previous release with `git checkout v21.7.10`

The setup solution is now much more modulat and will simplify requirements support across different environments... hoping this will make it easier to run on different OS.
* 2023/06/19 (v21.7.10)
- Quick fix for linux GUI startup where it would try to install darwin requirements on top of linux. Ugly fix but work. Hopefulle some linux user will improve via a PR.

Check warning on line 361 in README.md

View workflow job for this annotation

GitHub Actions / build

"Hopefulle" should be "Hopefully".
* 2023/06/18 (v21.7.9)
- Implement temporary fix for validation of image dataset. Will no longer stop execution but will let training continue... this is changed to avoid stopping training on false positive... yet still raise awaireness that something might be wrong with the image dataset structure.
* 2023/06/14 (v21.7.8)
Expand Down
16 changes: 12 additions & 4 deletions gui.bat
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
@echo off

:: Deactivate the virtual environment
call .\venv\Scripts\deactivate.bat

:: Calling external python program to check for local modules
python .\tools\check_local_modules.py --no_question
python .\setup\check_local_modules.py --no_question

:: Activate the virtual environment
call .\venv\Scripts\activate.bat
set PATH=%PATH%;%~dp0venv\Lib\site-packages\torch\lib

:: Validate requirements
python.exe .\tools\validate_requirements.py
python.exe .\setup\validate_requirements.py

:: If the exit code is 0, run the kohya_gui.py script with the command-line arguments
if %errorlevel% equ 0 (
python.exe kohya_gui.py %*
)
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.exe kohya_gui.py %*
) ELSE (
REM echo This script was started from a command prompt.
python.exe kohya_gui.py %*
)
)
4 changes: 2 additions & 2 deletions gui.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ if ($pipOutput) {
$env:PATH += ";$($MyInvocation.MyCommand.Path)\venv\Lib\site-packages\torch\lib"

# Debug info about system
# python.exe .\tools\debug_info.py
# python.exe .\setup\debug_info.py

# Validate the requirements and store the exit code
python.exe .\tools\validate_requirements.py
python.exe .\setup\validate_requirements.py

# If the exit code is 0, read arguments from gui_parameters.txt (if it exists)
# and run the kohya_gui.py script with the command-line arguments
Expand Down
58 changes: 52 additions & 6 deletions gui.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
#!/usr/bin/env bash

# Checks to see if variable is set and non-empty.
# This is defined first, so we can use the function for some default variable values
env_var_exists() {
if [[ -n "${!1}" ]]; then
return 0
else
return 1
fi
}

# Need RUNPOD to have a default value before first access
RUNPOD=false
if env_var_exists RUNPOD_POD_ID || env_var_exists RUNPOD_API_KEY; then
RUNPOD=true
fi

# If it is run with the sudo command, get the complete LD_LIBRARY_PATH environment variable of the system and assign it to the current environment,
# because it will be used later.
if [ -n "$SUDO_USER" ] || [ -n "$SUDO_COMMAND" ] ; then
if [ -n "$SUDO_USER" ] || [ -n "$SUDO_COMMAND" ]; then
echo "The sudo command resets the non-essential environment variables, we keep the LD_LIBRARY_PATH variable."
export LD_LIBRARY_PATH=$(sudo -i printenv LD_LIBRARY_PATH)
fi
Expand All @@ -11,12 +27,42 @@ fi
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)

# Step into GUI local directory
cd "$SCRIPT_DIR"
cd "$SCRIPT_DIR" || exit 1

if [ "$RUNPOD" = false ]; then
# Activate the virtual environment
source "$SCRIPT_DIR/venv/bin/activate" || exit 1
fi

# Check if LD_LIBRARY_PATH environment variable exists
if [[ -z "${LD_LIBRARY_PATH}" ]]; then
# Set the ANSI escape sequence for yellow text
YELLOW='\033[0;33m'
# Set the ANSI escape sequence to reset text color
RESET='\033[0m'

echo -e "${YELLOW}Warning: LD_LIBRARY_PATH environment variable is not set.${RESET}"
echo -e "${YELLOW}Certain functionalities may not work correctly.${RESET}"
echo -e "${YELLOW}Please ensure that the required libraries are properly configured.${RESET}"
echo -e " "
fi

# Activate the virtual environment
source "$SCRIPT_DIR/venv/bin/activate"
# Determine the requirements file based on the system
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$(uname -m)" == "arm64" ]]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_macos_arm64.txt"
else
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_macos_amd64.txt"
fi
else
if [ "$RUNPOD" = true ]; then
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_linux.txt"
else
REQUIREMENTS_FILE="$SCRIPT_DIR/requirements_runpod.txt"
fi
fi

# If the requirements are validated, run the kohya_gui.py script with the command-line arguments
if python "$SCRIPT_DIR"/tools/validate_requirements_unix.py -r "$SCRIPT_DIR"/requirements_unix.txt; then
# Validate the requirements and run the script if successful
if python "$SCRIPT_DIR/setup/validate_requirements.py" -r "$REQUIREMENTS_FILE"; then
python "$SCRIPT_DIR/kohya_gui.py" "$@"
fi
6 changes: 5 additions & 1 deletion library/convert_model_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def gradio_convert_model_tab(headless=False):
gr.Markdown(
'This utility can be used to convert from one stable diffusion model format to another.'
)

model_ext = gr.Textbox(value='*.safetensors *.ckpt', visible=False)
model_ext_name = gr.Textbox(value='Model types', visible=False)

with gr.Row():
source_model_input = gr.Textbox(
label='Source model',
Expand All @@ -198,7 +202,7 @@ def gradio_convert_model_tab(headless=False):
)
button_source_model_file.click(
get_file_path,
inputs=[source_model_input],
inputs=[source_model_input, model_ext, model_ext_name],
outputs=source_model_input,
show_progress=False,
)
Expand Down
6 changes: 5 additions & 1 deletion library/custom_logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
import time
import sys

from rich.theme import Theme
from rich.logging import RichHandler
Expand All @@ -23,7 +24,10 @@ def setup_logging(clean=False, debug=False):
except:
pass

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(pathname)s | %(message)s', filename='setup.log', filemode='a', encoding='utf-8', force=True)
if sys.version_info >= (3, 9):
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(pathname)s | %(message)s', filename='setup.log', filemode='a', encoding='utf-8', force=True)
else:
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s | %(levelname)s | %(pathname)s | %(message)s', filename='setup.log', filemode='a', force=True)

console = Console(log_time=True, log_time_format='%H:%M:%S-%f', theme=Theme({
"traceback.border": "black",
Expand Down
10 changes: 9 additions & 1 deletion lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,15 @@ def update_LoRA_settings(LoRA_type):
'decompose_both': ({'LyCORIS/LoKr'}, gr.Slider),
'train_on_input': ({'LyCORIS/iA3'}, gr.Slider),
'scale_weight_norms': (
{'Kohya DyLoRA', 'Kohya LoCon'},
{
'LoCon',
'Kohya DyLoRA',
'Kohya LoCon',
'LyCORIS/DyLoRA',
'LyCORIS/LoHa',
'LyCORIS/LoCon',
'LyCORIS/LoKr',
},
gr.Slider,
),
'network_dropout': (
Expand Down
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "library"
version = "1.0.3"
description = "Libraries required to run kohya_ss GUI"
authors = ["Bernard Maltais <[email protected]>"]
license = "Apache-2.0" # Apache Software License

[[tool.poetry.source]]
name = "library"
path = "library"

[tool.poetry.dependencies]
python = ">=3.9,<3.11"

[tool.poetry.dev-dependencies]
13 changes: 3 additions & 10 deletions requirements_Ubuntu_20.04.txt → requirements.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
accelerate==0.19.0
albumentations==1.3.0
altair==4.2.2
bitsandbytes==0.35.0
dadaptation==3.1
diffusers[torch]==0.10.2
easygui==0.98.3
einops==0.6.0
fairscale==0.4.13
ftfy==6.1.1
gradio==3.23.0; sys_platform == 'darwin'
gradio==3.32.0; sys_platform != 'darwin'
huggingface-hub==0.13.3; sys_platform == 'darwin'
huggingface-hub==0.13.3; sys_platform != 'darwin'
gradio==3.33.1
huggingface-hub>=0.13.3
lion-pytorch==0.0.6
lycoris_lora==0.1.6
opencv-python==4.7.0.68
prodigyopt==1.0
pytorch-lightning==1.9.0
rich==13.4.1
safetensors==0.2.6
tensorboard==2.10.1 ; sys_platform != 'darwin'
tensorboard==2.12.1 ; sys_platform == 'darwin'
tensorflow==2.10.1; sys_platform != 'darwin'
timm==0.6.12
tk==0.1.0
toml==0.10.2
transformers==4.26.0
voluptuous==0.13.1
wandb==0.15.0
# for kohya_ss library
.
-e . # no_verify leave this to specify not checking this a verification stage
4 changes: 4 additions & 0 deletions requirements_linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 # no_verify leave this to specify not checking this a verification stage
xformers==0.0.20 bitsandbytes==0.39.1
accelerate==0.19.0 tensorboard==2.12.1 tensorflow==2.12.0
-r requirements.txt
4 changes: 4 additions & 0 deletions requirements_macos_amd64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torch==2.0.0 torchvision==0.15.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
xformers bitsandbytes==0.35.0
accelerate==0.19.0 tensorflow-macos tensorboard==2.12.1
-r requirements.txt
4 changes: 4 additions & 0 deletions requirements_macos_arm64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
torch==2.0.0 torchvision==0.15.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
xformers bitsandbytes==0.35.0
accelerate==0.19.0 tensorflow-metal tensorboard==2.12.1
-r requirements.txt
5 changes: 5 additions & 0 deletions requirements_runpod.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
torch==2.0.1+cu117 torchvision==0.15.2+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 # no_verify leave this to specify not checking this a verification stage
xformers==0.0.20 bitsandbytes==0.39.1
accelerate==0.19.0 tensorboard==2.12.1 tensorflow==2.12.0
tensorrt
-r requirements.txt
Loading