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

add missing nonlocal scope keywords #2042

Merged
merged 2 commits into from
Mar 9, 2024
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
2 changes: 2 additions & 0 deletions kohya_gui/class_advanced_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def noise_offset_type_change(noise_offset_type):
)

def list_vae_files(path):
nonlocal current_vae_dir
current_vae_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

Expand Down Expand Up @@ -299,6 +300,7 @@ def full_options_update(full_fp16, full_bf16):
)

def list_state_dirs(path):
nonlocal current_state_dir
current_state_dir = path
return list(list_dirs(path))

Expand Down
2 changes: 2 additions & 0 deletions kohya_gui/convert_lcm_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ def gradio_convert_lcm_tab(headless=False):
current_save_dir = os.path.join(scriptdir, "outputs")

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".safetensors"], all=True))

Expand Down
2 changes: 2 additions & 0 deletions kohya_gui/convert_model_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,12 @@ def gradio_convert_model_tab(headless=False):
current_target_folder = default_target_folder

def list_source_model(path):
nonlocal current_source_model
current_source_model = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_target_folder(path):
nonlocal current_target_folder
current_target_folder = path
return list(list_dirs(path))

Expand Down
1 change: 1 addition & 0 deletions kohya_gui/dataset_balancing_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def gradio_dataset_balancing_tab(headless=False):
with gr.Group(), gr.Row():

def list_dataset_dirs(path):
nonlocal current_dataset_dir
current_dataset_dir = path
return list(list_dirs(path))

Expand Down
3 changes: 3 additions & 0 deletions kohya_gui/dreambooth_folder_creation_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def gradio_dreambooth_folder_creation_tab(
with gr.Group(), gr.Row():

def list_train_data_dirs(path):
nonlocal current_train_data_dir
current_train_data_dir = path
return list(list_dirs(path))

Expand Down Expand Up @@ -182,6 +183,7 @@ def list_train_data_dirs(path):

with gr.Group(), gr.Row():
def list_reg_data_dirs(path):
nonlocal current_reg_data_dir
current_reg_data_dir = path
return list(list_dirs(path))

Expand Down Expand Up @@ -215,6 +217,7 @@ def list_reg_data_dirs(path):
)
with gr.Group(), gr.Row():
def list_train_output_dirs(path):
nonlocal current_train_output_dir
current_train_output_dir = path
return list(list_dirs(path))

Expand Down
2 changes: 2 additions & 0 deletions kohya_gui/extract_lora_from_dylora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ def gradio_extract_dylora_tab(headless=False):
lora_ext_name = gr.Textbox(value='LoRA model types', visible=False)

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

Expand Down
3 changes: 3 additions & 0 deletions kohya_gui/extract_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ def gradio_extract_lora_tab(headless=False):
current_save_dir = os.path.join(scriptdir, "outputs")

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_org_models(path):
nonlocal current_model_org_dir
current_model_org_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

Expand Down
5 changes: 4 additions & 1 deletion kohya_gui/extract_lycoris_locon_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,17 @@ def gradio_extract_lycoris_locon_tab(headless=False):
current_save_dir = os.path.join(scriptdir, "outputs")

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_base_models(path):
current_model_org_dir = path
nonlocal current_base_model_dir
current_base_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".safetensors"], all=True))

Expand Down
1 change: 1 addition & 0 deletions kohya_gui/git_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def gradio_git_caption_gui_tab(headless=False, default_train_dir=None):
current_train_dir = default_train_dir

def list_train_dirs(path):
nonlocal current_train_dir
current_train_dir = path
return list(list_dirs(path))

Expand Down
2 changes: 2 additions & 0 deletions kohya_gui/group_images_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ def gradio_group_images_gui_tab(headless=False):
current_output_folder = os.path.join(scriptdir, "data")

def list_input_dirs(path):
nonlocal current_input_folder
current_input_folder = path
return list(list_dirs(path))

def list_output_dirs(path):
nonlocal current_output_folder
current_output_folder = path
return list(list_dirs(path))

Expand Down
6 changes: 6 additions & 0 deletions kohya_gui/merge_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,32 @@ def build_tab(self):
current_d_model_dir = current_sd_model_dir

def list_sd_models(path):
nonlocal current_sd_model_dir
current_sd_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_a_models(path):
nonlocal current_a_model_dir
current_a_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_b_models(path):
nonlocal current_b_model_dir
current_b_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_c_models(path):
nonlocal current_c_model_dir
current_c_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_d_models(path):
nonlocal current_d_model_dir
current_d_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

Expand Down
3 changes: 3 additions & 0 deletions kohya_gui/merge_lycoris_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ def gradio_merge_lycoris_tab(headless=False):
current_save_dir = current_model_dir

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_lycoris_model(path):
nonlocal current_lycoris_dir
current_lycoris_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

Expand Down
2 changes: 2 additions & 0 deletions kohya_gui/resize_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ def gradio_resize_lora_tab(headless=False):
current_save_dir = os.path.join(scriptdir, "outputs")

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".ckpt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

Expand Down
5 changes: 5 additions & 0 deletions kohya_gui/svd_merge_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,27 @@ def gradio_svd_merge_lora_tab(headless=False):
current_d_model_dir = current_save_dir

def list_a_models(path):
nonlocal current_a_model_dir
current_a_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_b_models(path):
nonlocal current_b_model_dir
current_b_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_c_models(path):
nonlocal current_c_model_dir
current_c_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_d_models(path):
nonlocal current_d_model_dir
current_d_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

def list_save_to(path):
nonlocal current_save_dir
current_save_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

Expand Down
1 change: 1 addition & 0 deletions kohya_gui/textual_inversion_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def ti_tab(
with gr.Row():

def list_embedding_files(path):
nonlocal current_embedding_dir
current_embedding_dir = path
return list(list_files(path, exts=[".pt", ".ckpt", ".safetensors" ], all=True))

Expand Down
1 change: 1 addition & 0 deletions kohya_gui/verify_lora_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def gradio_verify_lora_tab(headless=False):
current_model_dir = os.path.join(scriptdir, "outputs")

def list_models(path):
nonlocal current_model_dir
current_model_dir = path
return list(list_files(path, exts=[".pt", ".safetensors"], all=True))

Expand Down
1 change: 1 addition & 0 deletions kohya_gui/wd14_caption_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def gradio_wd14_caption_gui_tab(headless=False, default_train_dir=None):
current_train_dir = default_train_dir

def list_train_dirs(path):
nonlocal current_train_dir
current_train_dir = path
return list(list_dirs(path))

Expand Down
2 changes: 1 addition & 1 deletion setup/setup_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def main_menu():
"3. (Optional) Force installation of bitsandbytes 0.41.1 for new optimizer options support"
)
print(
"4. (Recommanded) Force installation of bitsandbytes 0.41.2 for new optimizer options support"
"4. (Recommended) Force installation of bitsandbytes 0.41.2 for new optimizer options support"
)
print(
"5. (Danger) Install bitsandbytes-windows (this package has been reported to cause issues for most... avoid...)"
Expand Down