Add linux support

This commit is contained in:
bmaltais 2023-03-04 18:56:22 -05:00
parent f903753989
commit 3beeef4414
18 changed files with 211 additions and 63 deletions

View File

@ -176,6 +176,9 @@ This will store your a backup file with your current locally installed pip packa
## Change History ## Change History
* 2023/03/04 (v21.1.3):
- Fix progress bar being displayed when not required.
- Add support for linux, thank you @devNegative-asm
* 2023/03/03 (v21.1.2): * 2023/03/03 (v21.1.2):
- Fix issue https://github.com/bmaltais/kohya_ss/issues/277 - Fix issue https://github.com/bmaltais/kohya_ss/issues/277
- Fix issue https://github.com/bmaltais/kohya_ss/issues/278 introduce by LoCon project switching to pip module. Make sure to run upgrade.ps1 to install the latest pip requirements for LoCon support. - Fix issue https://github.com/bmaltais/kohya_ss/issues/278 introduce by LoCon project switching to pip module. Make sure to run upgrade.ps1 to install the latest pip requirements for LoCon support.

View File

@ -25,7 +25,7 @@ from library.common_gui import (
gradio_config, gradio_config,
gradio_source_model, gradio_source_model,
set_legacy_8bitadam, set_legacy_8bitadam,
my_data, update_my_data,
) )
from library.tensorboard_gui import ( from library.tensorboard_gui import (
gradio_tensorboard, gradio_tensorboard,
@ -214,7 +214,7 @@ def open_configuration(
my_data = json.load(f) my_data = json.load(f)
print('Loading config...') print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True # Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data) my_data = update_my_data(my_data)
else: else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data = {} my_data = {}
@ -500,7 +500,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
train_data_dir_input_folder.click( train_data_dir_input_folder.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
reg_data_dir = gr.Textbox( reg_data_dir = gr.Textbox(
label='Regularisation folder', label='Regularisation folder',
@ -510,7 +512,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
reg_data_dir_input_folder.click( reg_data_dir_input_folder.click(
get_folder_path, outputs=reg_data_dir get_folder_path,
outputs=reg_data_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_dir = gr.Textbox( output_dir = gr.Textbox(
@ -529,7 +533,9 @@ def dreambooth_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
logging_dir_input_folder.click( logging_dir_input_folder.click(
get_folder_path, outputs=logging_dir get_folder_path,
outputs=logging_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_name = gr.Textbox( output_name = gr.Textbox(
@ -610,7 +616,11 @@ def dreambooth_tab(
placeholder='(Optiona) path to checkpoint of vae to replace for training', placeholder='(Optiona) path to checkpoint of vae to replace for training',
) )
vae_button = gr.Button('📂', elem_id='open_folder_small') vae_button = gr.Button('📂', elem_id='open_folder_small')
vae_button.click(get_any_file_path, outputs=vae) vae_button.click(
get_any_file_path,
outputs=vae,
show_progress=False,
)
( (
use_8bit_adam, use_8bit_adam,
xformers, xformers,
@ -664,10 +674,12 @@ def dreambooth_tab(
button_start_tensorboard.click( button_start_tensorboard.click(
start_tensorboard, start_tensorboard,
inputs=logging_dir, inputs=logging_dir,
show_progress=False,
) )
button_stop_tensorboard.click( button_stop_tensorboard.click(
stop_tensorboard, stop_tensorboard,
show_progress=False,
) )
settings_list = [ settings_list = [
@ -730,23 +742,27 @@ def dreambooth_tab(
open_configuration, open_configuration,
inputs=[config_file_name] + settings_list, inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list, outputs=[config_file_name] + settings_list,
show_progress=False,
) )
button_save_config.click( button_save_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_false, config_file_name] + settings_list, inputs=[dummy_db_false, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_save_as_config.click( button_save_as_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_true, config_file_name] + settings_list, inputs=[dummy_db_true, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_run.click( button_run.click(
train_model, train_model,
inputs=settings_list, inputs=settings_list,
show_progress=False,
) )
return ( return (

View File

@ -19,7 +19,7 @@ from library.common_gui import (
color_aug_changed, color_aug_changed,
run_cmd_training, run_cmd_training,
set_legacy_8bitadam, set_legacy_8bitadam,
my_data, update_my_data,
) )
from library.tensorboard_gui import ( from library.tensorboard_gui import (
gradio_tensorboard, gradio_tensorboard,
@ -33,7 +33,8 @@ refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄 document_symbol = '\U0001F4C4' # 📄
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe' PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def save_configuration( def save_configuration(
save_as, save_as,
@ -217,7 +218,7 @@ def open_config_file(
my_data_db = json.load(f) my_data_db = json.load(f)
print('Loading config...') print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True # Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data) my_data = update_my_data(my_data)
else: else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data_db = {} my_data_db = {}
@ -296,9 +297,7 @@ def train_model(
if not os.path.exists(train_dir): if not os.path.exists(train_dir):
os.mkdir(train_dir) os.mkdir(train_dir)
run_cmd = ( run_cmd = f'{PYTHON} finetune/merge_captions_to_metadata.py'
f'{PYTHON} finetune/merge_captions_to_metadata.py'
)
if caption_extension == '': if caption_extension == '':
run_cmd += f' --caption_extension=".caption"' run_cmd += f' --caption_extension=".caption"'
else: else:
@ -315,9 +314,7 @@ def train_model(
# create images buckets # create images buckets
if generate_image_buckets: if generate_image_buckets:
run_cmd = ( run_cmd = f'{PYTHON} finetune/prepare_buckets_latents.py'
f'{PYTHON} finetune/prepare_buckets_latents.py'
)
run_cmd += f' "{image_folder}"' run_cmd += f' "{image_folder}"'
run_cmd += f' "{train_dir}/{caption_metadata_filename}"' run_cmd += f' "{train_dir}/{caption_metadata_filename}"'
run_cmd += f' "{train_dir}/{latent_metadata_filename}"' run_cmd += f' "{train_dir}/{latent_metadata_filename}"'
@ -491,7 +488,11 @@ def finetune_tab():
train_dir_folder = gr.Button( train_dir_folder = gr.Button(
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
train_dir_folder.click(get_folder_path, outputs=train_dir) train_dir_folder.click(
get_folder_path,
outputs=train_dir,
show_progress=False,
)
image_folder = gr.Textbox( image_folder = gr.Textbox(
label='Training Image folder', label='Training Image folder',
@ -501,7 +502,9 @@ def finetune_tab():
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
image_folder_input_folder.click( image_folder_input_folder.click(
get_folder_path, outputs=image_folder get_folder_path,
outputs=image_folder,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_dir = gr.Textbox( output_dir = gr.Textbox(
@ -511,7 +514,11 @@ def finetune_tab():
output_dir_input_folder = gr.Button( output_dir_input_folder = gr.Button(
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
output_dir_input_folder.click(get_folder_path, outputs=output_dir) output_dir_input_folder.click(
get_folder_path,
outputs=output_dir,
show_progress=False,
)
logging_dir = gr.Textbox( logging_dir = gr.Textbox(
label='Logging folder', label='Logging folder',
@ -521,7 +528,9 @@ def finetune_tab():
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
logging_dir_input_folder.click( logging_dir_input_folder.click(
get_folder_path, outputs=logging_dir get_folder_path,
outputs=logging_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_name = gr.Textbox( output_name = gr.Textbox(
@ -655,6 +664,7 @@ def finetune_tab():
button_stop_tensorboard.click( button_stop_tensorboard.click(
stop_tensorboard, stop_tensorboard,
show_progress=False,
) )
settings_list = [ settings_list = [
@ -725,18 +735,21 @@ def finetune_tab():
open_config_file, open_config_file,
inputs=[config_file_name] + settings_list, inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list, outputs=[config_file_name] + settings_list,
show_progress=False,
) )
button_save_config.click( button_save_config.click(
save_configuration, save_configuration,
inputs=[dummy_ft_false, config_file_name] + settings_list, inputs=[dummy_ft_false, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_save_as_config.click( button_save_as_config.click(
save_configuration, save_configuration,
inputs=[dummy_ft_true, config_file_name] + settings_list, inputs=[dummy_ft_true, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )

View File

@ -4,6 +4,7 @@ import subprocess
from .common_gui import get_folder_path, add_pre_postfix, find_replace from .common_gui import get_folder_path, add_pre_postfix, find_replace
import os import os
def caption_images( def caption_images(
caption_text_input, caption_text_input,
images_dir_input, images_dir_input,
@ -85,7 +86,9 @@ def gradio_basic_caption_gui_tab():
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_images_dir_input.click( button_images_dir_input.click(
get_folder_path, outputs=images_dir_input get_folder_path,
outputs=images_dir_input,
show_progress=False,
) )
caption_file_ext = gr.Textbox( caption_file_ext = gr.Textbox(
label='Caption file extension', label='Caption file extension',
@ -139,4 +142,5 @@ def gradio_basic_caption_gui_tab():
find, find,
replace, replace,
], ],
show_progress=False,
) )

View File

@ -3,7 +3,9 @@ from easygui import msgbox
import subprocess import subprocess
import os import os
from .common_gui import get_folder_path, add_pre_postfix from .common_gui import get_folder_path, add_pre_postfix
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def caption_images( def caption_images(
train_data_dir, train_data_dir,
@ -81,7 +83,9 @@ def gradio_blip_caption_gui_tab():
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_train_data_dir_input.click( button_train_data_dir_input.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
caption_file_ext = gr.Textbox( caption_file_ext = gr.Textbox(
@ -138,4 +142,5 @@ def gradio_blip_caption_gui_tab():
prefix, prefix,
postfix, postfix,
], ],
show_progress=False,
) )

View File

@ -10,11 +10,11 @@ save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄 document_symbol = '\U0001F4C4' # 📄
def my_data(my_data): def update_my_data(my_data):
if my_data.get('use_8bit_adam', False): if my_data.get('use_8bit_adam', False):
my_data['optimizer'] = 'AdamW8bit' my_data['optimizer'] = 'AdamW8bit'
my_data['use_8bit_adam'] = False my_data['use_8bit_adam'] = False
if my_data.get('model_list', 'custom') == []: if my_data.get('model_list', 'custom') == []:
print('Old config with empty model list. Setting to custom...') print('Old config with empty model list. Setting to custom...')
my_data['model_list'] = 'custom' my_data['model_list'] = 'custom'
@ -276,7 +276,9 @@ def save_inference_file(output_dir, v2, v_parameterization, output_name):
) )
def set_pretrained_model_name_or_path_input(model_list, pretrained_model_name_or_path, v2, v_parameterization): def set_pretrained_model_name_or_path_input(
model_list, pretrained_model_name_or_path, v2, v_parameterization
):
# define a list of substrings to search for # define a list of substrings to search for
substrings_v2 = [ substrings_v2 = [
'stabilityai/stable-diffusion-2-1-base', 'stabilityai/stable-diffusion-2-1-base',
@ -320,7 +322,12 @@ def set_pretrained_model_name_or_path_input(model_list, pretrained_model_name_or
return model_list, v2, v_parameterization return model_list, v2, v_parameterization
if model_list == 'custom': if model_list == 'custom':
if str(pretrained_model_name_or_path) in substrings_v1_model or str(pretrained_model_name_or_path) in substrings_v2 or str(pretrained_model_name_or_path) in substrings_v_parameterization: if (
str(pretrained_model_name_or_path) in substrings_v1_model
or str(pretrained_model_name_or_path) in substrings_v2
or str(pretrained_model_name_or_path)
in substrings_v_parameterization
):
pretrained_model_name_or_path = '' pretrained_model_name_or_path = ''
v2 = False v2 = False
v_parameterization = False v_parameterization = False
@ -359,7 +366,7 @@ def gradio_source_model():
pretrained_model_name_or_path = gr.Textbox( pretrained_model_name_or_path = gr.Textbox(
label='Pretrained model name or path', label='Pretrained model name or path',
placeholder='enter the path to custom model or name of pretrained model', placeholder='enter the path to custom model or name of pretrained model',
value='runwayml/stable-diffusion-v1-5' value='runwayml/stable-diffusion-v1-5',
) )
pretrained_model_name_or_path_file = gr.Button( pretrained_model_name_or_path_file = gr.Button(
document_symbol, elem_id='open_folder_small' document_symbol, elem_id='open_folder_small'
@ -368,6 +375,7 @@ def gradio_source_model():
get_any_file_path, get_any_file_path,
inputs=pretrained_model_name_or_path, inputs=pretrained_model_name_or_path,
outputs=pretrained_model_name_or_path, outputs=pretrained_model_name_or_path,
show_progress=False,
) )
pretrained_model_name_or_path_folder = gr.Button( pretrained_model_name_or_path_folder = gr.Button(
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
@ -376,6 +384,7 @@ def gradio_source_model():
get_folder_path, get_folder_path,
inputs=pretrained_model_name_or_path, inputs=pretrained_model_name_or_path,
outputs=pretrained_model_name_or_path, outputs=pretrained_model_name_or_path,
show_progress=False,
) )
model_list = gr.Dropdown( model_list = gr.Dropdown(
label='Model Quick Pick', label='Model Quick Pick',
@ -388,7 +397,7 @@ def gradio_source_model():
'runwayml/stable-diffusion-v1-5', 'runwayml/stable-diffusion-v1-5',
'CompVis/stable-diffusion-v1-4', 'CompVis/stable-diffusion-v1-4',
], ],
value='runwayml/stable-diffusion-v1-5' value='runwayml/stable-diffusion-v1-5',
) )
save_model_as = gr.Dropdown( save_model_as = gr.Dropdown(
label='Save trained model as', label='Save trained model as',
@ -409,7 +418,12 @@ def gradio_source_model():
) )
model_list.change( model_list.change(
set_pretrained_model_name_or_path_input, set_pretrained_model_name_or_path_input,
inputs=[model_list, pretrained_model_name_or_path, v2, v_parameterization], inputs=[
model_list,
pretrained_model_name_or_path,
v2,
v_parameterization,
],
outputs=[ outputs=[
pretrained_model_name_or_path, pretrained_model_name_or_path,
v2, v2,
@ -661,7 +675,11 @@ def gradio_advanced_training():
placeholder='path to "last-state" state folder to resume from', placeholder='path to "last-state" state folder to resume from',
) )
resume_button = gr.Button('📂', elem_id='open_folder_small') resume_button = gr.Button('📂', elem_id='open_folder_small')
resume_button.click(get_folder_path, outputs=resume) resume_button.click(
get_folder_path,
outputs=resume,
show_progress=False,
)
max_train_epochs = gr.Textbox( max_train_epochs = gr.Textbox(
label='Max train epoch', label='Max train epoch',
placeholder='(Optional) Override number of epoch', placeholder='(Optional) Override number of epoch',

View File

@ -9,7 +9,8 @@ folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄 refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄 document_symbol = '\U0001F4C4' # 📄
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe' PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def convert_model( def convert_model(
source_model_input, source_model_input,
@ -166,7 +167,9 @@ def gradio_convert_model_tab():
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
button_source_model_dir.click( button_source_model_dir.click(
get_folder_path, outputs=source_model_input get_folder_path,
outputs=source_model_input,
show_progress=False,
) )
button_source_model_file = gr.Button( button_source_model_file = gr.Button(
@ -176,6 +179,7 @@ def gradio_convert_model_tab():
get_file_path, get_file_path,
inputs=[source_model_input], inputs=[source_model_input],
outputs=source_model_input, outputs=source_model_input,
show_progress=False,
) )
source_model_type = gr.Dropdown( source_model_type = gr.Dropdown(
@ -199,7 +203,9 @@ def gradio_convert_model_tab():
folder_symbol, elem_id='open_folder_small' folder_symbol, elem_id='open_folder_small'
) )
button_target_model_folder.click( button_target_model_folder.click(
get_folder_path, outputs=target_model_folder_input get_folder_path,
outputs=target_model_folder_input,
show_progress=False,
) )
target_model_name_input = gr.Textbox( target_model_name_input = gr.Textbox(
@ -234,4 +240,5 @@ def gradio_convert_model_tab():
target_model_type, target_model_type,
target_save_precision_type, target_save_precision_type,
], ],
show_progress=False,
) )

View File

@ -118,7 +118,9 @@ def gradio_dataset_balancing_tab():
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
select_dataset_folder_button.click( select_dataset_folder_button.click(
get_folder_path, outputs=select_dataset_folder_input get_folder_path,
outputs=select_dataset_folder_input,
show_progress=False,
) )
total_repeats_number = gr.Number( total_repeats_number = gr.Number(
@ -140,4 +142,5 @@ def gradio_dataset_balancing_tab():
select_dataset_folder_input, select_dataset_folder_input,
insecure, insecure,
], ],
show_progress=False,
) )

View File

@ -140,7 +140,9 @@ def gradio_dreambooth_folder_creation_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_util_training_images_dir_input.click( button_util_training_images_dir_input.click(
get_folder_path, outputs=util_training_images_dir_input get_folder_path,
outputs=util_training_images_dir_input,
show_progress=False,
) )
util_training_images_repeat_input = gr.Number( util_training_images_repeat_input = gr.Number(
label='Repeats', label='Repeats',
@ -158,7 +160,9 @@ def gradio_dreambooth_folder_creation_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_util_regularization_images_dir_input.click( button_util_regularization_images_dir_input.click(
get_folder_path, outputs=util_regularization_images_dir_input get_folder_path,
outputs=util_regularization_images_dir_input,
show_progress=False,
) )
util_regularization_images_repeat_input = gr.Number( util_regularization_images_repeat_input = gr.Number(
label='Repeats', label='Repeats',
@ -190,6 +194,7 @@ def gradio_dreambooth_folder_creation_tab(
util_class_prompt_input, util_class_prompt_input,
util_training_dir_output, util_training_dir_output,
], ],
show_progress=False,
) )
button_copy_info_to_Folders_tab = gr.Button('Copy info to Folders Tab') button_copy_info_to_Folders_tab = gr.Button('Copy info to Folders Tab')
button_copy_info_to_Folders_tab.click( button_copy_info_to_Folders_tab.click(
@ -201,4 +206,5 @@ def gradio_dreambooth_folder_creation_tab(
output_dir_input, output_dir_input,
logging_dir_input, logging_dir_input,
], ],
show_progress=False,
) )

View File

@ -12,7 +12,8 @@ folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄 refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄 document_symbol = '\U0001F4C4' # 📄
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe' PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def extract_lora( def extract_lora(
model_tuned, model_tuned,
@ -85,6 +86,7 @@ def gradio_extract_lora_tab():
get_file_path, get_file_path,
inputs=[model_tuned, model_ext, model_ext_name], inputs=[model_tuned, model_ext, model_ext_name],
outputs=model_tuned, outputs=model_tuned,
show_progress=False,
) )
model_org = gr.Textbox( model_org = gr.Textbox(
@ -99,6 +101,7 @@ def gradio_extract_lora_tab():
get_file_path, get_file_path,
inputs=[model_org, model_ext, model_ext_name], inputs=[model_org, model_ext, model_ext_name],
outputs=model_org, outputs=model_org,
show_progress=False,
) )
with gr.Row(): with gr.Row():
save_to = gr.Textbox( save_to = gr.Textbox(
@ -113,6 +116,7 @@ def gradio_extract_lora_tab():
get_saveasfilename_path, get_saveasfilename_path,
inputs=[save_to, lora_ext, lora_ext_name], inputs=[save_to, lora_ext, lora_ext_name],
outputs=save_to, outputs=save_to,
show_progress=False,
) )
save_precision = gr.Dropdown( save_precision = gr.Dropdown(
label='Save precision', label='Save precision',
@ -136,4 +140,5 @@ def gradio_extract_lora_tab():
extract_button.click( extract_button.click(
extract_lora, extract_lora,
inputs=[model_tuned, model_org, save_to, save_precision, dim, v2], inputs=[model_tuned, model_org, save_to, save_precision, dim, v2],
show_progress=False,
) )

View File

@ -3,7 +3,9 @@ from easygui import msgbox
import subprocess import subprocess
import os import os
from .common_gui import get_folder_path, add_pre_postfix from .common_gui import get_folder_path, add_pre_postfix
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def caption_images( def caption_images(
train_data_dir, train_data_dir,
@ -73,7 +75,9 @@ def gradio_git_caption_gui_tab():
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_train_data_dir_input.click( button_train_data_dir_input.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
caption_ext = gr.Textbox( caption_ext = gr.Textbox(
@ -126,4 +130,5 @@ def gradio_git_caption_gui_tab():
prefix, prefix,
postfix, postfix,
], ],
show_progress=False,
) )

View File

@ -12,7 +12,8 @@ folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄 refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
document_symbol = '\U0001F4C4' # 📄 document_symbol = '\U0001F4C4' # 📄
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe' PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
def merge_lora( def merge_lora(
lora_a_model, lora_a_model,
@ -81,6 +82,7 @@ def gradio_merge_lora_tab():
get_file_path, get_file_path,
inputs=[lora_a_model, lora_ext, lora_ext_name], inputs=[lora_a_model, lora_ext, lora_ext_name],
outputs=lora_a_model, outputs=lora_a_model,
show_progress=False,
) )
lora_b_model = gr.Textbox( lora_b_model = gr.Textbox(
@ -95,6 +97,7 @@ def gradio_merge_lora_tab():
get_file_path, get_file_path,
inputs=[lora_b_model, lora_ext, lora_ext_name], inputs=[lora_b_model, lora_ext, lora_ext_name],
outputs=lora_b_model, outputs=lora_b_model,
show_progress=False,
) )
with gr.Row(): with gr.Row():
ratio = gr.Slider( ratio = gr.Slider(
@ -119,6 +122,7 @@ def gradio_merge_lora_tab():
get_saveasfilename_path, get_saveasfilename_path,
inputs=[save_to, lora_ext, lora_ext_name], inputs=[save_to, lora_ext, lora_ext_name],
outputs=save_to, outputs=save_to,
show_progress=False,
) )
precision = gr.Dropdown( precision = gr.Dropdown(
label='Merge precision', label='Merge precision',
@ -145,4 +149,5 @@ def gradio_merge_lora_tab():
precision, precision,
save_precision, save_precision,
], ],
show_progress=False,
) )

View File

@ -3,7 +3,8 @@ from easygui import msgbox
import subprocess import subprocess
import os import os
from .common_gui import get_saveasfilename_path, get_file_path from .common_gui import get_saveasfilename_path, get_file_path
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
folder_symbol = '\U0001f4c2' # 📂 folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄 refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
@ -68,6 +69,7 @@ def gradio_resize_lora_tab():
get_file_path, get_file_path,
inputs=[model, lora_ext, lora_ext_name], inputs=[model, lora_ext, lora_ext_name],
outputs=model, outputs=model,
show_progress=False,
) )
with gr.Row(): with gr.Row():
new_rank = gr.Slider( new_rank = gr.Slider(
@ -92,6 +94,7 @@ def gradio_resize_lora_tab():
get_saveasfilename_path, get_saveasfilename_path,
inputs=[save_to, lora_ext, lora_ext_name], inputs=[save_to, lora_ext, lora_ext_name],
outputs=save_to, outputs=save_to,
show_progress=False,
) )
save_precision = gr.Dropdown( save_precision = gr.Dropdown(
label='Save precision', label='Save precision',
@ -116,4 +119,5 @@ def gradio_resize_lora_tab():
save_precision, save_precision,
device, device,
], ],
show_progress=False,
) )

View File

@ -5,7 +5,8 @@ import subprocess
import time import time
tensorboard_proc = None # I know... bad but heh tensorboard_proc = None # I know... bad but heh
TENSORBOARD = "tensorboard" if os.name == 'posix' else 'tensorboard.exe' TENSORBOARD = 'tensorboard' if os.name == 'posix' else 'tensorboard.exe'
def start_tensorboard(logging_dir): def start_tensorboard(logging_dir):
global tensorboard_proc global tensorboard_proc

View File

@ -7,7 +7,8 @@ from .common_gui import (
get_any_file_path, get_any_file_path,
get_file_path, get_file_path,
) )
PYTHON = "python3" if os.name == 'posix' else './venv/Scripts/python.exe'
PYTHON = 'python3' if os.name == 'posix' else './venv/Scripts/python.exe'
folder_symbol = '\U0001f4c2' # 📂 folder_symbol = '\U0001f4c2' # 📂
refresh_symbol = '\U0001f504' # 🔄 refresh_symbol = '\U0001f504' # 🔄
save_style_symbol = '\U0001f4be' # 💾 save_style_symbol = '\U0001f4be' # 💾
@ -29,11 +30,11 @@ def verify_lora(
run_cmd = [ run_cmd = [
PYTHON, PYTHON,
os.path.join("networks","check_lora_weights.py"), os.path.join('networks', 'check_lora_weights.py'),
f'{lora_model}' f'{lora_model}',
] ]
print(" ".join(run_cmd)) print(' '.join(run_cmd))
# Run the command # Run the command
process = subprocess.Popen( process = subprocess.Popen(
@ -71,6 +72,7 @@ def gradio_verify_lora_tab():
get_file_path, get_file_path,
inputs=[lora_model, lora_ext, lora_ext_name], inputs=[lora_model, lora_ext, lora_ext_name],
outputs=lora_model, outputs=lora_model,
show_progress=False,
) )
verify_button = gr.Button('Verify', variant='primary') verify_button = gr.Button('Verify', variant='primary')
@ -96,4 +98,5 @@ def gradio_verify_lora_tab():
lora_model, lora_model,
], ],
outputs=[lora_model_verif_output, lora_model_verif_error], outputs=[lora_model_verif_output, lora_model_verif_error],
show_progress=False,
) )

View File

@ -56,7 +56,9 @@ def gradio_wd14_caption_gui_tab():
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
button_train_data_dir_input.click( button_train_data_dir_input.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
caption_extension = gr.Textbox( caption_extension = gr.Textbox(
@ -76,4 +78,5 @@ def gradio_wd14_caption_gui_tab():
caption_button.click( caption_button.click(
caption_images, caption_images,
inputs=[train_data_dir, caption_extension, batch_size, thresh], inputs=[train_data_dir, caption_extension, batch_size, thresh],
show_progress=False,
) )

View File

@ -25,7 +25,7 @@ from library.common_gui import (
gradio_source_model, gradio_source_model,
run_cmd_training, run_cmd_training,
set_legacy_8bitadam, set_legacy_8bitadam,
my_data, update_my_data,
) )
from library.dreambooth_folder_creation_gui import ( from library.dreambooth_folder_creation_gui import (
gradio_dreambooth_folder_creation_tab, gradio_dreambooth_folder_creation_tab,
@ -239,7 +239,7 @@ def open_configuration(
my_data = json.load(f) my_data = json.load(f)
print('Loading config...') print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True # Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data) my_data = update_my_data(my_data)
else: else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data = {} my_data = {}
@ -462,7 +462,9 @@ def train_model(
try: try:
import locon.locon_kohya import locon.locon_kohya
except ModuleNotFoundError: except ModuleNotFoundError:
print("\033[1;31mError:\033[0m The required module 'locon' is not installed. Please install by running \033[33mupgrade.ps1\033[0m before running this program.") print(
"\033[1;31mError:\033[0m The required module 'locon' is not installed. Please install by running \033[33mupgrade.ps1\033[0m before running this program."
)
return return
run_cmd += f' --network_module=locon.locon_kohya' run_cmd += f' --network_module=locon.locon_kohya'
run_cmd += ( run_cmd += (
@ -588,27 +590,41 @@ def lora_tab(
) )
train_data_dir_folder = gr.Button('📂', elem_id='open_folder_small') train_data_dir_folder = gr.Button('📂', elem_id='open_folder_small')
train_data_dir_folder.click( train_data_dir_folder.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
reg_data_dir = gr.Textbox( reg_data_dir = gr.Textbox(
label='Regularisation folder', label='Regularisation folder',
placeholder='(Optional) Folder where where the regularization folders containing the images are located', placeholder='(Optional) Folder where where the regularization folders containing the images are located',
) )
reg_data_dir_folder = gr.Button('📂', elem_id='open_folder_small') reg_data_dir_folder = gr.Button('📂', elem_id='open_folder_small')
reg_data_dir_folder.click(get_folder_path, outputs=reg_data_dir) reg_data_dir_folder.click(
get_folder_path,
outputs=reg_data_dir,
show_progress=False,
)
with gr.Row(): with gr.Row():
output_dir = gr.Textbox( output_dir = gr.Textbox(
label='Output folder', label='Output folder',
placeholder='Folder to output trained model', placeholder='Folder to output trained model',
) )
output_dir_folder = gr.Button('📂', elem_id='open_folder_small') output_dir_folder = gr.Button('📂', elem_id='open_folder_small')
output_dir_folder.click(get_folder_path, outputs=output_dir) output_dir_folder.click(
get_folder_path,
outputs=output_dir,
show_progress=False,
)
logging_dir = gr.Textbox( logging_dir = gr.Textbox(
label='Logging folder', label='Logging folder',
placeholder='Optional: enable logging and output TensorBoard log to this folder', placeholder='Optional: enable logging and output TensorBoard log to this folder',
) )
logging_dir_folder = gr.Button('📂', elem_id='open_folder_small') logging_dir_folder = gr.Button('📂', elem_id='open_folder_small')
logging_dir_folder.click(get_folder_path, outputs=logging_dir) logging_dir_folder.click(
get_folder_path,
outputs=logging_dir,
show_progress=False,
)
with gr.Row(): with gr.Row():
output_name = gr.Textbox( output_name = gr.Textbox(
label='Model output name', label='Model output name',
@ -662,6 +678,7 @@ def lora_tab(
get_any_file_path, get_any_file_path,
inputs=[lora_network_weights], inputs=[lora_network_weights],
outputs=lora_network_weights, outputs=lora_network_weights,
show_progress=False,
) )
( (
learning_rate, learning_rate,
@ -736,7 +753,7 @@ def lora_tab(
return gr.Group.update(visible=True) return gr.Group.update(visible=True)
else: else:
return gr.Group.update(visible=False) return gr.Group.update(visible=False)
LoRA_type.change( LoRA_type.change(
LoRA_type_change, inputs=[LoRA_type], outputs=[LoCon_row] LoRA_type_change, inputs=[LoRA_type], outputs=[LoCon_row]
) )
@ -834,10 +851,12 @@ def lora_tab(
button_start_tensorboard.click( button_start_tensorboard.click(
start_tensorboard, start_tensorboard,
inputs=logging_dir, inputs=logging_dir,
show_progress=False,
) )
button_stop_tensorboard.click( button_stop_tensorboard.click(
stop_tensorboard, stop_tensorboard,
show_progress=False,
) )
settings_list = [ settings_list = [
@ -910,23 +929,27 @@ def lora_tab(
open_configuration, open_configuration,
inputs=[config_file_name] + settings_list, inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list + [LoCon_row], outputs=[config_file_name] + settings_list + [LoCon_row],
show_progress=False,
) )
button_save_config.click( button_save_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_false, config_file_name] + settings_list, inputs=[dummy_db_false, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_save_as_config.click( button_save_as_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_true, config_file_name] + settings_list, inputs=[dummy_db_true, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_run.click( button_run.click(
train_model, train_model,
inputs=settings_list, inputs=settings_list,
show_progress=False,
) )
return ( return (

View File

@ -25,7 +25,7 @@ from library.common_gui import (
gradio_config, gradio_config,
gradio_source_model, gradio_source_model,
set_legacy_8bitadam, set_legacy_8bitadam,
my_data, update_my_data,
) )
from library.tensorboard_gui import ( from library.tensorboard_gui import (
gradio_tensorboard, gradio_tensorboard,
@ -226,7 +226,7 @@ def open_configuration(
my_data_db = json.load(f) my_data_db = json.load(f)
print('Loading config...') print('Loading config...')
# Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True # Update values to fix deprecated use_8bit_adam checkbox and set appropriate optimizer if it is set to True
my_data = my_data(my_data) my_data = update_my_data(my_data)
else: else:
file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action file_path = original_file_path # In case a file_path was provided and the user decide to cancel the open action
my_data_db = {} my_data_db = {}
@ -542,7 +542,9 @@ def ti_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
train_data_dir_input_folder.click( train_data_dir_input_folder.click(
get_folder_path, outputs=train_data_dir get_folder_path,
outputs=train_data_dir,
show_progress=False,
) )
reg_data_dir = gr.Textbox( reg_data_dir = gr.Textbox(
label='Regularisation folder', label='Regularisation folder',
@ -552,7 +554,9 @@ def ti_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
reg_data_dir_input_folder.click( reg_data_dir_input_folder.click(
get_folder_path, outputs=reg_data_dir get_folder_path,
outputs=reg_data_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_dir = gr.Textbox( output_dir = gr.Textbox(
@ -562,7 +566,11 @@ def ti_tab(
output_dir_input_folder = gr.Button( output_dir_input_folder = gr.Button(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
output_dir_input_folder.click(get_folder_path, outputs=output_dir) output_dir_input_folder.click(
get_folder_path,
outputs=output_dir,
show_progress=False,
)
logging_dir = gr.Textbox( logging_dir = gr.Textbox(
label='Logging folder', label='Logging folder',
placeholder='Optional: enable logging and output TensorBoard log to this folder', placeholder='Optional: enable logging and output TensorBoard log to this folder',
@ -571,7 +579,9 @@ def ti_tab(
'📂', elem_id='open_folder_small' '📂', elem_id='open_folder_small'
) )
logging_dir_input_folder.click( logging_dir_input_folder.click(
get_folder_path, outputs=logging_dir get_folder_path,
outputs=logging_dir,
show_progress=False,
) )
with gr.Row(): with gr.Row():
output_name = gr.Textbox( output_name = gr.Textbox(
@ -607,7 +617,11 @@ def ti_tab(
placeholder='(Optional) Path to existing TI embeding file to keep training', placeholder='(Optional) Path to existing TI embeding file to keep training',
) )
weights_file_input = gr.Button('📂', elem_id='open_folder_small') weights_file_input = gr.Button('📂', elem_id='open_folder_small')
weights_file_input.click(get_file_path, outputs=weights) weights_file_input.click(
get_file_path,
outputs=weights,
show_progress=False,
)
with gr.Row(): with gr.Row():
token_string = gr.Textbox( token_string = gr.Textbox(
label='Token string', label='Token string',
@ -688,7 +702,11 @@ def ti_tab(
placeholder='(Optiona) path to checkpoint of vae to replace for training', placeholder='(Optiona) path to checkpoint of vae to replace for training',
) )
vae_button = gr.Button('📂', elem_id='open_folder_small') vae_button = gr.Button('📂', elem_id='open_folder_small')
vae_button.click(get_any_file_path, outputs=vae) vae_button.click(
get_any_file_path,
outputs=vae,
show_progress=False,
)
( (
use_8bit_adam, use_8bit_adam,
xformers, xformers,
@ -742,10 +760,12 @@ def ti_tab(
button_start_tensorboard.click( button_start_tensorboard.click(
start_tensorboard, start_tensorboard,
inputs=logging_dir, inputs=logging_dir,
show_progress=False,
) )
button_stop_tensorboard.click( button_stop_tensorboard.click(
stop_tensorboard, stop_tensorboard,
show_progress=False,
) )
settings_list = [ settings_list = [
@ -814,23 +834,27 @@ def ti_tab(
open_configuration, open_configuration,
inputs=[config_file_name] + settings_list, inputs=[config_file_name] + settings_list,
outputs=[config_file_name] + settings_list, outputs=[config_file_name] + settings_list,
show_progress=False,
) )
button_save_config.click( button_save_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_false, config_file_name] + settings_list, inputs=[dummy_db_false, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_save_as_config.click( button_save_as_config.click(
save_configuration, save_configuration,
inputs=[dummy_db_true, config_file_name] + settings_list, inputs=[dummy_db_true, config_file_name] + settings_list,
outputs=[config_file_name], outputs=[config_file_name],
show_progress=False,
) )
button_run.click( button_run.click(
train_model, train_model,
inputs=settings_list, inputs=settings_list,
show_progress=False,
) )
return ( return (