-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdearpygui_train_ui.py
More file actions
1360 lines (1163 loc) · 55.3 KB
/
dearpygui_train_ui.py
File metadata and controls
1360 lines (1163 loc) · 55.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Prototype implementation of OneTrainer UI using Dear PyGui instead of CustomTkinter
This file follows the structure of the original TrainUI.py file but uses Dear PyGui
"""
import json
import os
import threading
import traceback
import webbrowser
from collections.abc import Callable
from pathlib import Path
import sys
# Add current directory to Python path to ensure imports work
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Dear PyGui
import dearpygui.dearpygui as dpg
# Try importing modules from original codebase
try:
from modules.util.config.TrainConfig import TrainConfig
from modules.util.config.SampleConfig import SampleConfig
from modules.trainer.GenericTrainer import GenericTrainer
from modules.trainer.CloudTrainer import CloudTrainer
from modules.util.callbacks.TrainCallbacks import TrainCallbacks
from modules.util.commands.TrainCommands import TrainCommands
from modules.util.enum.DataType import DataType
from modules.util.enum.ImageFormat import ImageFormat
from modules.util.enum.ModelType import ModelType
from modules.util.enum.TrainingMethod import TrainingMethod
from modules.util.torch_util import torch_gc
from modules.util.TrainProgress import TrainProgress
from modules.zluda import ZLUDA
HAS_MODULES = True
except ImportError:
# Mock for testing without original modules
print("Warning: Original modules not found. Using mock classes for testing.")
from dataclasses import dataclass
@dataclass
class TrainConfig:
@staticmethod
def default_values():
return TrainConfig()
@dataclass
class UIState:
def __init__(self, master, config):
self.master = master
self.config = config
def get_var(self, var_name):
return UIVar()
class UIVar:
def __init__(self):
self.value = ""
def set(self, value):
self.value = value
def get(self):
return self.value
def trace_add(self, *args, **kwargs):
pass
# Mock classes
ModelType = type('ModelType', (), {})
TrainingMethod = type('TrainingMethod', (), {})
HAS_MODULES = False
class DPGUIState:
"""State management class similar to UIState from the original codebase, but for Dear PyGui"""
def __init__(self, train_config):
"""Initialize state with reference to train_config"""
self.train_config = train_config
self.vars = {}
self.callback_registry = {}
self.callback_count = 0
def register_var(self, var_name, initial_value=None):
"""Register a variable in the state system"""
# Create registry entry if needed
if var_name not in self.vars:
self.vars[var_name] = {
"value": initial_value,
"callbacks": {}
}
return var_name
def get_var_value(self, var_name):
"""Get the current value of a variable"""
if var_name in self.vars:
return self.vars[var_name]["value"]
return None
def set_var_value(self, var_name, value, trigger_callbacks=True):
"""Set the value of a variable and trigger callbacks if needed"""
if var_name not in self.vars:
self.register_var(var_name, value)
else:
self.vars[var_name]["value"] = value
# Trigger callbacks if requested
if trigger_callbacks:
for callback_id, callback in self.vars[var_name]["callbacks"].items():
try:
callback(value)
except Exception as e:
print(f"Error in callback for {var_name}: {e}")
traceback.print_exc()
def add_var_callback(self, var_name, callback):
"""Add a callback to be triggered when a variable changes"""
if var_name not in self.vars:
self.register_var(var_name)
callback_id = self.callback_count
self.callback_count += 1
self.vars[var_name]["callbacks"][callback_id] = callback
return callback_id
def remove_var_callback(self, var_name, callback_id):
"""Remove a callback from a variable"""
if var_name in self.vars and callback_id in self.vars[var_name]["callbacks"]:
del self.vars[var_name]["callbacks"][callback_id]
def update_from_config(self, config):
"""Update state values from a config object"""
# Similar to the update method in the original UIState
pass
class DearPyGuiComponents:
"""Helper class to create UI components consistently"""
@staticmethod
def label(parent, text, tag=None, tooltip=None, **kwargs):
"""Create a label with optional tooltip"""
tag = tag or f"label_{dpg.generate_uuid()}"
dpg.add_text(text, parent=parent, tag=tag, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def button(parent, text, callback=None, tag=None, tooltip=None, width=120, height=30, **kwargs):
"""Create a button with optional tooltip"""
tag = tag or f"button_{dpg.generate_uuid()}"
dpg.add_button(label=text, callback=callback, parent=parent,
tag=tag, width=width, height=height, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def input_text(parent, default_value="", callback=None, tag=None, tooltip=None, width=200, **kwargs):
"""Create a text input field with optional tooltip"""
tag = tag or f"input_{dpg.generate_uuid()}"
dpg.add_input_text(default_value=default_value, callback=callback,
parent=parent, tag=tag, width=width, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def checkbox(parent, label, default_value=False, callback=None, tag=None, tooltip=None, **kwargs):
"""Create a checkbox with optional tooltip"""
tag = tag or f"checkbox_{dpg.generate_uuid()}"
dpg.add_checkbox(label=label, default_value=default_value,
callback=callback, parent=parent, tag=tag, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def combo(parent, items, default_value=None, callback=None, tag=None, tooltip=None, width=200, **kwargs):
"""Create a dropdown with optional tooltip"""
tag = tag or f"combo_{dpg.generate_uuid()}"
if default_value is None and items:
default_value = items[0]
dpg.add_combo(items=items, default_value=default_value,
callback=callback, parent=parent, tag=tag, width=width, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def slider_float(parent, default_value=0.0, min_value=0.0, max_value=1.0,
callback=None, tag=None, tooltip=None, width=200, **kwargs):
"""Create a floating point slider with optional tooltip"""
tag = tag or f"slider_{dpg.generate_uuid()}"
dpg.add_slider_float(default_value=default_value, min_value=min_value, max_value=max_value,
callback=callback, parent=parent, tag=tag, width=width, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def slider_int(parent, default_value=0, min_value=0, max_value=100,
callback=None, tag=None, tooltip=None, width=200, **kwargs):
"""Create an integer slider with optional tooltip"""
tag = tag or f"slider_{dpg.generate_uuid()}"
dpg.add_slider_int(default_value=default_value, min_value=min_value, max_value=max_value,
callback=callback, parent=parent, tag=tag, width=width, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def file_selector(parent, directory_selector=False, callback=None,
default_path="", tag=None, tooltip=None, width=200, **kwargs):
"""Create a file dialog opener with a text field and button"""
tag = tag or f"file_selector_{dpg.generate_uuid()}"
# Create a group to hold the components
group_tag = f"{tag}_group"
dpg.add_group(horizontal=True, parent=parent, tag=group_tag)
# Text input for the path
input_tag = f"{tag}_input"
dpg.add_input_text(default_value=default_path, parent=group_tag, tag=input_tag, width=width-50, **kwargs)
# Create the file dialog
dialog_tag = f"{tag}_dialog"
if directory_selector:
dpg.add_file_dialog(tag=dialog_tag, directory_selector=True, show=False,
callback=lambda s, a, u: dpg.set_value(input_tag, a["file_path_name"]))
else:
dpg.add_file_dialog(tag=dialog_tag, show=False,
callback=lambda s, a, u: dpg.set_value(input_tag, a["file_path_name"]))
# Button to open dialog
button_tag = f"{tag}_button"
dpg.add_button(label="...", parent=group_tag, tag=button_tag, width=30, height=23,
callback=lambda: dpg.show_item(dialog_tag))
if tooltip:
with dpg.tooltip(parent=input_tag):
dpg.add_text(tooltip)
return {
"group": group_tag,
"input": input_tag,
"button": button_tag,
"dialog": dialog_tag
}
@staticmethod
def progress_bar(parent, default_value=0.0, tag=None, tooltip=None, width=200, **kwargs):
"""Create a progress bar with optional tooltip"""
tag = tag or f"progress_{dpg.generate_uuid()}"
dpg.add_progress_bar(default_value=default_value, parent=parent, tag=tag, width=width, **kwargs)
if tooltip:
with dpg.tooltip(parent=tag):
dpg.add_text(tooltip)
return tag
@staticmethod
def tab_bar(parent, tag=None, **kwargs):
"""Create a tab bar container"""
tag = tag or f"tab_bar_{dpg.generate_uuid()}"
return dpg.add_tab_bar(parent=parent, tag=tag, **kwargs)
@staticmethod
def tab(parent, label, tag=None, **kwargs):
"""Create a tab within a tab bar"""
tag = tag or f"tab_{label}_{dpg.generate_uuid()}"
return dpg.add_tab(label=label, parent=parent, tag=tag, **kwargs)
@staticmethod
def menu_bar(parent, tag=None, **kwargs):
"""Create a menu bar"""
tag = tag or f"menu_bar_{dpg.generate_uuid()}"
return dpg.add_menu_bar(parent=parent, tag=tag, **kwargs)
@staticmethod
def menu(parent, label, tag=None, **kwargs):
"""Create a menu within a menu bar"""
tag = tag or f"menu_{dpg.generate_uuid()}"
return dpg.add_menu(label=label, parent=parent, tag=tag, **kwargs)
@staticmethod
def menu_item(parent, label, callback=None, tag=None, **kwargs):
"""Create a menu item"""
tag = tag or f"menu_item_{dpg.generate_uuid()}"
return dpg.add_menu_item(label=label, callback=callback, parent=parent, tag=tag, **kwargs)
class DearPyGuiTrainUI:
"""Main UI class using Dear PyGui instead of CustomTkinter"""
def __init__(self):
"""Initialize Dear PyGui and create the main window"""
# Initialize Dear PyGui
dpg.create_context()
dpg.create_viewport(title="OneTrainer", width=1280, height=800)
# Set up the DPG configuration
with dpg.font_registry():
# Add default font
default_font = dpg.add_font("resources/fonts/OpenSans-Regular.ttf", 16) if os.path.exists("resources/fonts/OpenSans-Regular.ttf") else None
if default_font:
dpg.bind_font(default_font)
with dpg.theme() as global_theme:
with dpg.theme_component(dpg.mvAll):
# Theme similar to CustomTkinter dark-blue
dpg.add_theme_color(dpg.mvThemeCol_WindowBg, [26, 27, 38, 255]) # Dark blue background
dpg.add_theme_color(dpg.mvThemeCol_TitleBg, [32, 34, 48, 255]) # Title bar
dpg.add_theme_color(dpg.mvThemeCol_TitleBgActive, [39, 41, 57, 255]) # Active title
dpg.add_theme_color(dpg.mvThemeCol_Button, [41, 83, 154, 255]) # Buttons (blue)
dpg.add_theme_color(dpg.mvThemeCol_ButtonHovered, [59, 113, 202, 255]) # Buttons hovered
dpg.add_theme_color(dpg.mvThemeCol_ButtonActive, [66, 127, 227, 255]) # Buttons active
dpg.add_theme_color(dpg.mvThemeCol_FrameBg, [37, 38, 51, 255]) # Frame background
dpg.add_theme_color(dpg.mvThemeCol_CheckMark, [41, 83, 154, 255]) # Checkboxes
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarBg, [30, 31, 41, 255]) # Scrollbar bg
dpg.add_theme_color(dpg.mvThemeCol_ScrollbarGrab, [41, 83, 154, 255]) # Scrollbar
dpg.add_theme_color(dpg.mvThemeCol_Header, [41, 83, 154, 255]) # Headers
# Add spacing to match CustomTkinter look
dpg.add_theme_style(dpg.mvStyleVar_FramePadding, [8, 5])
dpg.add_theme_style(dpg.mvStyleVar_ItemSpacing, [8, 5])
dpg.add_theme_style(dpg.mvStyleVar_WindowPadding, [10, 10])
dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 4.0) # Rounded corners
dpg.add_theme_style(dpg.mvStyleVar_GrabRounding, 4.0) # Rounded corners
dpg.bind_theme(global_theme)
# Create train configuration if modules are available
if HAS_MODULES:
self.train_config = TrainConfig.default_values()
self.ui_state = DPGUIState(self.train_config)
else:
# Mock objects for testing
self.train_config = TrainConfig()
self.ui_state = DPGUIState(self.train_config)
# Create windows and UI elements
self.setup_primary_window()
# Training attributes
self.training_thread = None
self.training_callbacks = None
self.training_commands = None
# Start the viewport
dpg.setup_dearpygui()
dpg.show_viewport()
def setup_primary_window(self):
"""Create the main window layout"""
# Create the main window
with dpg.window(tag="primary_window", label="OneTrainer", no_title_bar=True, no_resize=False,
no_move=False, no_close=False, no_collapse=False, no_scrollbar=True):
# Layout with top bar, main area and bottom bar
with dpg.group(horizontal=False):
# Top bar (app title, config selector, model selection)
self.create_top_bar()
# Main content area with tabs
self.create_tabs_content()
# Bottom bar (progress bars, status, buttons)
self.create_bottom_bar()
def create_top_bar(self):
"""Create the top bar with logo, preset selector and model type selection"""
with dpg.group(horizontal=True, tag="top_bar"):
# App title and logo (left side)
with dpg.group(horizontal=True):
# Logo would go here
DearPyGuiComponents.label(parent="top_bar", text="OneTrainer", tag="app_title")
# Config/preset selection
with dpg.group(horizontal=True):
configs = [("Default Config", "#.json")] # Would be populated from available configs
# Config dropdown - wide for better preset names visibility
DearPyGuiComponents.combo(
parent="top_bar",
items=[name for name, _ in configs],
default_value=configs[0][0] if configs else "",
callback=self.load_config,
tag="config_selector",
width=350
)
# Save config button
DearPyGuiComponents.button(
parent="top_bar",
text="Save Config",
callback=self.save_config,
tooltip="Save the current configuration as a preset"
)
# Wiki button
DearPyGuiComponents.button(
parent="top_bar",
text="Wiki",
callback=lambda: webbrowser.open("https://github.com/Nerogar/OneTrainer/wiki", new=0, autoraise=False),
tooltip="Open OneTrainer Wiki"
)
# Flexible space
dpg.add_spacer(width=20)
# Model type selection (right side)
with dpg.group(horizontal=True):
model_types = [
"Stable Diffusion 1.5",
"Stable Diffusion 1.5 Inpainting",
"Stable Diffusion 2.0",
"Stable Diffusion 2.0 Inpainting",
"Stable Diffusion 2.1",
"Stable Diffusion 3",
"Stable Diffusion 3.5",
"Stable Diffusion XL 1.0 Base",
"Stable Diffusion XL 1.0 Base Inpainting",
"Wuerstchen v2",
"Stable Cascade",
"PixArt Alpha",
"PixArt Sigma",
"Flux Dev",
"Flux Fill Dev",
"Sana",
"Hunyuan Video",
"HiDream Full"
]
DearPyGuiComponents.combo(
parent="top_bar",
items=model_types,
default_value=model_types[0],
callback=self.change_model_type,
tag="model_type_selector",
width=250
)
# Training method selection
training_methods = ["Fine Tune", "LoRA", "Embedding"]
DearPyGuiComponents.combo(
parent="top_bar",
items=training_methods,
default_value=training_methods[0],
callback=self.change_training_method,
tag="training_method_selector",
width=120
)
def create_tabs_content(self):
"""Create the tabbed content area"""
with dpg.child_window(tag="main_content", height=-40, no_scrollbar=True):
tab_bar = DearPyGuiComponents.tab_bar(parent="main_content", tag="main_tabs")
# General tab
self.create_general_tab(DearPyGuiComponents.tab(tab_bar, "General", tag="general_tab"))
# Model tab
self.create_model_tab(DearPyGuiComponents.tab(tab_bar, "Model", tag="model_tab"))
# Data tab
self.create_data_tab(DearPyGuiComponents.tab(tab_bar, "Data", tag="data_tab"))
# Concepts tab
self.create_concepts_tab(DearPyGuiComponents.tab(tab_bar, "Concepts", tag="concepts_tab"))
# Training tab
self.create_training_tab(DearPyGuiComponents.tab(tab_bar, "Training", tag="training_tab"))
# Sampling tab
self.create_sampling_tab(DearPyGuiComponents.tab(tab_bar, "Sampling", tag="sampling_tab"))
# Backup tab
self.create_backup_tab(DearPyGuiComponents.tab(tab_bar, "Backup", tag="backup_tab"))
# Tools tab
self.create_tools_tab(DearPyGuiComponents.tab(tab_bar, "Tools", tag="tools_tab"))
# Additional embeddings tab
self.create_additional_embeddings_tab(DearPyGuiComponents.tab(tab_bar, "Additional Embeddings", tag="additional_embeddings_tab"))
# Cloud tab
self.create_cloud_tab(DearPyGuiComponents.tab(tab_bar, "Cloud", tag="cloud_tab"))
# If training method is LoRA, add LoRA tab
self.create_lora_tab(DearPyGuiComponents.tab(tab_bar, "LoRA", tag="lora_tab"))
def create_bottom_bar(self):
"""Create the bottom bar with progress indicators and action buttons"""
with dpg.group(horizontal=True, tag="bottom_bar"):
# Progress indicators
with dpg.group(horizontal=False, width=400):
# Step progress
DearPyGuiComponents.label(parent="bottom_bar", text="Step Progress", tag="step_progress_label")
self.step_progress_bar = DearPyGuiComponents.progress_bar(
parent="bottom_bar",
default_value=0.0,
tag="step_progress_bar",
width=390
)
# Epoch progress
DearPyGuiComponents.label(parent="bottom_bar", text="Epoch Progress", tag="epoch_progress_label")
self.epoch_progress_bar = DearPyGuiComponents.progress_bar(
parent="bottom_bar",
default_value=0.0,
tag="epoch_progress_bar",
width=390
)
# Status label
self.status_label = DearPyGuiComponents.label(
parent="bottom_bar",
text="Ready",
tag="status_label"
)
# Flexible space
dpg.add_spacer(width=20)
# Action buttons
DearPyGuiComponents.button(
parent="bottom_bar",
text="Tensorboard",
callback=self.open_tensorboard,
tooltip="Open TensorBoard visualization"
)
self.training_button = DearPyGuiComponents.button(
parent="bottom_bar",
text="Start Training",
callback=self.start_training,
tooltip="Start or stop the training process"
)
DearPyGuiComponents.button(
parent="bottom_bar",
text="Export",
callback=self.export_training,
tooltip="Export the current configuration as a script to run without a UI"
)
def create_general_tab(self, parent):
"""Create the general tab content"""
with dpg.group(parent=parent, horizontal=False):
with dpg.collapsing_header(label="Workspace Settings", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Workspace Directory",
tooltip="The directory where all files of this training run are saved"
)
workspace_selector = DearPyGuiComponents.file_selector(
parent=dpg.last_item(),
directory_selector=True,
default_path="./workspace",
tooltip="The directory where all files of this training run are saved",
width=400
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Cache Directory",
tooltip="The directory where cached data is saved"
)
cache_selector = DearPyGuiComponents.file_selector(
parent=dpg.last_item(),
directory_selector=True,
default_path="./cache",
tooltip="The directory where cached data is saved",
width=400
)
with dpg.collapsing_header(label="Training Options", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Continue from last backup",
tooltip="Automatically continues training from the last backup saved in <workspace>/backup"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Only Cache",
tooltip="Only populate the cache, without any training"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Debug mode",
tooltip="Save debug information during the training into the debug directory"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Debug Directory",
tooltip="The directory where debug data is saved"
)
debug_selector = DearPyGuiComponents.file_selector(
parent=dpg.last_item(),
directory_selector=True,
default_path="./debug",
tooltip="The directory where debug data is saved",
width=400
)
with dpg.collapsing_header(label="Tensorboard Options", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Tensorboard",
tooltip="Starts the Tensorboard Web UI during training"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Expose Tensorboard",
tooltip="Exposes Tensorboard Web UI to all network interfaces (makes it accessible from the network)"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Tensorboard Port",
tooltip="Port to use for Tensorboard link"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="6006",
width=100
)
with dpg.collapsing_header(label="Device Settings", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Dataloader Threads",
tooltip="Number of threads used for the data loader"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="4",
width=100
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Train Device",
tooltip="The device used for training. Can be \"cuda\", \"cuda:0\", \"cuda:1\" etc. Default:\"cuda\""
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="cuda",
width=100
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Temp Device",
tooltip="The device used to temporarily offload models while they are not used. Default:\"cpu\""
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="cpu",
width=100
)
def create_model_tab(self, parent):
"""Create the model tab content"""
# This is a simplification - would need to be dynamic based on model type
with dpg.group(parent=parent):
with dpg.collapsing_header(label="Model Settings", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Base Model",
tooltip="The base model to train on"
)
base_model_selector = DearPyGuiComponents.file_selector(
parent=dpg.last_item(),
directory_selector=False,
tooltip="The base model to train on",
width=400
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Output Model",
tooltip="The destination to save the output model to"
)
output_model_selector = DearPyGuiComponents.file_selector(
parent=dpg.last_item(),
directory_selector=True,
tooltip="The destination to save the output model to",
width=400
)
def create_data_tab(self, parent):
"""Create the data tab content"""
with dpg.group(parent=parent):
with dpg.collapsing_header(label="Data Processing Options", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Aspect Ratio Bucketing",
tooltip="Aspect ratio bucketing enables training on images with different aspect ratios"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Latent Caching",
tooltip="Caching of intermediate training data that can be re-used between epochs"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Clear cache before training",
tooltip="Clears the cache directory before starting to train"
)
def create_concepts_tab(self, parent):
"""Create the concepts tab content"""
with dpg.group(parent=parent):
# This would be much more complex in practice,
# involving a table for concepts and buttons to add/edit/remove them
with dpg.group(horizontal=True):
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Add Concept",
callback=self.add_concept
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Edit Selected",
callback=self.edit_concept
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Remove Selected",
callback=self.remove_concept
)
# Placeholder for concept list
with dpg.group():
DearPyGuiComponents.label(parent=dpg.last_item(), text="No concepts defined")
def create_training_tab(self, parent):
"""Create the training tab content"""
with dpg.group(parent=parent):
with dpg.collapsing_header(label="Training Parameters", default_open=True):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Training Method",
tooltip="The method used for training"
)
DearPyGuiComponents.combo(
parent=dpg.last_item(),
items=["LORA", "Embedding", "Fine-tune", "Fine-tune VAE"],
default_value="LORA",
width=200
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Resolution",
tooltip="The resolution used for training"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="512x512",
width=100
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Batch Size",
tooltip="The batch size used for training"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="1",
width=100
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Epochs",
tooltip="The number of epochs to train for"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="10",
width=100
)
def create_sampling_tab(self, parent):
"""Create the sampling tab content"""
with dpg.group(parent=parent):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Sample After",
tooltip="The interval used when automatically sampling from the model during training"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="500",
width=100
)
DearPyGuiComponents.combo(
parent=dpg.last_item(),
items=["STEPS", "EPOCHS"],
default_value="STEPS",
width=100
)
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Skip First",
tooltip="Start sampling automatically after this interval has elapsed"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="0",
width=50
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Sample Now",
callback=self.sample_now
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Manual Sample",
callback=self.open_sample_ui
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Non-EMA Sampling",
tooltip="Whether to include non-ema sampling when using ema"
)
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Samples to Tensorboard",
tooltip="Whether to include sample images in the Tensorboard output"
)
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Sample at Startup",
tooltip="Whether to generate samples when the model is loaded, before training begins"
)
# Sample configurations would be displayed in a table below
with dpg.group():
DearPyGuiComponents.label(parent=dpg.last_item(), text="No sample configurations defined")
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Add Sample Config",
callback=self.add_sample_config
)
def create_backup_tab(self, parent):
"""Create the backup tab content"""
with dpg.group(parent=parent):
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Backup After",
tooltip="The interval used when automatically creating model backups during training"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="5000",
width=100
)
DearPyGuiComponents.combo(
parent=dpg.last_item(),
items=["STEPS", "EPOCHS", "MINUTES", "HOURS"],
default_value="STEPS",
width=100
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Backup Now",
callback=self.backup_now
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Rolling Backup",
tooltip="If rolling backups are enabled, older backups are deleted automatically"
)
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Rolling Backup Count",
tooltip="Defines the number of backups to keep if rolling backups are enabled"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="5",
width=50
)
with dpg.group(horizontal=True):
DearPyGuiComponents.checkbox(
parent=dpg.last_item(),
label="Backup Before Save",
tooltip="Create a full backup before saving the final model"
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Save Every",
tooltip="The interval used when automatically saving the model during training"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),
default_value="10000",
width=100
)
DearPyGuiComponents.combo(
parent=dpg.last_item(),
items=["STEPS", "EPOCHS", "MINUTES", "HOURS"],
default_value="STEPS",
width=100
)
DearPyGuiComponents.button(
parent=dpg.last_item(),
text="Save Now",
callback=self.save_now
)
with dpg.group(horizontal=True):
DearPyGuiComponents.label(
parent=dpg.last_item(),
text="Skip First",
tooltip="Start saving automatically after this interval has elapsed"
)
DearPyGuiComponents.input_text(
parent=dpg.last_item(),