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

Implement LR Warmup disabling when constant scheduler is used #2292

Merged
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ ControlNet dataset is used to specify the mask. The mask images should be the RG
- Added a HuggingFace section to all trainers tabs, enabling users to authenticate and utilize HuggingFace's powerful AI models.
- Converted the Graphical User Interface (GUI) to use the configuration TOML file format to pass arguments to sd-scripts. This change improves security by eliminating the need for sensitive information to be passed through the command-line interface (CLI).
- Made various other minor improvements and bug fixes to enhance the overall functionality and user experience.
- Disabled LR Warmup when using the Constant LR Scheduler to prevent traceback errors with sd-scripts.

### 2024/04/10 (v23.1.5)

Expand Down
27 changes: 27 additions & 0 deletions kohya_gui/class_basic_training.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import gradio as gr
from typing import Tuple
from .custom_logging import setup_logging

# Set up logging
log = setup_logging()

class BasicTraining:
"""
Expand Down Expand Up @@ -44,6 +47,7 @@ def __init__(
self.finetuning = finetuning
self.dreambooth = dreambooth
self.config = config
self.old_lr_warmup = 0

# Initialize the UI components
self.initialize_ui_components()
Expand Down Expand Up @@ -162,6 +166,9 @@ def init_lr_and_optimizer_controls(self) -> None:
],
value=self.config.get("basic.lr_scheduler", self.lr_scheduler_value),
)



# Initialize the optimizer dropdown
self.optimizer = gr.Dropdown(
label="Optimizer",
Expand Down Expand Up @@ -278,6 +285,26 @@ def init_learning_rate_controls(self) -> None:
maximum=100,
step=1,
)

def lr_scheduler_changed(scheduler, value):
if scheduler == "constant":
self.old_lr_warmup = value
value = 0
interactive=False
info="Can't use LR warmup with LR Scheduler constant... setting to 0 and disabling field..."
else:
if self.old_lr_warmup != 0:
value = self.old_lr_warmup
self.old_lr_warmup = 0
interactive=True
info=""
return gr.Slider(value=value, interactive=interactive, info=info)

self.lr_scheduler.change(
lr_scheduler_changed,
inputs=[self.lr_scheduler, self.lr_warmup],
outputs=self.lr_warmup,
)

def init_scheduler_controls(self) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion kohya_gui/class_command_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def execute_command(self, run_cmd: str, **kwargs):

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

# Execute the command securely
self.process = subprocess.Popen(run_cmd, **kwargs)
Expand Down