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

v24.0.3 #2320

Merged
merged 3 commits into from
Apr 18, 2024
Merged

v24.0.3 #2320

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
2 changes: 1 addition & 1 deletion .release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v24.0.2
v24.0.3
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ The GUI allows you to set the training parameters and generate and run the requi
- [SDXL training](#sdxl-training)
- [Masked loss](#masked-loss)
- [Change History](#change-history)
- [2024/04/24 (v24.0.3)](#20240424-v2403)
- [2024/04/24 (v24.0.2)](#20240424-v2402)
- [2024/04/17 (v24.0.1)](#20240417-v2401)
- [Enhancements](#enhancements)
- [Security and Stability](#security-and-stability)
Expand Down Expand Up @@ -406,6 +408,11 @@ ControlNet dataset is used to specify the mask. The mask images should be the RG

## Change History


### 2024/04/24 (v24.0.3)

- Fix issue with sample prompt creation

### 2024/04/24 (v24.0.2)

- Fixed issue with clip_skip not being passed as an int to sd-scripts when using old config.json files.
Expand Down
26 changes: 11 additions & 15 deletions kohya_gui/basic_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,31 @@ def caption_images(
log.info(f"Captioning files in {images_dir} with {caption_text}...")

# Build the command to run caption.py
run_cmd = [PYTHON, fr'"{scriptdir}/tools/caption.py"']

# Add required arguments
run_cmd.append('--caption_text')
run_cmd.append(caption_text)
run_cmd = rf'"{PYTHON}" "{scriptdir}/tools/caption.py"'
run_cmd += f' --caption_text="{caption_text}"'

# Add optional flags to the command
if overwrite:
run_cmd.append("--overwrite")
run_cmd += f" --overwrite"
if caption_ext:
run_cmd.append('--caption_file_ext')
run_cmd.append(caption_ext)
run_cmd += f' --caption_file_ext="{caption_ext}"'

run_cmd += f' "{images_dir}"'

# Add the directory containing the images
run_cmd.append(fr'"{images_dir}"')
# Log the command
log.info(run_cmd)

# Set the environment variable for the Python path
env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
env["TF_ENABLE_ONEDNN_OPTS"] = "0"

# Reconstruct the safe command string for display
command_to_run = " ".join(run_cmd)
log.info(f"Executing command: {command_to_run} with shell={use_shell}")
log.info(f"Executing command: {run_cmd} with shell={use_shell}")

# Run the command in the sd-scripts folder context
subprocess.run(command_to_run, env=env, shell=use_shell)
subprocess.run(run_cmd, env=env, shell=use_shell)


# Check if overwrite option is enabled
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/blip_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def caption_images(
log.info(f"Captioning files in {train_data_dir}...")

# Construct the command to run make_captions.py
run_cmd = [PYTHON, fr'"{scriptdir}/sd-scripts/finetune/make_captions.py"']
run_cmd = [fr'"{PYTHON}"', fr'"{scriptdir}/sd-scripts/finetune/make_captions.py"']

# Add required arguments
run_cmd.append('--batch_size')
Expand Down
21 changes: 20 additions & 1 deletion kohya_gui/common_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ def update_my_data(my_data):

# Convert values to int if they are strings
for key in [
"adaptive_noise_scale",
"clip_skip",
"epoch",
"gradient_accumulation_steps",
Expand Down Expand Up @@ -351,7 +352,7 @@ def update_my_data(my_data):
except ValueError:
# Handle the case where the string is not a valid float
my_data[key] = int(1)

# Convert values to int if they are strings
for key in ["max_token_length"]:
value = my_data.get(key)
Expand Down Expand Up @@ -1449,3 +1450,21 @@ def is_file_writable(file_path: str) -> bool:
except IOError:
# If an IOError occurs, the file cannot be written to
return False

def print_command_and_toml(run_cmd, tmpfilename):
log.warning(
"Here is the trainer command as a reference. It will not be executed:\n"
)
# Reconstruct the safe command string for display
command_to_run = " ".join(run_cmd)

log.info(command_to_run)
print("")

log.info(f"Showing toml config file: {tmpfilename}")
print("")
with open(tmpfilename, "r") as toml_file:
log.info(toml_file.read())
log.info(f"end of toml config file: {tmpfilename}")

save_to_file(command_to_run)
31 changes: 10 additions & 21 deletions kohya_gui/convert_lcm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,40 +47,29 @@ def convert_lcm(
path, ext = os.path.splitext(save_to)
save_to = f"{path}_lcm{ext}"

# Initialize the command to run the script
run_cmd = [
PYTHON,
f"{scriptdir}/path_to_script.py",
] # Adjust the script path accordingly

# Add required arguments
run_cmd.append("--lora-scale")
run_cmd.append(str(lora_scale))
run_cmd.append("--model")
run_cmd.append(rf'"{model_path}"')
run_cmd.append("--name")
run_cmd.append(name)

# Add conditional flags based on the model type
# Construct the command to run the script
run_cmd += f" --lora-scale {lora_scale}"
run_cmd += f' --model "{model_path}"'
run_cmd += f' --name "{name}"'

if model_type == "SDXL":
run_cmd.append("--sdxl")
run_cmd += f" --sdxl"
if model_type == "SSD-1B":
run_cmd.append("--ssd-1b")
run_cmd += f" --ssd-1b"

# Set up the environment
env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
env["TF_ENABLE_ONEDNN_OPTS"] = "0"

# Reconstruct the safe command string for display
command_to_run = " ".join(run_cmd)
log.info(f"Executing command: {command_to_run} with shell={use_shell}")
log.info(f"Executing command: {run_cmd} with shell={use_shell}")

# Run the command in the sd-scripts folder context
subprocess.run(
command_to_run, env=env, shell=use_shell
run_cmd, env=env, shell=use_shell
)

# Return a success message
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/convert_model_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def convert_model(
return

run_cmd = [
PYTHON,
fr'"{PYTHON}"',
fr'"{scriptdir}/sd-scripts/tools/convert_diffusers20_original_sd.py"',
]

Expand Down Expand Up @@ -100,7 +100,7 @@ def convert_model(

env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
# Adding an example of an environment variable that might be relevant
env["TF_ENABLE_ONEDNN_OPTS"] = "0"
Expand Down
26 changes: 8 additions & 18 deletions kohya_gui/dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import toml
from datetime import datetime
from .common_gui import (
check_if_model_exist,
color_aug_changed,
get_executable_path,
get_file_path,
get_saveasfile_path,
color_aug_changed,
print_command_and_toml,
run_cmd_advanced_training,
update_my_data,
check_if_model_exist,
SaveConfigFile,
save_to_file,
scriptdir,
update_my_data,
validate_paths,
)
from .class_accelerate_launch import AccelerateLaunch
Expand Down Expand Up @@ -49,8 +49,6 @@
huggingface = None
use_shell = False

PYTHON = sys.executable

TRAIN_BUTTON_VISIBLE = [gr.Button(visible=True), gr.Button(visible=False), gr.Textbox(value=time.time())]


Expand Down Expand Up @@ -669,7 +667,7 @@ def train_model(
"save_state_to_huggingface": save_state_to_huggingface,
"resume_from_huggingface": resume_from_huggingface,
"async_upload": async_upload,
"adaptive_noise_scale": adaptive_noise_scale if adaptive_noise_scale != 0 else None,
"adaptive_noise_scale": adaptive_noise_scale if not 0 else None,
"bucket_no_upscale": bucket_no_upscale,
"bucket_reso_steps": bucket_reso_steps,
"cache_latents": cache_latents,
Expand Down Expand Up @@ -749,7 +747,7 @@ def train_model(
"resume": resume,
"sample_every_n_epochs": sample_every_n_epochs if sample_every_n_epochs != 0 else None,
"sample_every_n_steps": sample_every_n_steps if sample_every_n_steps != 0 else None,
"sample_prompts": create_prompt_file(output_dir, output_dir),
"sample_prompts": create_prompt_file(sample_prompts, output_dir),
"sample_sampler": sample_sampler,
"save_every_n_epochs": save_every_n_epochs if save_every_n_epochs!= 0 else None,
"save_every_n_steps": save_every_n_steps if save_every_n_steps != 0 else None,
Expand Down Expand Up @@ -806,15 +804,7 @@ def train_model(
run_cmd = run_cmd_advanced_training(run_cmd=run_cmd, **kwargs_for_training)

if print_only:
log.warning(
"Here is the trainer command as a reference. It will not be executed:\n"
)
# Reconstruct the safe command string for display
command_to_run = " ".join(run_cmd)

print(command_to_run)

save_to_file(command_to_run)
print_command_and_toml(run_cmd, tmpfilename)
else:
# Saving config file for model
current_datetime = datetime.now()
Expand All @@ -834,7 +824,7 @@ def train_model(

env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
env["TF_ENABLE_ONEDNN_OPTS"] = "0"

Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/extract_lora_from_dylora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def extract_dylora(
save_to = f"{path}_tmp{ext}"

run_cmd = [
PYTHON,
fr'"{PYTHON}"',
rf'"{scriptdir}/sd-scripts/networks/extract_lora_from_dylora.py"',
"--save_to",
rf'"{save_to}"',
Expand All @@ -63,7 +63,7 @@ def extract_dylora(

env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
# Example environment variable adjustment for the Python environment
env["TF_ENABLE_ONEDNN_OPTS"] = "0"
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/extract_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract_lora(
return

run_cmd = [
PYTHON,
fr'"{PYTHON}"',
fr'"{scriptdir}/sd-scripts/networks/extract_lora_from_models.py"',
"--load_precision",
load_precision,
Expand Down Expand Up @@ -112,7 +112,7 @@ def extract_lora(

env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
# Adding an example of another potentially relevant environment variable
env["TF_ENABLE_ONEDNN_OPTS"] = "0"
Expand Down
4 changes: 2 additions & 2 deletions kohya_gui/extract_lycoris_locon_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract_lycoris_locon(
path, ext = os.path.splitext(output_name)
output_name = f"{path}_tmp{ext}"

run_cmd = [PYTHON, fr'"{scriptdir}/tools/lycoris_locon_extract.py"']
run_cmd = [fr'"{PYTHON}"', fr'"{scriptdir}/tools/lycoris_locon_extract.py"']

if is_sdxl:
run_cmd.append("--is_sdxl")
Expand Down Expand Up @@ -127,7 +127,7 @@ def extract_lycoris_locon(

env = os.environ.copy()
env["PYTHONPATH"] = (
rf"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
f"{scriptdir}{os.pathsep}{scriptdir}/sd-scripts{os.pathsep}{env.get('PYTHONPATH', '')}"
)
# Adding an example of an environment variable that might be relevant
env["TF_ENABLE_ONEDNN_OPTS"] = "0"
Expand Down
Loading
Loading