Spaces:
Build error
Build error
Julian Bilcke commited on
Commit ·
24afbfe
1
Parent(s): d4b556f
fixes
Browse filesFiles changed (2)
9 unmodified lines1011121314131415169 unmodified linesimport logging
from ..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_handlerfrom ..utils import normalize_image, is_image_file, is_video_file, add_prefix_to_caption, webdataset_handler
logger = logging.getLogger(__name__)
3 unmodified lines4567891011111212131415140 unmodified lines156157158159159160161162150 unmodified lines31331431531631731831932032132232332432532632732832933033133233341 unmodified lines3753763773633783793803673683693813823833843853863873763883893903793913923813823833933943953963973983873883893903994004014024033944044054064074084094004104114024034124134064074084094104114124134144144154164174164184194204214224234244254264274284294304314324334344354364374384394404414424434444244254264274284294454464474484494504514524534544554564314574584594604614624634644654664674684694704714724374384394404414424734744754764778 unmodified lines4864874884894904914924934944954964977 unmodified lines5055065074705085095105114724734744754764775125135145155165175185195205215225235245255265275284875295305315325337 unmodified lines5415425435015025035045055065075445455463 unmodified lines
import gradio as grimport loggingimport osfrom typing import Dict, Any, List, Optional, Tuplefrom pathlib import Path
from .base_tab import BaseTabfrom ..config import TRAINING_PRESETS, OUTPUT_PATH, MODEL_TYPES, ASK_USER_TO_DUPLICATE_SPACE, SMALL_TRAINING_BUCKETSfrom ..utils import TrainingLogParserfrom ..config import TRAINING_PRESETS, OUTPUT_PATH, MODEL_TYPES, ASK_USER_TO_DUPLICATE_SPACE, SMALL_TRAINING_BUCKETS, TRAINING_TYPES
logger = logging.getLogger(__name__)
140 unmodified lines # Model type change event def 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]) info = self.get_model_info(model, training_type) show_lora_params = training_type == list(TRAINING_TYPES.keys())[0] # Show if LoRA Finetune return {150 unmodified lines self.components["pause_resume_btn"] ] )
# Add an event handler for delete_checkpoints_btn self.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 lines except 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": 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": 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" return base_info + "\n- Required VRAM: ~48GB minimum\n- **Full finetune not recommended due to VRAM requirements**" elif model_type == "wan": base_info = """### Wan-2.1-T2V - Recommended batch size: 1-2 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": 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)" 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": 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": 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 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_ # Default fallback return f"### {model_type}\nPlease check documentation for VRAM requirements and recommended settings."
def get_default_params(self, model_type: str) -> Dict[str, Any]: 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 type matching_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 preset preset = 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 fallbacks 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 "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" } else: # ltx_video 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 defaults return { "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 "lora_rank": "128", "lora_alpha": "128" } def update_training_params(self, preset_name: str) -> Tuple:8 unmodified lines key for key, value in MODEL_TYPES.items() if value == preset["model_type"] ) # Find the display name that maps to our training type training_display_name = next( key for key, value in TRAINING_TYPES.items() if value == preset["training_type"] ) # Get preset description for display description = preset.get("description", "")7 unmodified lines info_text = f"{description}{bucket_info}" # Return values in the same order as the output components # Check if LoRA params should be visible show_lora_params = preset["training_type"] == "lora" # Use preset defaults but preserve user-modified values if they exist lora_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"] lora_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 components return ( 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 info_text, gr.Row(visible=show_lora_params) ) def update_training_ui(self, training_state: Dict[str, Any]):7 unmodified lines f"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']}", "",vms/services/importer.py+1-2
vms/tabs/train_tab.py+94-58