Skip to content

Commit

Permalink
Reverting all changes for max_train_steps
Browse files Browse the repository at this point in the history
  • Loading branch information
bmaltais committed Nov 19, 2024
1 parent 309a9bb commit d0cd9f5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 45 deletions.
38 changes: 18 additions & 20 deletions kohya_gui/dreambooth_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,8 +654,6 @@ def train_model(
gr.Button(visible=False or headless),
gr.Textbox(value=train_state_value),
]

max_train_steps_info = "Automatic by sd-scripts"

if executor.is_running():
log.error("Training is already running. Can't start another training session.")
Expand Down Expand Up @@ -783,23 +781,23 @@ def train_model(

log.info(f"Regularization factor: {reg_factor}")

# if max_train_steps == 0:
# # calculate max_train_steps
# max_train_steps = int(
# math.ceil(
# float(total_steps)
# / int(train_batch_size)
# / int(gradient_accumulation_steps)
# * int(epoch)
# * int(reg_factor)
# )
# )
# max_train_steps_info = f"max_train_steps ({total_steps} / {train_batch_size} / {gradient_accumulation_steps} * {epoch} * {reg_factor}) = {max_train_steps}"
# else:
# if max_train_steps == 0:
# max_train_steps_info = f"Max train steps: 0. sd-scripts will therefore default to 1600. Please specify a different value if required."
# else:
# max_train_steps_info = f"Max train steps: {max_train_steps}"
if max_train_steps == 0:
# calculate max_train_steps
max_train_steps = int(
math.ceil(
float(total_steps)
/ int(train_batch_size)
/ int(gradient_accumulation_steps)
* int(epoch)
* int(reg_factor)
)
)
max_train_steps_info = f"max_train_steps ({total_steps} / {train_batch_size} / {gradient_accumulation_steps} * {epoch} * {reg_factor}) = {max_train_steps}"
else:
if max_train_steps == 0:
max_train_steps_info = f"Max train steps: 0. sd-scripts will therefore default to 1600. Please specify a different value if required."
else:
max_train_steps_info = f"Max train steps: {max_train_steps}"

log.info(f"Total steps: {total_steps}")

Expand Down Expand Up @@ -1470,4 +1468,4 @@ def dreambooth_tab(
folders.reg_data_dir,
folders.output_dir,
folders.logging_dir,
)
)
24 changes: 11 additions & 13 deletions kohya_gui/finetune_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,6 @@ def train_model(
gr.Button(visible=False or headless),
gr.Textbox(value=train_state_value),
]

max_train_steps_info = "Automatic by sd-scripts"

if executor.is_running():
log.error("Training is already running. Can't start another training session.")
Expand Down Expand Up @@ -848,16 +846,16 @@ def train_model(
repeats = int(image_num) * int(dataset_repeats)
log.info(f"repeats = {str(repeats)}")

# if max_train_steps == 0:
# # calculate max_train_steps
# max_train_steps = int(
# math.ceil(
# float(repeats)
# / int(train_batch_size)
# / int(gradient_accumulation_steps)
# * int(epoch)
# )
# )
if max_train_steps == 0:
# calculate max_train_steps
max_train_steps = int(
math.ceil(
float(repeats)
/ int(train_batch_size)
/ int(gradient_accumulation_steps)
* int(epoch)
)
)

# Divide by two because flip augmentation create two copied of the source images
if flip_aug and max_train_steps:
Expand Down Expand Up @@ -1634,4 +1632,4 @@ def list_presets(path):
if os.path.exists(top_level_path):
with open(os.path.join(top_level_path), "r", encoding="utf-8") as file:
guides_top_level = file.read() + "\n"
gr.Markdown(guides_top_level)
gr.Markdown(guides_top_level)
16 changes: 9 additions & 7 deletions kohya_gui/lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,6 @@ def train_model(
gr.Button(visible=False or headless),
gr.Textbox(value=train_state_value),
]

max_train_steps_info = "Automatic by sd-scripts"

if executor.is_running():
log.error("Training is already running. Can't start another training session.")
Expand Down Expand Up @@ -1078,7 +1076,7 @@ def train_model(

log.info(f"Regularization factor: {reg_factor}")

if (max_train_steps == 0) and (stop_text_encoder_training != 0):
if max_train_steps == 0:
# calculate max_train_steps
max_train_steps = int(
math.ceil(
Expand All @@ -1096,9 +1094,13 @@ def train_model(
else:
max_train_steps_info = f"Max train steps: {max_train_steps}"

stop_text_encoder_training = math.ceil(
float(max_train_steps) / 100 * int(stop_text_encoder_training)
) if stop_text_encoder_training != 0 else 0
# calculate stop encoder training
if stop_text_encoder_training == 0:
stop_text_encoder_training = 0
else:
stop_text_encoder_training = math.ceil(
float(max_train_steps) / 100 * int(stop_text_encoder_training)
)

# Calculate lr_warmup_steps
if lr_warmup_steps > 0:
Expand Down Expand Up @@ -2855,4 +2857,4 @@ def update_LoRA_settings(
folders.reg_data_dir,
folders.output_dir,
folders.logging_dir,
)
)
25 changes: 20 additions & 5 deletions kohya_gui/textual_inversion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,6 @@ def train_model(
gr.Textbox(value=train_state_value),
]

max_train_steps_info = "Automatic by sd-scripts"

if executor.is_running():
log.error("Training is already running. Can't start another training session.")
return TRAIN_BUTTON_VISIBLE
Expand Down Expand Up @@ -666,9 +664,22 @@ def train_model(
log.info(f"Regularization factor: {reg_factor}")

if max_train_steps == 0:
max_train_steps_info = f"Max train steps: 0. sd-scripts will therefore default to 1600. Please specify a different value if required."
# calculate max_train_steps
max_train_steps = int(
math.ceil(
float(total_steps)
/ int(train_batch_size)
/ int(gradient_accumulation_steps)
* int(epoch)
* int(reg_factor)
)
)
max_train_steps_info = f"max_train_steps ({total_steps} / {train_batch_size} / {gradient_accumulation_steps} * {epoch} * {reg_factor}) = {max_train_steps}"
else:
max_train_steps_info = f"Max train steps: {max_train_steps}"
if max_train_steps == 0:
max_train_steps_info = f"Max train steps: 0. sd-scripts will therefore default to 1600. Please specify a different value if required."
else:
max_train_steps_info = f"Max train steps: {max_train_steps}"

# calculate stop encoder training
if stop_text_encoder_training_pct == 0:
Expand Down Expand Up @@ -1065,6 +1076,10 @@ def list_embedding_files(path):
step=1,
label="Vectors",
)
# max_train_steps = gr.Textbox(
# label='Max train steps',
# placeholder='(Optional) Maximum number of steps',
# )
template = gr.Dropdown(
label="Template",
choices=[
Expand Down Expand Up @@ -1294,4 +1309,4 @@ def list_embedding_files(path):
folders.reg_data_dir,
folders.output_dir,
folders.logging_dir,
)
)

0 comments on commit d0cd9f5

Please sign in to comment.