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

Sd3 flux.1 uv #3051

Open
wants to merge 7 commits into
base: sd3-flux.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Python
.venv
venv
venv2
__pycache__
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
2 changes: 1 addition & 1 deletion config example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Edit the values to suit your needs

[settings]
use_shell = false # Use shell furing process run of sd-scripts oython code. Most secure is false but some systems may require it to be true to properly run sd-scripts.
use_shell = false # Use shell during process run of sd-scripts oython code. Most secure is false but some systems may require it to be true to properly run sd-scripts.

# Default folders location
[model]
Expand Down
47 changes: 47 additions & 0 deletions gui-uv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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
}

# Define the directory path for WSL2
lib_path="/usr/lib/wsl/lib/"

# Check if the directory exists
if [ -d "$lib_path" ]; then
# Check if LD_LIBRARY_PATH is already set
if [ -z "${LD_LIBRARY_PATH}" ]; then
# LD_LIBRARY_PATH is not set, set it to the lib_path
export LD_LIBRARY_PATH="$lib_path"
# echo "LD_LIBRARY_PATH set to: $LD_LIBRARY_PATH"
fi
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
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

# This gets the directory the script is run from so pathing can work relative to the script where needed.
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)

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

# Check if uv is already installed
if [ ! -f "$HOME/.local/bin/uv" ]; then
# Setup uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
fi

git submodule update --init --recursive
uv run kohya_gui.py --noverify "$@"
47 changes: 47 additions & 0 deletions gui-uv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/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
}

# Define the directory path for WSL2
lib_path="/usr/lib/wsl/lib/"

# Check if the directory exists
if [ -d "$lib_path" ]; then
# Check if LD_LIBRARY_PATH is already set
if [ -z "${LD_LIBRARY_PATH}" ]; then
# LD_LIBRARY_PATH is not set, set it to the lib_path
export LD_LIBRARY_PATH="$lib_path"
# echo "LD_LIBRARY_PATH set to: $LD_LIBRARY_PATH"
fi
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
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

# This gets the directory the script is run from so pathing can work relative to the script where needed.
SCRIPT_DIR=$(cd -- "$(dirname -- "$0")" && pwd)

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

# Check if uv is already installed
if ! command -v uv &> /dev/null; then
# Setup uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
fi

git submodule update --init --recursive
uv run kohya_gui.py --noverify "$@"
4 changes: 2 additions & 2 deletions kohya_gui/class_flux1.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def noise_offset_type_change(
# interactive=True,
# )
self.single_blocks_to_swap = gr.Slider(
label="Single Blocks to swap (depercated)",
label="Single Blocks to swap (deprecated)",
value=self.config.get("flux1.single_blocks_to_swap", 0),
info="[Experimental] Sets the number of 'single_blocks' (~320MB) to swap during the forward and backward passes.",
minimum=0,
Expand All @@ -221,7 +221,7 @@ def noise_offset_type_change(
interactive=True,
)
self.double_blocks_to_swap = gr.Slider(
label="Double Blocks to swap (depercated)",
label="Double Blocks to swap (deprecated)",
value=self.config.get("flux1.double_blocks_to_swap", 0),
info="[Experimental] Sets the number of 'double_blocks' (~640MB) to swap during the forward and backward passes.",
minimum=0,
Expand Down
1 change: 1 addition & 0 deletions kohya_ss
Submodule kohya_ss added at e5e8be
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[project]
name = "kohya-ss"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.10,<3.11"
dependencies = [
"accelerate==0.33.0",
"aiofiles==23.2.1",
"altair==4.2.2",
"bitsandbytes==0.44.0",
"dadaptation==3.2",
"diffusers[torch]==0.25.0",
"easygui==0.98.3",
"einops==0.7.0",
"fairscale==0.4.13",
"ftfy==6.1.1",
"gradio>=5.4.0",
"huggingface-hub==0.25.2",
"imagesize==1.4.1",
"invisible-watermark==0.2.0",
"library",
"lion-pytorch==0.0.6",
"lycoris-lora==3.1.0",
"omegaconf==2.3.0",
"onnx==1.16.1",
"onnxruntime-gpu==1.19.2",
"open-clip-torch==2.20.0",
"opencv-python==4.10.0.84",
"prodigy-plus-schedule-free==1.8.0",
"prodigyopt==1.0",
"protobuf==3.20.3",
"pytorch-lightning==1.9.0",
"rich>=13.7.1",
"safetensors==0.4.4",
"schedulefree==1.4",
"scipy==1.11.4",
"sentencepiece==0.2.0",
"tensorboard>=2.18.0",
"tensorflow>=2.16.1",
"tensorflow-io-gcs-filesystem==0.31.0",
"timm==0.6.12",
"tk==0.1.0",
"toml==0.10.2",
"torch>=2.5.0",
"torchvision>=0.20.0",
"transformers==4.44.2",
"voluptuous==0.13.1",
"wandb==0.18.0",
"xformers>=0.0.28.post2",
]

[tool.uv.sources]
library = { path = "sd-scripts" }

[[tool.uv.index]]
url = "https://download.pytorch.org/whl/cu124"
32 changes: 32 additions & 0 deletions setup-uv.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
@echo off

IF NOT EXIST venv (
echo Creating venv...
python -m venv venv
)

:: Create the directory if it doesn't exist
mkdir ".\logs\setup" > nul 2>&1

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

call .\venv\Scripts\activate.bat

REM first make sure we have setuptools and uv available in the venv
python -m pip install --require-virtualenv --no-input -q -q setuptools uv

REM upgrade pip if needed
python -m pip install --upgrade pip -q

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 %*
)

:: Deactivate the virtual environment
call .\venv\Scripts\deactivate.bat
18 changes: 14 additions & 4 deletions setup/setup_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def install_requirements_inbulk(

# Build the command as a list
cmd = ["pip", "install", "-r", requirements_file]
if installed("uv") and shutil.which("uv"):
log.info("Using uv for pip...")
cmd.insert(0, "uv")
if upgrade:
cmd.append("--upgrade")
if not show_stdout:
Expand All @@ -179,8 +182,11 @@ def install_requirements_inbulk(
)

for line in process.stdout:
if "Requirement already satisfied" not in line:
log.info(line.strip()) if show_stdout else None
if installed("uv"):
print(line)
else:
if "Requirement already satisfied" not in line:
log.info(line.strip()) if show_stdout else None

# Capture and log any errors
_, stderr = process.communicate()
Expand Down Expand Up @@ -447,9 +453,13 @@ def pip(arg: str, ignore: bool = False, quiet: bool = False, show_stdout: bool =
log.info(
f'Installing package: {arg.replace("install", "").replace("--upgrade", "").replace("--no-deps", "").replace("--force", "").replace(" ", " ").strip()}'
)
# pip_cmd = [rf"{sys.executable}", "-m", "pip"] + arg.split(" ")
pip_cmd = [rf"{sys.executable}", "-m", "pip"] + arg.split(" ")
if installed("uv"):
log.info("Using uv for pip...")
pip_cmd.insert(2, "uv")
log.debug(f"Running pip: {pip_cmd}")
if show_stdout:
if show_stdout or installed("uv"):
subprocess.run(pip_cmd, shell=False, check=False, env=os.environ)
else:
result = subprocess.run(
Expand Down Expand Up @@ -653,7 +663,7 @@ def ensure_base_requirements():
try:
import rich # pylint: disable=unused-import
except ImportError:
install("--upgrade rich", "rich")
install("rich", "rich")

try:
import packaging
Expand Down
Loading
Loading