Spaces:
Build error
Build error
Julian Bilcke commited on
Commit ·
24afbfe
1
Parent(s): d4b556f
fixes
Browse filesFiles changed (2)
9 unmodified lines10111213141516179 unmodified linesimport loggingfrom ..config import NORMALIZE_IMAGES_TO, TRAINING_VIDEOS_PATH, VIDEOS_TO_SPLIT_PATH, STAGING_PATH, DEFAULT_PROMPT_PREFIXfrom ..utils import normalize_image, is_image_file, is_video_file, add_prefix_to_captionfrom ..webdataset import webdataset_handlerlogger = logging.getLogger(__name__)9 unmodified lines101112131415169 unmodified linesimport loggingfrom ..config import NORMALIZE_IMAGES_TO, TRAINING_VIDEOS_PATH, VIDEOS_TO_SPLIT_PATH, STAGING_PATH, DEFAULT_PROMPT_PREFIXfrom ..utils import normalize_image, is_image_file, is_video_file, add_prefix_to_caption, webdataset_handlerlogger = logging.getLogger(__name__)
3 unmodified lines456789101112131415140 unmodified lines156157158159160161162150 unmodified lines31331431531631731841 unmodified lines3603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444458 unmodified lines4544554564574584597 unmodified lines4674684694704714724734744754764774784794804814824834844854864874884894907 unmodified lines4984995005015025035045055065075085095103 unmodified linesimport gradio as grimport loggingfrom typing import Dict, Any, List, Optional, Tuplefrom pathlib import Pathfrom .base_tab import BaseTabfrom ..config import TRAINING_PRESETS, OUTPUT_PATH, MODEL_TYPES, ASK_USER_TO_DUPLICATE_SPACE, SMALL_TRAINING_BUCKETSfrom ..utils import TrainingLogParserlogger = logging.getLogger(__name__)140 unmodified lines# Model type change eventdef update_model_info(model, training_type):params = self.get_default_params(MODEL_TYPES[model], TRAINING_TYPES[training_type])info = self.get_model_info(MODEL_TYPES[model], TRAINING_TYPES[training_type])show_lora_params = training_type == list(TRAINING_TYPES.keys())[0] # Show if LoRA Finetunereturn {150 unmodified linesself.components["pause_resume_btn"]])def handle_training_start(self, preset, model_type, training_type, *args):"""Handle training start with proper log parser reset and checkpoint detection"""41 unmodified linesexcept Exception as e:logger.exception("Error starting training")return f"Error starting training: {str(e)}", f"Exception: {str(e)}\n\nCheck the logs for more details."def get_model_info(self, model_type: str, training_type: str) -> str:"""Get information about the selected model type and training method"""training_method = "LoRA finetune" if training_type == "lora" else "Full finetune"if model_type == "hunyuan_video":base_info = """### HunyuanVideo- Required VRAM: ~48GB minimum- Recommended batch size: 1-2- Typical training time: 2-4 hours- Default resolution: 49x512x768"""if training_type == "lora":return base_info + "\n- Required VRAM: ~18GB minimum\n- Default LoRA rank: 128 (~400 MB)"else:return base_info + "\n- Required VRAM: ~21GB minimum\n- Full model size: ~8GB"elif model_type == "wan":base_info = """### Wan-2.1-T2V- Recommended batch size: 1-2- Typical training time: 1-3 hours- Default resolution: 49x512x768"""if training_type == "lora":return base_info + "\n- Required VRAM: ~16GB minimum\n- Default LoRA rank: 32 (~120 MB)"else:return base_info + "\n- **Full finetune not supported in this UI**" + "\n- Required VRAM: ~18GB minimum\n- Default LoRA rank: 128 (~400 MB)"else:return base_info + "\n- Required VRAM: ~21GB minimum\n- Full model size: ~8GB"elif model_type == "wan":base_info = """### Wan-2.1-T2V- Recommended batch size: 1-2- Typical training time: 1-3 hours- Default resolution: 49x512x768"""if training_type == "lora":return base_info + "\n- Required VRAM: ~16GB minimum\n- Default LoRA rank: 32 (~120 MB)"else:return base_info + "\n- **Full finetune not supported in this UI**" + "\n- Default LoRA rank: 128 (~600 MB)"else:return base_info + "\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 hours- Default resolution: 49x512x768"""if training_type == "lora":return base_def get_default_params(self, model_type: str) -> Dict[str, Any]:"""Get default training parameters for model type"""if model_type == "hunyuan_video":return {"num_epochs": 70,"batch_size": 1,"learning_rate": 2e-5,"save_iterations": 500,"video_resolution_buckets": SMALL_TRAINING_BUCKETS,"video_reshape_mode": "center","caption_dropout_p": 0.05,"gradient_accumulation_steps": 1,"rank": 128,"lora_alpha": 128}else: # ltx_videoreturn {"num_epochs": 70,"batch_size": 1,"learning_rate": 3e-5,"save_iterations": 500,"video_resolution_buckets": SMALL_TRAINING_BUCKETS,"video_reshape_mode": "center","caption_dropout_p": 0.05,"gradient_accumulation_steps": 4,"rank": 128,"lora_alpha": 128}def update_training_params(self, preset_name: str) -> Tuple:8 unmodified lineskey for key, value in MODEL_TYPES.items()if value == preset["model_type"])# Get preset description for displaydescription = preset.get("description", "")7 unmodified linesinfo_text = f"{description}{bucket_info}"# Return values in the same order as the output components# 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["lora_rank"]lora_alpha_val = current_state.get("lora_alpha") if current_state.get("lora_alpha") != preset.get("lora_alpha", "128") else preset["lora_alpha"]num_epochs_val = current_state.get("num_epochs") if current_state.get("num_epochs") != preset.get("num_epochs", 70) else preset["num_epochs"]batch_size_val = current_state.get("batch_size") if current_state.get("batch_size") != preset.get("batch_size", 1) else preset["batch_size"]learning_rate_val = current_state.get("learning_rate") if current_state.get("learning_rate") != preset.get("learning_rate", 3e-5) else preset["learning_rate"]save_iterations_val = current_state.get("save_iterations") if current_state.get("save_iterations") != preset.get("save_iterations", 500) else preset["save_iterations"]return (model_display_name,lora_rank_val,lora_alpha_val,num_epochs_val,batch_size_val,learning_rate_val,save_iterations_val,info_text)def update_training_ui(self, training_state: Dict[str, Any]):7 unmodified linesf"Status: {training_state['status']}",f"Progress: {training_state['progress']}",f"Step: {training_state['current_step']}/{training_state['total_steps']}",# Epoch information# there is an issue with how epoch is reported because we display:# Progress: 96.9%, Step: 872/900, Epoch: 12/50# we should probably just show the steps#f"Epoch: {training_state['current_epoch']}/{training_state['total_epochs']}",f"Time elapsed: {training_state['elapsed']}",f"Estimated remaining: {training_state['remaining']}","",3 unmodified lines456789101112131415140 unmodified lines156157158159160161162150 unmodified lines31331431531631731831932032132232332432532632732832933033133233341 unmodified lines3753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764778 unmodified lines4864874884894904914924934944954964977 unmodified lines5055065075085095105115125135145155165175185195205215225235245255265275285295305315325337 unmodified lines5415425435445455463 unmodified linesimport gradio as grimport loggingimport osfrom typing import Dict, Any, List, Optional, Tuplefrom 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__)140 unmodified lines# Model type change eventdef update_model_info(model, training_type):params = self.get_default_params(MODEL_TYPES[model], TRAINING_TYPES[training_type])info = self.get_model_info(model, training_type)show_lora_params = training_type == list(TRAINING_TYPES.keys())[0] # Show if LoRA Finetunereturn {150 unmodified linesself.components["pause_resume_btn"]])# Add an event handler for delete_checkpoints_btnself.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"]])def handle_training_start(self, preset, model_type, training_type, *args):"""Handle training start with proper log parser reset and checkpoint detection"""41 unmodified linesexcept Exception as e:logger.exception("Error starting training")return f"Error starting training: {str(e)}", f"Exception: {str(e)}\n\nCheck the logs for more details."def 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-2- Typical training time: 2-4 hours- Default resolution: 49x512x768"""if training_type == "LoRA Finetune":return base_info + "\n- Required VRAM: ~18GB minimum\n- Default LoRA rank: 128 (~400 MB)"else: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 hours- Default resolution: 49x512x768"""if training_type == "LoRA Finetune":return base_info + "\n- Required VRAM: ~18GB minimum\n- Default LoRA rank: 128 (~400 MB)"else: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**"# Default fallbackreturn f"### {model_type}\nPlease check documentation for VRAM requirements and recommended settings."def get_default_params(self, model_type: str, training_type: str) -> Dict[str, Any]:"""Get default training parameters for model type"""# Find preset that matches model type and training typematching_presets = [preset for preset_name, preset in TRAINING_PRESETS.items()if preset["model_type"] == model_type and preset["training_type"] == training_type]if matching_presets:# 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:8 unmodified lineskey for key, value in MODEL_TYPES.items()if value == preset["model_type"])# Find the display name that maps to our training typetraining_display_name = next(key for key, value in TRAINING_TYPES.items()if value == preset["training_type"])# Get preset description for displaydescription = preset.get("description", "")7 unmodified linesinfo_text = f"{description}{bucket_info}"# Check if LoRA params should be visibleshow_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 (model_display_name,training_display_name,lora_rank_val,lora_alpha_val,num_epochs_val,batch_size_val,learning_rate_val,save_iterations_val,info_text,gr.Row(visible=show_lora_params))def update_training_ui(self, training_state: Dict[str, Any]):7 unmodified linesf"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']}","",
vms/services/importer.py+1-2
vms/tabs/train_tab.py+94-58