Spaces:
Build error
Build error
Julian Bilcke commited on
Commit ·
2a0dc25
1
Parent(s): edf0515
cleaning code
Browse filesFiles changed (4)
- vms/config.py+116-89
- vms/services/trainer.py+90-47
- vms/tabs/train_tab.py+153-177
- vms/ui/video_trainer_ui.py+79-43
57 unmodified lines5859606162636465662 unmodified lines69707172737412 unmodified lines878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241253 unmodified lines1291301311321331341351361371381391401411421431441451461471 unmodified line1491501511521531541551561571581591601611621631641651661671681691701711721 unmodified line1741751761771781791801811821831841851861871881891901911921931942 unmodified lines1971981992002012022032042052062 unmodified lines20921021121221321421521621721825 unmodified lines2442452462472482492506 unmodified lines25725825926026126226326426526626726826927027127227 unmodified lines3003013023033043053063073083093103113123133147 unmodified lines3223233243253263273283293303313323333343353367 unmodified lines3443453463473483493503513523533543553567 unmodified lines3643653663673683693702 unmodified lines37337437537637737837948 unmodified lines42842943043143243343457 unmodified lines# Expanded model types to include Wan-2.1-T2VMODEL_TYPES = {"HunyuanVideo (LoRA)": "hunyuan_video","LTX-Video (LoRA)": "ltx_video","Wan-2.1-T2V (LoRA)": "wan"}# Training types2 unmodified lines"Full Finetune": "full-finetune"}# it is best to use resolutions that are powers of 8# The resolution should be divisible by 3212 unmodified linesNB_FRAMES_1 = 1 # 1NB_FRAMES_9 = 8 + 1 # 8 + 1NB_FRAMES_17 = 8 * 2 + 1 # 16 + 1NB_FRAMES_32 = 8 * 4 + 1 # 32 + 1NB_FRAMES_48 = 8 * 6 + 1 # 48 + 1NB_FRAMES_64 = 8 * 8 + 1 # 64 + 1NB_FRAMES_80 = 8 * 10 + 1 # 80 + 1NB_FRAMES_96 = 8 * 12 + 1 # 96 + 1NB_FRAMES_112 = 8 * 14 + 1 # 112 + 1NB_FRAMES_128 = 8 * 16 + 1 # 128 + 1NB_FRAMES_144 = 8 * 18 + 1 # 144 + 1NB_FRAMES_160 = 8 * 20 + 1 # 160 + 1NB_FRAMES_176 = 8 * 22 + 1 # 176 + 1NB_FRAMES_192 = 8 * 24 + 1 # 192 + 1NB_FRAMES_224 = 8 * 28 + 1 # 224 + 1NB_FRAMES_256 = 8 * 32 + 1 # 256 + 1# 256 isn't a lot by the way, especially with 60 FPS videos..# can we crank it and put more frames in here?SMALL_TRAINING_BUCKETS = [(NB_FRAMES_1, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 1(NB_FRAMES_9, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 8 + 1(NB_FRAMES_17, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 16 + 1(NB_FRAMES_32, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 32 + 1(NB_FRAMES_48, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 48 + 1(NB_FRAMES_64, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 64 + 1(NB_FRAMES_80, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 80 + 1(NB_FRAMES_96, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 96 + 1(NB_FRAMES_112, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 112 + 1(NB_FRAMES_128, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 128 + 1(NB_FRAMES_144, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 144 + 1(NB_FRAMES_160, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 160 + 1(NB_FRAMES_176, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 176 + 1(NB_FRAMES_192, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 192 + 1(NB_FRAMES_224, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 224 + 1(NB_FRAMES_256, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 256 + 1]MEDIUM_19_9_RATIO_WIDTH = 928 # 32 * 293 unmodified lines(NB_FRAMES_1, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 1(NB_FRAMES_9, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 8 + 1(NB_FRAMES_17, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 16 + 1(NB_FRAMES_32, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 32 + 1(NB_FRAMES_48, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 48 + 1(NB_FRAMES_64, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 64 + 1(NB_FRAMES_80, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 80 + 1(NB_FRAMES_96, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 96 + 1(NB_FRAMES_112, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 112 + 1(NB_FRAMES_128, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 128 + 1(NB_FRAMES_144, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 144 + 1(NB_FRAMES_160, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 160 + 1(NB_FRAMES_176, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 176 + 1(NB_FRAMES_192, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 192 + 1(NB_FRAMES_224, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 224 + 1(NB_FRAMES_256, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 256 + 1]# Updated training presets to include Wan-2.1-T2V and support both LoRA and full-finetune1 unmodified line"HunyuanVideo (normal)": {"model_type": "hunyuan_video","training_type": "lora","lora_rank": "128","lora_alpha": "128","num_epochs": 70,"batch_size": 1,"learning_rate": 2e-5,"save_iterations": 500,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "none"},"LTX-Video (normal)": {"model_type": "ltx_video","training_type": "lora","lora_rank": "128","lora_alpha": "128","num_epochs": 70,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 500,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},1 unmodified line"model_type": "ltx_video","training_type": "lora","lora_rank": "256","lora_alpha": "128","num_epochs": 50,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 200,"training_buckets": MEDIUM_19_9_RATIO_BUCKETS,"flow_weighting_scheme": "logit_normal"},"LTX-Video (Full Finetune)": {"model_type": "ltx_video","training_type": "full-finetune","num_epochs": 30,"batch_size": 1,"learning_rate": 1e-5,"save_iterations": 300,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},2 unmodified lines"training_type": "lora","lora_rank": "32","lora_alpha": "32","num_epochs": 70,"batch_size": 1,"learning_rate": 5e-5,"save_iterations": 500,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},2 unmodified lines"training_type": "lora","lora_rank": "64","lora_alpha": "64","num_epochs": 50,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 200,"training_buckets": MEDIUM_19_9_RATIO_BUCKETS,"flow_weighting_scheme": "logit_normal"}25 unmodified linesid_token: Optional[str] = Nonevideo_resolution_buckets: List[Tuple[int, int, int]] = field(default_factory=lambda: SMALL_TRAINING_BUCKETS)video_reshape_mode: str = "center"caption_dropout_p: float = 0.05caption_dropout_technique: str = "empty"precompute_conditions: bool = False6 unmodified lines# Training argumentstraining_type: str = "lora"seed: int = 42mixed_precision: str = "bf16"batch_size: int = 1train_epochs: int = 70lora_rank: int = 128lora_alpha: int = 128target_modules: List[str] = field(default_factory=lambda: ["to_q", "to_k", "to_v", "to_out.0"])gradient_accumulation_steps: int = 1gradient_checkpointing: bool = Truecheckpointing_steps: int = 500checkpointing_limit: Optional[int] = 2resume_from_checkpoint: Optional[str] = Noneenable_slicing: bool = True27 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_epochs=70,lr=2e-5,gradient_checkpointing=True,id_token="afkx",gradient_accumulation_steps=1,lora_rank=128,lora_alpha=128,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=0.05,flow_weighting_scheme="none", # Hunyuan specifictraining_type="lora")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_epochs=40,lr=3e-5,gradient_checkpointing=True,id_token="BW_STYLE",gradient_accumulation_steps=4,lora_rank=128,lora_alpha=128,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=0.05,flow_weighting_scheme="logit_normal", # LTX specifictraining_type="lora")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_epochs=30,lr=1e-5,gradient_checkpointing=True,id_token="BW_STYLE",gradient_accumulation_steps=1,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=0.05,flow_weighting_scheme="logit_normal", # LTX specifictraining_type="full-finetune")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_epochs=70,lr=5e-5,gradient_checkpointing=True,id_token=None, # Default is no ID token for Wan2 unmodified lineslora_alpha=32,target_modules=["blocks.*(to_q|to_k|to_v|to_out.0)"], # Wan-specific target modulesvideo_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=0.05,flow_weighting_scheme="logit_normal", # Wan specifictraining_type="lora")48 unmodified lines#args.extend(["--mixed_precision", self.mixed_precision])args.extend(["--batch_size", str(self.batch_size)])args.extend(["--train_steps", str(self.train_epochs * 1000)]) # Convert epochs to steps for compatibility# LoRA specific argumentsif self.training_type == "lora":57 unmodified lines5859606162636465662 unmodified lines697071727374757677787980818283848586878889909112 unmodified lines1041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511523 unmodified lines1561571581591601611621631641651661671681691701711721731741 unmodified line1761771781791801811821831841851861871881891901911921931941951961971981991 unmodified line2012022032042052062072082092102112122132142152162172182192202212 unmodified lines2242252262272282292302312322332 unmodified lines23623723823924024124224324424525 unmodified lines2712722732742752762776 unmodified lines28428528628728828929029129229329429529629729829927 unmodified lines3273283293303313323333343353363373383393403417 unmodified lines3493503513523533543553563573583593603613623637 unmodified lines3713723733743753763773783793803813823837 unmodified lines3913923933943953963972 unmodified lines40040140240340440540648 unmodified lines45545645745845946046157 unmodified lines# Expanded model types to include Wan-2.1-T2VMODEL_TYPES = {"HunyuanVideo": "hunyuan_video","LTX-Video": "ltx_video","Wan-2.1-T2V": "wan"}# Training types2 unmodified lines"Full Finetune": "full-finetune"}DEFAULT_SEED = 42DEFAULT_NB_TRAINING_STEPS = 1000DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS = 200DEFAULT_LORA_RANK = 128DEFAULT_LORA_RANK_STR = str(DEFAULT_LORA_RANK)DEFAULT_LORA_ALPHA = 128DEFAULT_LORA_ALPHA_STR = str(DEFAULT_LORA_ALPHA)DEFAULT_CAPTION_DROPOUT_P = 0.05DEFAULT_BATCH_SIZE = 1DEFAULT_LEARNING_RATE = 3e-5# it is best to use resolutions that are powers of 8# The resolution should be divisible by 3212 unmodified linesNB_FRAMES_1 = 1 # 1NB_FRAMES_9 = 8 + 1 # 8 + 1NB_FRAMES_17 = 8 * 2 + 1 # 16 + 1NB_FRAMES_33 = 8 * 4 + 1 # 32 + 1NB_FRAMES_49 = 8 * 6 + 1 # 48 + 1NB_FRAMES_65 = 8 * 8 + 1 # 64 + 1NB_FRAMES_81 = 8 * 10 + 1 # 80 + 1NB_FRAMES_97 = 8 * 12 + 1 # 96 + 1NB_FRAMES_113 = 8 * 14 + 1 # 112 + 1NB_FRAMES_129 = 8 * 16 + 1 # 128 + 1NB_FRAMES_145 = 8 * 18 + 1 # 144 + 1NB_FRAMES_161 = 8 * 20 + 1 # 160 + 1NB_FRAMES_177 = 8 * 22 + 1 # 176 + 1NB_FRAMES_193 = 8 * 24 + 1 # 192 + 1NB_FRAMES_225 = 8 * 28 + 1 # 224 + 1NB_FRAMES_257 = 8 * 32 + 1 # 256 + 1# 256 isn't a lot by the way, especially with 60 FPS videos..# can we crank it and put more frames in here?NB_FRAMES_273 = 8 * 34 + 1 # 272 + 1NB_FRAMES_289 = 8 * 36 + 1 # 288 + 1NB_FRAMES_305 = 8 * 38 + 1 # 304 + 1NB_FRAMES_321 = 8 * 40 + 1 # 320 + 1NB_FRAMES_337 = 8 * 42 + 1 # 336 + 1NB_FRAMES_353 = 8 * 44 + 1 # 352 + 1NB_FRAMES_369 = 8 * 46 + 1 # 368 + 1NB_FRAMES_385 = 8 * 48 + 1 # 384 + 1NB_FRAMES_401 = 8 * 50 + 1 # 400 + 1SMALL_TRAINING_BUCKETS = [(NB_FRAMES_1, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 1(NB_FRAMES_9, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 8 + 1(NB_FRAMES_17, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 16 + 1(NB_FRAMES_33, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 32 + 1(NB_FRAMES_49, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 48 + 1(NB_FRAMES_65, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 64 + 1(NB_FRAMES_81, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 80 + 1(NB_FRAMES_97, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 96 + 1(NB_FRAMES_113, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 112 + 1(NB_FRAMES_129, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 128 + 1(NB_FRAMES_145, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 144 + 1(NB_FRAMES_161, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 160 + 1(NB_FRAMES_177, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 176 + 1(NB_FRAMES_193, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 192 + 1(NB_FRAMES_225, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 224 + 1(NB_FRAMES_257, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 256 + 1]MEDIUM_19_9_RATIO_WIDTH = 928 # 32 * 293 unmodified lines(NB_FRAMES_1, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 1(NB_FRAMES_9, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 8 + 1(NB_FRAMES_17, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 16 + 1(NB_FRAMES_33, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 32 + 1(NB_FRAMES_49, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 48 + 1(NB_FRAMES_65, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 64 + 1(NB_FRAMES_81, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 80 + 1(NB_FRAMES_97, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 96 + 1(NB_FRAMES_113, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 112 + 1(NB_FRAMES_129, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 128 + 1(NB_FRAMES_145, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 144 + 1(NB_FRAMES_161, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 160 + 1(NB_FRAMES_177, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 176 + 1(NB_FRAMES_193, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 192 + 1(NB_FRAMES_225, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 224 + 1(NB_FRAMES_257, MEDIUM_19_9_RATIO_HEIGHT, MEDIUM_19_9_RATIO_WIDTH), # 256 + 1]# Updated training presets to include Wan-2.1-T2V and support both LoRA and full-finetune1 unmodified line"HunyuanVideo (normal)": {"model_type": "hunyuan_video","training_type": "lora","lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": 2e-5,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "none"},"LTX-Video (normal)": {"model_type": "ltx_video","training_type": "lora","lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},1 unmodified line"model_type": "ltx_video","training_type": "lora","lora_rank": "256","lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": MEDIUM_19_9_RATIO_BUCKETS,"flow_weighting_scheme": "logit_normal"},"LTX-Video (Full Finetune)": {"model_type": "ltx_video","training_type": "full-finetune","train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},2 unmodified lines"training_type": "lora","lora_rank": "32","lora_alpha": "32","train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": 5e-5,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": SMALL_TRAINING_BUCKETS,"flow_weighting_scheme": "logit_normal"},2 unmodified lines"training_type": "lora","lora_rank": "64","lora_alpha": "64","train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_buckets": MEDIUM_19_9_RATIO_BUCKETS,"flow_weighting_scheme": "logit_normal"}25 unmodified linesid_token: Optional[str] = Nonevideo_resolution_buckets: List[Tuple[int, int, int]] = field(default_factory=lambda: SMALL_TRAINING_BUCKETS)video_reshape_mode: str = "center"caption_dropout_p: float = DEFAULT_CAPTION_DROPOUT_Pcaption_dropout_technique: str = "empty"precompute_conditions: bool = False6 unmodified lines# Training argumentstraining_type: str = "lora"seed: int = DEFAULT_SEEDmixed_precision: str = "bf16"batch_size: int = 1train_step: int = DEFAULT_NB_TRAINING_STEPSlora_rank: int = DEFAULT_LORA_RANKlora_alpha: int = DEFAULT_LORA_ALPHAtarget_modules: List[str] = field(default_factory=lambda: ["to_q", "to_k", "to_v", "to_out.0"])gradient_accumulation_steps: int = 1gradient_checkpointing: bool = Truecheckpointing_steps: int = DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPScheckpointing_limit: Optional[int] = 2resume_from_checkpoint: Optional[str] = Noneenable_slicing: bool = True27 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_steps=DEFAULT_NB_TRAINING_STEPS,lr=2e-5,gradient_checkpointing=True,id_token="afkx",gradient_accumulation_steps=1,lora_rank=DEFAULT_LORA_RANK,lora_alpha=DEFAULT_LORA_ALPHA,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=DEFAULT_CAPTION_DROPOUT_P,flow_weighting_scheme="none", # Hunyuan specifictraining_type="lora")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_steps=DEFAULT_NB_TRAINING_STEPS,lr=DEFAULT_LEARNING_RATE,gradient_checkpointing=True,id_token="BW_STYLE",gradient_accumulation_steps=4,lora_rank=DEFAULT_LORA_RANK,lora_alpha=DEFAULT_LORA_ALPHA,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=DEFAULT_CAPTION_DROPOUT_P,flow_weighting_scheme="logit_normal", # LTX specifictraining_type="lora")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_steps=DEFAULT_NB_TRAINING_STEPS,lr=1e-5,gradient_checkpointing=True,id_token="BW_STYLE",gradient_accumulation_steps=1,video_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=DEFAULT_CAPTION_DROPOUT_P,flow_weighting_scheme="logit_normal", # LTX specifictraining_type="full-finetune")7 unmodified linesdata_root=data_path,output_dir=output_path,batch_size=1,train_steps=DEFAULT_NB_TRAINING_STEPS,lr=5e-5,gradient_checkpointing=True,id_token=None, # Default is no ID token for Wan2 unmodified lineslora_alpha=32,target_modules=["blocks.*(to_q|to_k|to_v|to_out.0)"], # Wan-specific target modulesvideo_resolution_buckets=buckets or SMALL_TRAINING_BUCKETS,caption_dropout_p=DEFAULT_CAPTION_DROPOUT_P,flow_weighting_scheme="logit_normal", # Wan specifictraining_type="lora")48 unmodified lines#args.extend(["--mixed_precision", self.mixed_precision])args.extend(["--batch_size", str(self.batch_size)])args.extend(["--train_steps", str(self.train_steps)])# LoRA specific argumentsif self.training_type == "lora":
22 unmodified lines2324252627282981 unmodified lines11111211311411511611711811912012112212312412512612712816 unmodified lines1451461471481491501511521534 unmodified lines15815916016116216312 unmodified lines17617717817918018118218318418518618721 unmodified lines209210211212213214215216217218219220140 unmodified lines361362363364365366367140 unmodified lines50850951051151251351415 unmodified lines53053153253353453553653753853954085 unmodified lines6266276286296306316322 unmodified lines635636637638639640641642643644645646647648140 unmodified lines78979079179279379479579679779879980052 unmodified lines8538548558568578588598608618628638647 unmodified lines87287387487587687787887988088188288322 unmodified linesfrom ..config import (TrainingConfig, TRAINING_PRESETS, LOG_FILE_PATH, TRAINING_VIDEOS_PATH,STORAGE_PATH, TRAINING_PATH, MODEL_PATH, OUTPUT_PATH, HF_API_TOKEN,MODEL_TYPES, TRAINING_TYPES)from ..utils import make_archive, parse_training_log, is_image_file, is_video_file, prepare_finetrainers_dataset, copy_files_to_training_dir81 unmodified linesexcept Exception as e:logger.error(f"Error saving UI state: {str(e)}")def load_ui_state(self) -> Dict[str, Any]:"""Load saved UI state"""ui_state_file = OUTPUT_PATH / "ui_state.json"default_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": "128","lora_alpha": "128","num_epochs": 50,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 200,"training_preset": list(TRAINING_PRESETS.keys())[0]}16 unmodified linessaved_state = json.loads(file_content)# Convert numeric values to appropriate typesif "num_epochs" in saved_state:saved_state["num_epochs"] = int(saved_state["num_epochs"])if "batch_size" in saved_state:saved_state["batch_size"] = int(saved_state["batch_size"])if "learning_rate" in saved_state:4 unmodified lines# Make sure we have all keys (in case structure changed)merged_state = default_state.copy()merged_state.update(saved_state)return merged_stateexcept json.JSONDecodeError as e:logger.error(f"Error parsing UI state JSON: {str(e)}")12 unmodified linesdefault_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": "128","lora_alpha": "128","num_epochs": 50,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 200,"training_preset": list(TRAINING_PRESETS.keys())[0]}self.save_ui_state(default_state)21 unmodified linesdefault_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": "128","lora_alpha": "128","num_epochs": 50,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 200,"training_preset": list(TRAINING_PRESETS.keys())[0]}self.save_ui_state(default_state)140 unmodified linesmodel_type: str,lora_rank: str,lora_alpha: str,num_epochs: int,batch_size: int,learning_rate: float,save_iterations: int,140 unmodified linesreturn error_msg, "Unsupported model"# Update with UI parametersconfig.train_epochs = int(num_epochs)config.batch_size = int(batch_size)config.lr = float(learning_rate)config.checkpointing_steps = int(save_iterations)15 unmodified lines# Common settings for both modelsconfig.mixed_precision = "bf16"config.seed = 42config.gradient_checkpointing = Trueconfig.enable_slicing = Trueconfig.enable_tiling = Trueconfig.caption_dropout_p = 0.05validation_error = self.validate_training_config(config, model_type)if validation_error:85 unmodified lines"training_type": training_type,"lora_rank": lora_rank,"lora_alpha": lora_alpha,"num_epochs": num_epochs,"batch_size": batch_size,"learning_rate": learning_rate,"save_iterations": save_iterations,2 unmodified lines})# Update initial training statustotal_steps = num_epochs * (max(1, video_count) // batch_size)self.save_status(state='training',epoch=0,step=0,total_steps=total_steps,loss=0.0,total_epochs=num_epochs,message='Training started',repo_id=repo_id,model_type=model_type,140 unmodified lines"params": {"model_type": MODEL_TYPES.get(ui_state.get("model_type", list(MODEL_TYPES.keys())[0])),"training_type": TRAINING_TYPES.get(ui_state.get("training_type", list(TRAINING_TYPES.keys())[0])),"lora_rank": ui_state.get("lora_rank", "128"),"lora_alpha": ui_state.get("lora_alpha", "128"),"num_epochs": ui_state.get("num_epochs", 70),"batch_size": ui_state.get("batch_size", 1),"learning_rate": ui_state.get("learning_rate", 3e-5),"save_iterations": ui_state.get("save_iterations", 500),"preset_name": ui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0]),"repo_id": "" # Default empty repo ID}52 unmodified linesui_updates.update({"model_type": model_type_display, # Use the display name for the UI dropdown"training_type": training_type_display, # Use the display name for training type"lora_rank": params.get('lora_rank', "128"),"lora_alpha": params.get('lora_alpha', "128"),"num_epochs": params.get('num_epochs', 70),"batch_size": params.get('batch_size', 1),"learning_rate": params.get('learning_rate', 3e-5),"save_iterations": params.get('save_iterations', 500),"training_preset": params.get('preset_name', list(TRAINING_PRESETS.keys())[0])})7 unmodified lines# But keep model_type_display for the UIresult = self.start_training(model_type=model_type_internal,lora_rank=params.get('lora_rank', "128"),lora_alpha=params.get('lora_alpha', "128"),num_epochs=params.get('num_epochs', 70),batch_size=params.get('batch_size', 1),learning_rate=params.get('learning_rate', 3e-5),save_iterations=params.get('save_iterations', 500),repo_id=params.get('repo_id', ''),preset_name=params.get('preset_name', list(TRAINING_PRESETS.keys())[0]),training_type=training_type_internal,22 unmodified lines23242526272829303132333481 unmodified lines11611711811912012112212312412512612712812913013113213313416 unmodified lines1511521531541551561571581591601611621631644 unmodified lines16917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720812 unmodified lines22122222322422522622722822923023123221 unmodified lines254255256257258259260261262263264265140 unmodified lines406407408409410411412140 unmodified lines55355455555655755855915 unmodified lines57557657757857958058158258358458585 unmodified lines6716726736746756766772 unmodified lines680681682683684685686687688689690691140 unmodified lines83283383483583683783883984084184284352 unmodified lines8968978988999009019029039049059069077 unmodified lines91591691791891992092192292392492592622 unmodified linesfrom ..config import (TrainingConfig, TRAINING_PRESETS, LOG_FILE_PATH, TRAINING_VIDEOS_PATH,STORAGE_PATH, TRAINING_PATH, MODEL_PATH, OUTPUT_PATH, HF_API_TOKEN,MODEL_TYPES, TRAINING_TYPES,DEFAULT_NB_TRAINING_STEPS, DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,DEFAULT_BATCH_SIZE, DEFAULT_CAPTION_DROPOUT_P,DEFAULT_LEARNING_RATE,DEFAULT_LORA_RANK, DEFAULT_LORA_ALPHA,DEFAULT_LORA_RANK_STR, DEFAULT_LORA_ALPHA_STR)from ..utils import make_archive, parse_training_log, is_image_file, is_video_file, prepare_finetrainers_dataset, copy_files_to_training_dir81 unmodified linesexcept Exception as e:logger.error(f"Error saving UI state: {str(e)}")# Additional fix for the load_ui_state method in trainer.py to clean up old valuesdef load_ui_state(self) -> Dict[str, Any]:"""Load saved UI state"""ui_state_file = OUTPUT_PATH / "ui_state.json"default_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_preset": list(TRAINING_PRESETS.keys())[0]}16 unmodified linessaved_state = json.loads(file_content)# Clean up model type if it contains " (LoRA)" suffixif "model_type" in saved_state and " (LoRA)" in saved_state["model_type"]:saved_state["model_type"] = saved_state["model_type"].replace(" (LoRA)", "")logger.info(f"Removed (LoRA) suffix from saved model type: {saved_state['model_type']}")# Convert numeric values to appropriate typesif "train_steps" in saved_state:saved_state["train_steps"] = int(saved_state["train_steps"])if "batch_size" in saved_state:saved_state["batch_size"] = int(saved_state["batch_size"])if "learning_rate" in saved_state:4 unmodified lines# Make sure we have all keys (in case structure changed)merged_state = default_state.copy()merged_state.update(saved_state)# Validate model_type is in available choicesif merged_state["model_type"] not in MODEL_TYPES:# Try to map from internal namemodel_found = Falsefor display_name, internal_name in MODEL_TYPES.items():if internal_name == merged_state["model_type"]:merged_state["model_type"] = display_namemodel_found = Truebreak# If still not found, use defaultif not model_found:merged_state["model_type"] = default_state["model_type"]logger.warning(f"Invalid model type in saved state, using default")# Validate training_type is in available choicesif merged_state["training_type"] not in TRAINING_TYPES:# Try to map from internal nametraining_found = Falsefor display_name, internal_name in TRAINING_TYPES.items():if internal_name == merged_state["training_type"]:merged_state["training_type"] = display_nametraining_found = Truebreak# If still not found, use defaultif not training_found:merged_state["training_type"] = default_state["training_type"]logger.warning(f"Invalid training type in saved state, using default")# Validate training_preset is in available choicesif merged_state["training_preset"] not in TRAINING_PRESETS:merged_state["training_preset"] = default_state["training_preset"]logger.warning(f"Invalid training preset in saved state, using default")return merged_stateexcept json.JSONDecodeError as e:logger.error(f"Error parsing UI state JSON: {str(e)}")12 unmodified linesdefault_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"training_preset": list(TRAINING_PRESETS.keys())[0]}self.save_ui_state(default_state)21 unmodified linesdefault_state = {"model_type": list(MODEL_TYPES.keys())[0],"training_type": list(TRAINING_TYPES.keys())[0],"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR,"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_NB_TRAINING_STEPS,"training_preset": list(TRAINING_PRESETS.keys())[0]}self.save_ui_state(default_state)140 unmodified linesmodel_type: str,lora_rank: str,lora_alpha: str,train_steps: int,batch_size: int,learning_rate: float,save_iterations: int,140 unmodified linesreturn error_msg, "Unsupported model"# Update with UI parametersconfig.train_steps = int(train_steps)config.batch_size = int(batch_size)config.lr = float(learning_rate)config.checkpointing_steps = int(save_iterations)15 unmodified lines# Common settings for both modelsconfig.mixed_precision = "bf16"config.seed = DEFAULT_SEEDconfig.gradient_checkpointing = Trueconfig.enable_slicing = Trueconfig.enable_tiling = Trueconfig.caption_dropout_p = DEFAULT_CAPTION_DROPOUT_Pvalidation_error = self.validate_training_config(config, model_type)if validation_error:85 unmodified lines"training_type": training_type,"lora_rank": lora_rank,"lora_alpha": lora_alpha,"train_steps": train_steps,"batch_size": batch_size,"learning_rate": learning_rate,"save_iterations": save_iterations,2 unmodified lines})# Update initial training statustotal_steps = int(train_steps)self.save_status(state='training',step=0,total_steps=total_steps,loss=0.0,message='Training started',repo_id=repo_id,model_type=model_type,140 unmodified lines"params": {"model_type": MODEL_TYPES.get(ui_state.get("model_type", list(MODEL_TYPES.keys())[0])),"training_type": TRAINING_TYPES.get(ui_state.get("training_type", list(TRAINING_TYPES.keys())[0])),"lora_rank": ui_state.get("lora_rank", DEFAULT_LORA_RANK_STR),"lora_alpha": ui_state.get("lora_alpha", DEFAULT_LORA_ALPHA_STR),"train_steps": ui_state.get("train_steps", DEFAULT_NB_TRAINING_STEPS),"batch_size": ui_state.get("batch_size", DEFAULT_BATCH_SIZE),"learning_rate": ui_state.get("learning_rate", DEFAULT_LEARNING_RATE),"save_iterations": ui_state.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS),"preset_name": ui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0]),"repo_id": "" # Default empty repo ID}52 unmodified linesui_updates.update({"model_type": model_type_display, # Use the display name for the UI dropdown"training_type": training_type_display, # Use the display name for training type"lora_rank": params.get('lora_rank', DEFAULT_LORA_RANK_STR),"lora_alpha": params.get('lora_alpha', DEFAULT_LORA_ALPHA_STR),"train_steps": params.get('train_steps', DEFAULT_NB_TRAINING_STEPS),"batch_size": params.get('batch_size', DEFAULT_BATCH_SIZE),"learning_rate": params.get('learning_rate', DEFAULT_LEARNING_RATE),"save_iterations": params.get('save_iterations', DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS),"training_preset": params.get('preset_name', list(TRAINING_PRESETS.keys())[0])})7 unmodified lines# But keep model_type_display for the UIresult = self.start_training(model_type=model_type_internal,lora_rank=params.get('lora_rank', DEFAULT_LORA_RANK_STR),lora_alpha=params.get('lora_alpha', DEFAULT_LORA_ALPHA_STR),train_size=params.get('train_steps', DEFAULT_NB_TRAINING_STEPS),batch_size=params.get('batch_size', DEFAULT_BATCH_SIZE),learning_rate=params.get('learning_rate', DEFAULT_LEARNING_RATE),save_iterations=params.get('save_iterations', DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS),repo_id=params.get('repo_id', ''),preset_name=params.get('preset_name', list(TRAINING_PRESETS.keys())[0]),training_type=training_type_internal,
8 unmodified lines910111213141547 unmodified lines63646566676869707172737475767778798081826 unmodified lines899091929394959697989910010168 unmodified lines1701711721731741751769 unmodified lines18618718818919019119211 unmodified lines20420520620720820921014 unmodified lines22522622722822923023123223328 unmodified lines26226326426526626726811 unmodified lines2802812822832842852863 unmodified lines2902912922932942952962972982993003013023033043053063073083093103113123133143153162 unmodified lines3193203213223233243253263273281 unmodified line33033133233333433533633733833934034134234334434545 unmodified lines3913923933943953963975 unmodified lines4034044054064074084094 unmodified lines41441541641741841942042142242342442542642712 unmodified lines44044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949031 unmodified lines5225235245255265275285295305315325331 unmodified line5355365375385395405411 unmodified line54354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760854 unmodified lines6636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227238 unmodified linesfrom pathlib import Pathfrom .base_tab import BaseTabfrom ..config import TRAINING_PRESETS, OUTPUT_PATH, MODEL_TYPES, ASK_USER_TO_DUPLICATE_SPACE, SMALL_TRAINING_BUCKETS, TRAINING_TYPESlogger = logging.getLogger(__name__)47 unmodified linesself.components["lora_rank"] = gr.Dropdown(label="LoRA Rank",choices=["16", "32", "64", "128", "256", "512", "1024"],value="128",type="value")self.components["lora_alpha"] = gr.Dropdown(label="LoRA Alpha",choices=["16", "32", "64", "128", "256", "512", "1024"],value="128",type="value")with gr.Row():self.components["num_epochs"] = gr.Number(label="Number of Epochs",value=70,minimum=1,precision=0)6 unmodified lineswith gr.Row():self.components["learning_rate"] = gr.Number(label="Learning Rate",value=2e-5,minimum=1e-7)self.components["save_iterations"] = gr.Number(label="Save checkpoint every N iterations",value=500,minimum=50,precision=0,info="Model will be saved periodically after these many steps")68 unmodified linesreturn {self.components["model_info"]: info,self.components["num_epochs"]: params["num_epochs"],self.components["batch_size"]: params["batch_size"],self.components["learning_rate"]: params["learning_rate"],self.components["save_iterations"]: params["save_iterations"],9 unmodified linesinputs=[self.components["model_type"], self.components["training_type"]],outputs=[self.components["model_info"],self.components["num_epochs"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],11 unmodified linesinputs=[self.components["model_type"], self.components["training_type"]],outputs=[self.components["model_info"],self.components["num_epochs"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],14 unmodified linesoutputs=[])self.components["num_epochs"].change(fn=lambda v: self.app.update_ui_state(num_epochs=v),inputs=[self.components["num_epochs"]],outputs=[])28 unmodified linesself.components["training_type"],self.components["lora_rank"],self.components["lora_alpha"],self.components["num_epochs"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],11 unmodified linesself.components["training_type"],self.components["lora_rank"],self.components["lora_alpha"],self.components["num_epochs"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],3 unmodified linesself.components["status_box"],self.components["log_box"]]).success(fn=self.get_latest_status_message_logs_and_button_labels,outputs=[self.components["status_box"],self.components["log_box"],self.components["start_btn"],self.components["stop_btn"],self.components["pause_resume_btn"],self.components["current_task_box"] # Include new component])self.components["pause_resume_btn"].click(fn=self.handle_pause_resume,outputs=[self.components["status_box"],self.components["log_box"],self.components["start_btn"],self.components["stop_btn"],self.components["pause_resume_btn"],self.components["current_task_box"] # Include new component])2 unmodified linesoutputs=[self.components["status_box"],self.components["log_box"],self.components["start_btn"],self.components["stop_btn"],self.components["pause_resume_btn"],self.components["current_task_box"] # Include new component])1 unmodified lineself.components["delete_checkpoints_btn"].click(fn=lambda: self.app.trainer.delete_all_checkpoints(),outputs=[self.components["status_box"]]).then(fn=self.get_latest_status_message_logs_and_button_labels,outputs=[self.components["status_box"],self.components["log_box"],self.components["start_btn"],self.components["stop_btn"],self.components["delete_checkpoints_btn"],self.components["current_task_box"] # Include new component])def handle_training_start(self, preset, model_type, training_type, *args):45 unmodified linesdef get_model_info(self, model_type: str, training_type: str) -> str:"""Get information about the selected model type and training method"""if model_type == "HunyuanVideo (LoRA)":base_info = """### HunyuanVideo- Required VRAM: ~48GB minimum- Recommended batch size: 1-25 unmodified lineselse:return base_info + "\n- Required VRAM: ~48GB minimum\n- **Full finetune not recommended due to VRAM requirements**"elif model_type == "LTX-Video (LoRA)":base_info = """### LTX-Video- Recommended batch size: 1-4- Typical training time: 1-3 hours4 unmodified lineselse:return base_info + "\n- Required VRAM: ~21GB minimum\n- Full model size: ~8GB"elif model_type == "Wan-2.1-T2V (LoRA)":base_info = """### Wan-2.1-T2V- Recommended batch size: 1-2- Typical training time: 1-3 hours- Default resolution: 49x512x768"""if training_type == "LoRA Finetune":return base_info + "\n- Required VRAM: ~16GB minimum\n- Default LoRA rank: 32 (~120 MB)"else:return base_info + "\n- **Full finetune not recommended due to VRAM requirements**"12 unmodified lines# Use the first matching presetpreset = matching_presets[0]return {"num_epochs": preset.get("num_epochs", 70),"batch_size": preset.get("batch_size", 1),"learning_rate": preset.get("learning_rate", 3e-5),"save_iterations": preset.get("save_iterations", 500),"lora_rank": preset.get("lora_rank", "128"),"lora_alpha": preset.get("lora_alpha", "128")}# Default fallbacksif model_type == "hunyuan_video":return {"num_epochs": 70,"batch_size": 1,"learning_rate": 2e-5,"save_iterations": 500,"lora_rank": "128","lora_alpha": "128"}elif model_type == "ltx_video":return {"num_epochs": 70,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 500,"lora_rank": "128","lora_alpha": "128"}elif model_type == "wan":return {"num_epochs": 70,"batch_size": 1,"learning_rate": 5e-5,"save_iterations": 500,"lora_rank": "32","lora_alpha": "32"}else:# Generic defaultsreturn {"num_epochs": 70,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 500,"lora_rank": "128","lora_alpha": "128"}def update_training_params(self, preset_name: str) -> Tuple:31 unmodified linesshow_lora_params = preset["training_type"] == "lora"# Use preset defaults but preserve user-modified values if they existlora_rank_val = current_state.get("lora_rank") if current_state.get("lora_rank") != preset.get("lora_rank", "128") else preset.get("lora_rank", "128")lora_alpha_val = current_state.get("lora_alpha") if current_state.get("lora_alpha") != preset.get("lora_alpha", "128") else preset.get("lora_alpha", "128")num_epochs_val = current_state.get("num_epochs") if current_state.get("num_epochs") != preset.get("num_epochs", 70) else preset.get("num_epochs", 70)batch_size_val = current_state.get("batch_size") if current_state.get("batch_size") != preset.get("batch_size", 1) else preset.get("batch_size", 1)learning_rate_val = current_state.get("learning_rate") if current_state.get("learning_rate") != preset.get("learning_rate", 3e-5) else preset.get("learning_rate", 3e-5)save_iterations_val = current_state.get("save_iterations") if current_state.get("save_iterations") != preset.get("save_iterations", 500) else preset.get("save_iterations", 500)# Return values in the same order as the output componentsreturn (1 unmodified linetraining_display_name,lora_rank_val,lora_alpha_val,num_epochs_val,batch_size_val,learning_rate_val,save_iterations_val,1 unmodified linegr.Row(visible=show_lora_params))def update_training_ui(self, training_state: Dict[str, Any]):"""Update UI components based on training state"""updates = {}# Update status box with high-level informationstatus_text = []if training_state["status"] != "idle":status_text.extend([f"Status: {training_state['status']}",f"Progress: {training_state['progress']}",f"Step: {training_state['current_step']}/{training_state['total_steps']}",f"Time elapsed: {training_state['elapsed']}",f"Estimated remaining: {training_state['remaining']}","",f"Current loss: {training_state['step_loss']}",f"Learning rate: {training_state['learning_rate']}",f"Gradient norm: {training_state['grad_norm']}",f"Memory usage: {training_state['memory']}"])if training_state["error_message"]:status_text.append(f"\nError: {training_state['error_message']}")updates["status_box"] = "\n".join(status_text)# Add current task information to the dedicated boxif training_state.get("current_task"):updates["current_task_box"] = training_state["current_task"]else:updates["current_task_box"] = "No active task" if training_state["status"] != "training" else "Waiting for task information..."# Update button statesupdates["start_btn"] = gr.Button("Start training",interactive=(training_state["status"] in ["idle", "completed", "error", "stopped"]),variant="primary" if training_state["status"] == "idle" else "secondary")updates["stop_btn"] = gr.Button("Stop training",interactive=(training_state["status"] in ["training", "initializing"]),variant="stop")return updatesdef handle_pause_resume(self):status, _, _ = self.get_latest_status_message_and_logs()if status == "paused":self.app.trainer.resume_training()else:self.app.trainer.pause_training()return self.get_latest_status_message_logs_and_button_labels()def handle_stop(self):self.app.trainer.stop_training()return self.get_latest_status_message_logs_and_button_labels()def get_latest_status_message_and_logs(self) -> Tuple[str, str, str]:"""Get latest status message, log content, and status code in a safer way"""state = self.app.trainer.get_status()54 unmodified linesreturn (state["status"], state["message"], logs)def get_latest_status_message_logs_and_button_labels(self) -> Tuple:"""Get latest status message, logs and button states"""status, message, logs = self.get_latest_status_message_and_logs()# Add checkpoints detectionhas_checkpoints = len(list(OUTPUT_PATH.glob("checkpoint-*"))) > 0button_updates = self.update_training_buttons(status, has_checkpoints).values()# Get current task if availablecurrent_task = ""if hasattr(self.app, 'log_parser') and self.app.log_parser is not None:current_task = self.app.log_parser.get_current_task_display()# Return in order expected by timer (added current_task)return (message, logs, *button_updates, current_task)def update_training_buttons(self, status: str, has_checkpoints: bool = None) -> Dict:"""Update training control buttons based on state"""if has_checkpoints is None:has_checkpoints = len(list(OUTPUT_PATH.glob("checkpoint-*"))) > 0is_training = status in ["training", "initializing"]is_completed = status in ["completed", "error", "stopped"]start_text = "Continue Training" if has_checkpoints else "Start Training"# Only include buttons that we know exist in componentsresult = {"start_btn": gr.Button(value=start_text,interactive=not is_training,variant="primary" if not is_training else "secondary",),"stop_btn": gr.Button(value="Stop at Last Checkpoint",interactive=is_training,variant="primary" if is_training else "secondary",)}# Add delete_checkpoints_btn only if it exists in componentsif "delete_checkpoints_btn" in self.components:result["delete_checkpoints_btn"] = gr.Button(value="Delete All Checkpoints",interactive=has_checkpoints and not is_training,variant="stop",)else:# Add pause_resume_btn as fallbackresult["pause_resume_btn"] = gr.Button(value="Resume Training" if status == "paused" else "Pause Training",interactive=(is_training or status == "paused") and not is_completed,variant="secondary",visible=False)return result8 unmodified lines91011121314151617181920212247 unmodified lines70717273747576777879808182838485868788896 unmodified lines9697989910010110210310410510610710868 unmodified lines1771781791801811821839 unmodified lines19319419519619719819911 unmodified lines21121221321421521621714 unmodified lines23223323423523623723823924028 unmodified lines26927027127227327427511 unmodified lines2872882892902912922933 unmodified lines2972982993003013023033043053063073083093103113123133143153162 unmodified lines3193203213223233243253263273281 unmodified line33033133233333433545 unmodified lines3813823833843853863875 unmodified lines3933943953963973983994 unmodified lines40440540640740840941041141241341441541641712 unmodified lines43043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948031 unmodified lines5125135145155165175185195205215225231 unmodified line5255265275285295305311 unmodified line53353453553653753854 unmodified lines5935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986998 unmodified linesfrom pathlib import Pathfrom .base_tab import BaseTabfrom ..config import (TRAINING_PRESETS, OUTPUT_PATH, MODEL_TYPES, ASK_USER_TO_DUPLICATE_SPACE, SMALL_TRAINING_BUCKETS, TRAINING_TYPES,DEFAULT_NB_TRAINING_STEPS, DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,DEFAULT_BATCH_SIZE, DEFAULT_CAPTION_DROPOUT_P,DEFAULT_LEARNING_RATE,DEFAULT_LORA_RANK, DEFAULT_LORA_ALPHA,DEFAULT_LORA_RANK_STR, DEFAULT_LORA_ALPHA_STR)logger = logging.getLogger(__name__)47 unmodified linesself.components["lora_rank"] = gr.Dropdown(label="LoRA Rank",choices=["16", "32", "64", "128", "256", "512", "1024"],value=DEFAULT_LORA_RANK_STR,type="value")self.components["lora_alpha"] = gr.Dropdown(label="LoRA Alpha",choices=["16", "32", "64", "128", "256", "512", "1024"],value=DEFAULT_LORA_ALPHA_STR,type="value")with gr.Row():self.components["train_steps"] = gr.Number(label="Number of Training Steps",value=DEFAULT_NB_TRAINING_STEPS,minimum=1,precision=0)6 unmodified lineswith gr.Row():self.components["learning_rate"] = gr.Number(label="Learning Rate",value=DEFAULT_LEARNING_RATE,minimum=1e-8)self.components["save_iterations"] = gr.Number(label="Save checkpoint every N iterations",value=DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,minimum=1,precision=0,info="Model will be saved periodically after these many steps")68 unmodified linesreturn {self.components["model_info"]: info,self.components["train_steps"]: params["train_steps"],self.components["batch_size"]: params["batch_size"],self.components["learning_rate"]: params["learning_rate"],self.components["save_iterations"]: params["save_iterations"],9 unmodified linesinputs=[self.components["model_type"], self.components["training_type"]],outputs=[self.components["model_info"],self.components["train_steps"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],11 unmodified linesinputs=[self.components["model_type"], self.components["training_type"]],outputs=[self.components["model_info"],self.components["train_steps"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],14 unmodified linesoutputs=[])self.components["train_steps"].change(fn=lambda v: self.app.update_ui_state(train_steps=v),inputs=[self.components["train_steps"]],outputs=[])28 unmodified linesself.components["training_type"],self.components["lora_rank"],self.components["lora_alpha"],self.components["train_steps"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],11 unmodified linesself.components["training_type"],self.components["lora_rank"],self.components["lora_alpha"],self.components["train_steps"],self.components["batch_size"],self.components["learning_rate"],self.components["save_iterations"],3 unmodified linesself.components["status_box"],self.components["log_box"]])# Use simplified event handlers for pause/resume and stopthird_btn = self.components["delete_checkpoints_btn"] if "delete_checkpoints_btn" in self.components else self.components["pause_resume_btn"]self.components["pause_resume_btn"].click(fn=self.handle_pause_resume,outputs=[self.components["status_box"],self.components["log_box"],self.components["current_task_box"],self.components["start_btn"],self.components["stop_btn"],third_btn])2 unmodified linesoutputs=[self.components["status_box"],self.components["log_box"],self.components["current_task_box"],self.components["start_btn"],self.components["stop_btn"],third_btn])1 unmodified lineself.components["delete_checkpoints_btn"].click(fn=lambda: self.app.trainer.delete_all_checkpoints(),outputs=[self.components["status_box"]])def handle_training_start(self, preset, model_type, training_type, *args):45 unmodified linesdef get_model_info(self, model_type: str, training_type: str) -> str:"""Get information about the selected model type and training method"""if model_type == "HunyuanVideo":base_info = """### HunyuanVideo- Required VRAM: ~48GB minimum- Recommended batch size: 1-25 unmodified lineselse:return base_info + "\n- Required VRAM: ~48GB minimum\n- **Full finetune not recommended due to VRAM requirements**"elif model_type == "LTX-Video":base_info = """### LTX-Video- Recommended batch size: 1-4- Typical training time: 1-3 hours4 unmodified lineselse:return base_info + "\n- Required VRAM: ~21GB minimum\n- Full model size: ~8GB"elif model_type == "Wan-2.1-T2V":base_info = """### Wan-2.1-T2V- Recommended batch size: ?- Typical training time: ? hours- Default resolution: 49x512x768"""if training_type == "LoRA Finetune":return base_info + "\n- Required VRAM: ?GB minimum\n- Default LoRA rank: 32 (~120 MB)"else:return base_info + "\n- **Full finetune not recommended due to VRAM requirements**"12 unmodified lines# Use the first matching presetpreset = matching_presets[0]return {"train_steps": preset.get("train_steps", DEFAULT_NB_TRAINING_STEPS),"batch_size": preset.get("batch_size", DEFAULT_BATCH_SIZE),"learning_rate": preset.get("learning_rate", DEFAULT_LEARNING_RATE),"save_iterations": preset.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS),"lora_rank": preset.get("lora_rank", DEFAULT_LORA_RANK_STR),"lora_alpha": preset.get("lora_alpha", DEFAULT_LORA_ALPHA_STR)}# Default fallbacksif model_type == "hunyuan_video":return {"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": 2e-5,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR}elif model_type == "ltx_video":return {"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR}elif model_type == "wan":return {"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": 5e-5,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"lora_rank": "32","lora_alpha": "32"}else:# Generic defaultsreturn {"train_steps": DEFAULT_NB_TRAINING_STEPS,"batch_size": DEFAULT_BATCH_SIZE,"learning_rate": DEFAULT_LEARNING_RATE,"save_iterations": DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,"lora_rank": DEFAULT_LORA_RANK_STR,"lora_alpha": DEFAULT_LORA_ALPHA_STR}def update_training_params(self, preset_name: str) -> Tuple:31 unmodified linesshow_lora_params = preset["training_type"] == "lora"# Use preset defaults but preserve user-modified values if they existlora_rank_val = current_state.get("lora_rank") if current_state.get("lora_rank") != preset.get("lora_rank", DEFAULT_LORA_RANK_STR) else preset.get("lora_rank", DEFAULT_LORA_RANK_STR)lora_alpha_val = current_state.get("lora_alpha") if current_state.get("lora_alpha") != preset.get("lora_alpha", DEFAULT_LORA_ALPHA_STR) else preset.get("lora_alpha", DEFAULT_LORA_ALPHA_STR)train_steps_val = current_state.get("train_steps") if current_state.get("train_steps") != preset.get("train_steps", DEFAULT_NB_TRAINING_STEPS) else preset.get("train_steps", DEFAULT_NB_TRAINING_STEPS)batch_size_val = current_state.get("batch_size") if current_state.get("batch_size") != preset.get("batch_size", DEFAULT_BATCH_SIZE) else preset.get("batch_size", DEFAULT_BATCH_SIZE)learning_rate_val = current_state.get("learning_rate") if current_state.get("learning_rate") != preset.get("learning_rate", DEFAULT_LEARNING_RATE) else preset.get("learning_rate", DEFAULT_LEARNING_RATE)save_iterations_val = current_state.get("save_iterations") if current_state.get("save_iterations") != preset.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS) else preset.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS)# Return values in the same order as the output componentsreturn (1 unmodified linetraining_display_name,lora_rank_val,lora_alpha_val,train_steps_val,batch_size_val,learning_rate_val,save_iterations_val,1 unmodified linegr.Row(visible=show_lora_params))def get_latest_status_message_and_logs(self) -> Tuple[str, str, str]:"""Get latest status message, log content, and status code in a safer way"""state = self.app.trainer.get_status()54 unmodified linesreturn (state["status"], state["message"], logs)def get_status_updates(self):"""Get status updates for text components (no variant property)"""status, message, logs = self.get_latest_status_message_and_logs()# Get current task if availablecurrent_task = ""if hasattr(self.app, 'log_parser') and self.app.log_parser is not None:current_task = self.app.log_parser.get_current_task_display()return message, logs, current_taskdef get_button_updates(self):"""Get button updates (with variant property)"""status, _, _ = self.get_latest_status_message_and_logs()# Add checkpoints detectionhas_checkpoints = len(list(OUTPUT_PATH.glob("checkpoint-*"))) > 0is_training = status in ["training", "initializing"]is_completed = status in ["completed", "error", "stopped"]start_text = "Continue Training" if has_checkpoints else "Start Training"# Create button updatesstart_btn = gr.Button(value=start_text,interactive=not is_training,variant="primary" if not is_training else "secondary")stop_btn = gr.Button(value="Stop at Last Checkpoint",interactive=is_training,variant="primary" if is_training else "secondary")# Add delete_checkpoints_btn or pause_resume_btnif "delete_checkpoints_btn" in self.components:third_btn = gr.Button("Delete All Checkpoints",interactive=has_checkpoints and not is_training,variant="stop")else:third_btn = gr.Button("Resume Training" if status == "paused" else "Pause Training",interactive=(is_training or status == "paused") and not is_completed,variant="secondary",visible=False)return start_btn, stop_btn, third_btndef update_training_ui(self, training_state: Dict[str, Any]):"""Update UI components based on training state"""updates = {}# Update status box with high-level informationstatus_text = []if training_state["status"] != "idle":status_text.extend([f"Status: {training_state['status']}",f"Progress: {training_state['progress']}",f"Step: {training_state['current_step']}/{training_state['total_steps']}",f"Time elapsed: {training_state['elapsed']}",f"Estimated remaining: {training_state['remaining']}","",f"Current loss: {training_state['step_loss']}",f"Learning rate: {training_state['learning_rate']}",f"Gradient norm: {training_state['grad_norm']}",f"Memory usage: {training_state['memory']}"])if training_state["error_message"]:status_text.append(f"\nError: {training_state['error_message']}")updates["status_box"] = "\n".join(status_text)# Add current task information to the dedicated boxif training_state.get("current_task"):updates["current_task_box"] = training_state["current_task"]else:updates["current_task_box"] = "No active task" if training_state["status"] != "training" else "Waiting for task information..."return updatesdef handle_pause_resume(self):"""Handle pause/resume button click"""status, _, _ = self.get_latest_status_message_and_logs()if status == "paused":self.app.trainer.resume_training()else:self.app.trainer.pause_training()# Return the updates separately for text and buttonsreturn (*self.get_status_updates(), *self.get_button_updates())def handle_stop(self):"""Handle stop button click"""self.app.trainer.stop_training()# Return the updates separately for text and buttonsreturn (*self.get_status_updates(), *self.get_button_updates())
8 unmodified lines910111213141576 unmodified lines929394959697985 unmodified lines10410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313440 unmodified lines17517617717817918020 unmodified lines2012022032042052062078 unmodified lines21621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524612 unmodified lines2592602612622632642659 unmodified lines2752762772782792802812822832842852869 unmodified lines2962972982993003013023033043053063078 unmodified linesfrom ..config import (STORAGE_PATH, VIDEOS_TO_SPLIT_PATH, STAGING_PATH, OUTPUT_PATH,TRAINING_PATH, LOG_FILE_PATH, TRAINING_PRESETS, TRAINING_VIDEOS_PATH, MODEL_PATH, OUTPUT_PATH,MODEL_TYPES, SMALL_TRAINING_BUCKETS, TRAINING_TYPES)from ..utils import count_media_files, format_media_title, TrainingLogParserfrom ..tabs import ImportTab, SplitTab, CaptionTab, TrainTab, ManageTab76 unmodified linesself.tabs["train_tab"].components["training_type"],self.tabs["train_tab"].components["lora_rank"],self.tabs["train_tab"].components["lora_alpha"],self.tabs["train_tab"].components["num_epochs"],self.tabs["train_tab"].components["batch_size"],self.tabs["train_tab"].components["learning_rate"],self.tabs["train_tab"].components["save_iterations"],5 unmodified linesdef _add_timers(self):"""Add auto-refresh timers to the UI"""# Status update timer (every 1 second)status_timer = gr.Timer(value=1)# Use a safer approach - check if the component exists before using itoutputs = [self.tabs["train_tab"].components["status_box"],self.tabs["train_tab"].components["log_box"],self.tabs["train_tab"].components["start_btn"],self.tabs["train_tab"].components["stop_btn"]]# Add current_task_box componentif "current_task_box" in self.tabs["train_tab"].components:outputs.append(self.tabs["train_tab"].components["current_task_box"])# Add delete_checkpoints_btn only if it existsif "delete_checkpoints_btn" in self.tabs["train_tab"].components:outputs.append(self.tabs["train_tab"].components["delete_checkpoints_btn"])else:# Add pause_resume_btn as fallbackoutputs.append(self.tabs["train_tab"].components["pause_resume_btn"])status_timer.tick(fn=self.tabs["train_tab"].get_latest_status_message_logs_and_button_labels,outputs=outputs)# Dataset refresh timer (every 5 seconds)40 unmodified linesif "model_type" in recovery_ui:model_type_value = recovery_ui["model_type"]# If it's an internal name, convert to display nameif model_type_value not in MODEL_TYPES:# Find the display name for this internal model type20 unmodified linesui_state["training_type"] = training_type_value# Copy other parametersfor param in ["lora_rank", "lora_alpha", "num_epochs","batch_size", "learning_rate", "save_iterations", "training_preset"]:if param in recovery_ui:ui_state[param] = recovery_ui[param]8 unmodified lines# Load values (potentially with recovery updates applied)ui_state = self.load_ui_values()# Ensure model_type is a display name, not internal namemodel_type_val = ui_state.get("model_type", list(MODEL_TYPES.keys())[0])if model_type_val not in MODEL_TYPES:# Convert from internal to display namefor display_name, internal_name in MODEL_TYPES.items():if internal_name == model_type_val:model_type_val = display_namebreak# Ensure training_type is a display name, not internal nametraining_type_val = ui_state.get("training_type", list(TRAINING_TYPES.keys())[0])if training_type_val not in TRAINING_TYPES:# Convert from internal to display namefor display_name, internal_name in TRAINING_TYPES.items():if internal_name == training_type_val:training_type_val = display_namebreaktraining_preset = ui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0])lora_rank_val = ui_state.get("lora_rank", "128")lora_alpha_val = ui_state.get("lora_alpha", "128")num_epochs_val = int(ui_state.get("num_epochs", 70))batch_size_val = int(ui_state.get("batch_size", 1))learning_rate_val = float(ui_state.get("learning_rate", 3e-5))save_iterations_val = int(ui_state.get("save_iterations", 500))# Initial current task valuecurrent_task_val = ""12 unmodified linestraining_type_val,lora_rank_val,lora_alpha_val,num_epochs_val,batch_size_val,learning_rate_val,save_iterations_val,9 unmodified linesui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0]),ui_state.get("model_type", list(MODEL_TYPES.keys())[0]),ui_state.get("training_type", list(TRAINING_TYPES.keys())[0]),ui_state.get("lora_rank", "128"),ui_state.get("lora_alpha", "128"),ui_state.get("num_epochs", 70),ui_state.get("batch_size", 1),ui_state.get("learning_rate", 3e-5),ui_state.get("save_iterations", 500))def update_ui_state(self, **kwargs):9 unmodified linesui_state = self.trainer.load_ui_state()# Ensure proper type conversion for numeric valuesui_state["lora_rank"] = ui_state.get("lora_rank", "128")ui_state["lora_alpha"] = ui_state.get("lora_alpha", "128")ui_state["num_epochs"] = int(ui_state.get("num_epochs", 70))ui_state["batch_size"] = int(ui_state.get("batch_size", 1))ui_state["learning_rate"] = float(ui_state.get("learning_rate", 3e-5))ui_state["save_iterations"] = int(ui_state.get("save_iterations", 500))return ui_state8 unmodified lines9101112131415161718192076 unmodified lines9798991001011021035 unmodified lines10911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014140 unmodified lines18218318418518618718818919019119220 unmodified lines2132142152162172182198 unmodified lines22822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128212 unmodified lines2952962972982993003019 unmodified lines3113123133143153163173183193203213229 unmodified lines3323333343353363373383393403413423438 unmodified linesfrom ..config import (STORAGE_PATH, VIDEOS_TO_SPLIT_PATH, STAGING_PATH, OUTPUT_PATH,TRAINING_PATH, LOG_FILE_PATH, TRAINING_PRESETS, TRAINING_VIDEOS_PATH, MODEL_PATH, OUTPUT_PATH,MODEL_TYPES, SMALL_TRAINING_BUCKETS, TRAINING_TYPES,DEFAULT_NB_TRAINING_STEPS, DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS,DEFAULT_BATCH_SIZE, DEFAULT_CAPTION_DROPOUT_P,DEFAULT_LEARNING_RATE,DEFAULT_LORA_RANK, DEFAULT_LORA_ALPHA,DEFAULT_LORA_RANK_STR, DEFAULT_LORA_ALPHA_STR)from ..utils import count_media_files, format_media_title, TrainingLogParserfrom ..tabs import ImportTab, SplitTab, CaptionTab, TrainTab, ManageTab76 unmodified linesself.tabs["train_tab"].components["training_type"],self.tabs["train_tab"].components["lora_rank"],self.tabs["train_tab"].components["lora_alpha"],self.tabs["train_tab"].components["train_steps"],self.tabs["train_tab"].components["batch_size"],self.tabs["train_tab"].components["learning_rate"],self.tabs["train_tab"].components["save_iterations"],5 unmodified linesdef _add_timers(self):"""Add auto-refresh timers to the UI"""# Status update timer for text components (every 1 second)status_timer = gr.Timer(value=1)status_timer.tick(fn=self.tabs["train_tab"].get_status_updates, # Use a new function that returns appropriate updatesoutputs=[self.tabs["train_tab"].components["status_box"],self.tabs["train_tab"].components["log_box"],self.tabs["train_tab"].components["current_task_box"] if "current_task_box" in self.tabs["train_tab"].components else None])# Button update timer for button components (every 1 second)button_timer = gr.Timer(value=1)button_outputs = [self.tabs["train_tab"].components["start_btn"],self.tabs["train_tab"].components["stop_btn"]]# Add delete_checkpoints_btn or pause_resume_btn as the third buttonif "delete_checkpoints_btn" in self.tabs["train_tab"].components:button_outputs.append(self.tabs["train_tab"].components["delete_checkpoints_btn"])elif "pause_resume_btn" in self.tabs["train_tab"].components:button_outputs.append(self.tabs["train_tab"].components["pause_resume_btn"])button_timer.tick(fn=self.tabs["train_tab"].get_button_updates, # Use a new function for button-specific updatesoutputs=button_outputs)# Dataset refresh timer (every 5 seconds)40 unmodified linesif "model_type" in recovery_ui:model_type_value = recovery_ui["model_type"]# Remove " (LoRA)" suffix if presentif " (LoRA)" in model_type_value:model_type_value = model_type_value.replace(" (LoRA)", "")logger.info(f"Removed (LoRA) suffix from model type: {model_type_value}")# If it's an internal name, convert to display nameif model_type_value not in MODEL_TYPES:# Find the display name for this internal model type20 unmodified linesui_state["training_type"] = training_type_value# Copy other parametersfor param in ["lora_rank", "lora_alpha", "train_steps","batch_size", "learning_rate", "save_iterations", "training_preset"]:if param in recovery_ui:ui_state[param] = recovery_ui[param]8 unmodified lines# Load values (potentially with recovery updates applied)ui_state = self.load_ui_values()# Ensure model_type is a valid display namemodel_type_val = ui_state.get("model_type", list(MODEL_TYPES.keys())[0])# Remove " (LoRA)" suffix if presentif " (LoRA)" in model_type_val:model_type_val = model_type_val.replace(" (LoRA)", "")logger.info(f"Removed (LoRA) suffix from model type: {model_type_val}")# Ensure it's a valid model type in the dropdownif model_type_val not in MODEL_TYPES:# Convert from internal to display name or use defaultmodel_type_found = Falsefor display_name, internal_name in MODEL_TYPES.items():if internal_name == model_type_val:model_type_val = display_namemodel_type_found = Truebreak# If still not found, use the first model typeif not model_type_found:model_type_val = list(MODEL_TYPES.keys())[0]logger.warning(f"Invalid model type '{model_type_val}', using default: {model_type_val}")# Ensure training_type is a valid display nametraining_type_val = ui_state.get("training_type", list(TRAINING_TYPES.keys())[0])if training_type_val not in TRAINING_TYPES:# Convert from internal to display name or use defaulttraining_type_found = Falsefor display_name, internal_name in TRAINING_TYPES.items():if internal_name == training_type_val:training_type_val = display_nametraining_type_found = Truebreak# If still not found, use the first training typeif not training_type_found:training_type_val = list(TRAINING_TYPES.keys())[0]logger.warning(f"Invalid training type '{training_type_val}', using default: {training_type_val}")# Validate training presettraining_preset = ui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0])if training_preset not in TRAINING_PRESETS:training_preset = list(TRAINING_PRESETS.keys())[0]logger.warning(f"Invalid training preset '{training_preset}', using default: {training_preset}")# Rest of the function remains unchangedlora_rank_val = ui_state.get("lora_rank", DEFAULT_LORA_RANK_STR)lora_alpha_val = ui_state.get("lora_alpha", DEFAULT_LORA_ALPHA_STR)train_steps_val = int(ui_state.get("train_steps", DEFAULT_NB_TRAINING_STEPS))batch_size_val = int(ui_state.get("batch_size", DEFAULT_BATCH_SIZE))learning_rate_val = float(ui_state.get("learning_rate", DEFAULT_LEARNING_RATE))save_iterations_val = int(ui_state.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS))# Initial current task valuecurrent_task_val = ""12 unmodified linestraining_type_val,lora_rank_val,lora_alpha_val,train_steps_val,batch_size_val,learning_rate_val,save_iterations_val,9 unmodified linesui_state.get("training_preset", list(TRAINING_PRESETS.keys())[0]),ui_state.get("model_type", list(MODEL_TYPES.keys())[0]),ui_state.get("training_type", list(TRAINING_TYPES.keys())[0]),ui_state.get("lora_rank", DEFAULT_LORA_RANK_STR),ui_state.get("lora_alpha", DEFAULT_LORA_ALPHA_STR),ui_state.get("train_steps", DEFAULT_NB_TRAINING_STEPS),ui_state.get("batch_size", DEFAULT_BATCH_SIZE),ui_state.get("learning_rate", DEFAULT_LEARNING_RATE),ui_state.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS))def update_ui_state(self, **kwargs):9 unmodified linesui_state = self.trainer.load_ui_state()# Ensure proper type conversion for numeric valuesui_state["lora_rank"] = ui_state.get("lora_rank", DEFAULT_LORA_RANK_STR)ui_state["lora_alpha"] = ui_state.get("lora_alpha", DEFAULT_LORA_ALPHA_STR)ui_state["train_steps"] = int(ui_state.get("train_steps", DEFAULT_NB_TRAINING_STEPS))ui_state["batch_size"] = int(ui_state.get("batch_size", DEFAULT_BATCH_SIZE))ui_state["learning_rate"] = float(ui_state.get("learning_rate", DEFAULT_LEARNING_RATE))ui_state["save_iterations"] = int(ui_state.get("save_iterations", DEFAULT_SAVE_CHECKPOINT_EVERY_N_STEPS))return ui_state
vms/config.py+116-89
vms/services/trainer.py+90-47
vms/tabs/train_tab.py+153-177
vms/ui/video_trainer_ui.py+79-43