Julian Bilcke commited on
Commit ·
77ce18f
1
Parent(s): a29dde5
add some fixes to the UI
Browse filesFiles changed (10)
- finetrainers/args.py+3-2
- finetrainers/patches/__init__.py+6-1
- finetrainers/patches/models/ltx_video/patch.py+2-2
- finetrainers/patches/models/wan/patch.pyAdded+33
- finetrainers/trainer/sft_trainer/trainer.py+4-2
- vms/ui/app_ui.py+12-18
- vms/ui/monitoring/tabs/general_tab.py+1-1
- vms/ui/project/tabs/manage_tab.py+11-11
- vms/ui/project/tabs/preview_tab.py+3-3
- vms/ui/project/tabs/train_tab.py+72-71
852 unmodified lines853854855856857856857858859860861852 unmodified lines
def _validate_validation_args(args: BaseArgs): if args.dp_shards > 1 and args.enable_model_cpu_offload: raise ValueError("Model CPU offload is not supported with FSDP at the moment.") if args.enable_model_cpu_offload: if any(x > 1 for x in [args.pp_degree, args.dp_degree, args.dp_shards, args.cp_degree, args.tp_degree]): raise ValueError("Model CPU offload is not supported on multi-GPU at the moment.")
def _display_helper_messages(args: argparse.Namespace):16 unmodified lines1718192021222324252126272816 unmodified lines if parallel_backend.tensor_parallel_enabled: patch.patch_apply_rotary_emb_for_tp_compatibility()
if args.model_name == ModelType.WAN and "transformer" in args.layerwise_upcasting_modules: from .models.wan import patch
patch.patch_time_text_image_embedding_forward()
if args.training_type == TrainingType.LORA and len(args.layerwise_upcasting_modules) > 0: from dependencies.peft import patch from .dependencies.peft import patch
patch.patch_peft_move_adapter_to_device_of_base_layer()15 unmodified lines161718191920212212 unmodified lines353637383839404115 unmodified lines
def _perform_ltx_transformer_forward_patch() -> None: LTXVideoTransformer3DModel.forward = _patched_LTXVideoTransformer3Dforward LTXVideoTransformer3DModel.forward = _patched_LTXVideoTransformer3D_forward
def _perform_ltx_apply_rotary_emb_tensor_parallel_compatibility_patch() -> None:12 unmodified lines diffusers.models.transformers.transformer_ltx.apply_rotary_emb = apply_rotary_emb
def _patched_LTXVideoTransformer3Dforward(def _patched_LTXVideoTransformer3D_forward( self, hidden_states: torch.Tensor, encoder_hidden_states: torch.Tensor,123456789101112131415161718192021222324252627282930313233from typing import Optional
import diffusersimport torch
def patch_time_text_image_embedding_forward() -> None: _patch_time_text_image_embedding_forward()
def _patch_time_text_image_embedding_forward() -> None: diffusers.models.transformers.transformer_wan.WanTimeTextImageEmbedding.forward = ( _patched_WanTimeTextImageEmbedding_forward )
def _patched_WanTimeTextImageEmbedding_forward( self, timestep: torch.Tensor, encoder_hidden_states: torch.Tensor, encoder_hidden_states_image: Optional[torch.Tensor] = None,): # Some code has been removed compared to original implementation in Diffusers # Also, timestep is typed as that of encoder_hidden_states timestep = self.timesteps_proj(timestep).type_as(encoder_hidden_states) temb = self.time_embedder(timestep).type_as(encoder_hidden_states) timestep_proj = self.time_proj(self.act_fn(temb))
encoder_hidden_states = self.text_embedder(encoder_hidden_states) if encoder_hidden_states_image is not None: encoder_hidden_states_image = self.image_embedder(encoder_hidden_states_image)
return temb, timestep_proj, encoder_hidden_states, encoder_hidden_states_image333 unmodified lines334335336337338339340107 unmodified lines448449450450451451452453454455274 unmodified lines730731732733734735736333 unmodified lines parallel_backend = self.state.parallel_backend train_state = self.state.train_state device = parallel_backend.device dtype = self.args.transformer_dtype
memory_statistics = utils.get_memory_statistics() logger.info(f"Memory before training start: {json.dumps(memory_statistics, indent=4)}")107 unmodified lines
logger.debug(f"Starting training step ({train_state.step}/{self.args.train_steps})")
utils.align_device_and_dtype(latent_model_conditions, device, self.args.transformer_dtype) utils.align_device_and_dtype(condition_model_conditions, device, self.args.transformer_dtype) latent_model_conditions = utils.align_device_and_dtype(latent_model_conditions, device, dtype) condition_model_conditions = utils.align_device_and_dtype(condition_model_conditions, device, dtype) latent_model_conditions = utils.make_contiguous(latent_model_conditions) condition_model_conditions = utils.make_contiguous(condition_model_conditions)
274 unmodified lines
parallel_backend.wait_for_everyone() if not final_validation: self._move_components_to_device() self.transformer.train()
def _evaluate(self) -> None:145 unmodified lines14614714814915014915015115215320 unmodified lines17417517617717717817918076 unmodified lines257258259260260261262263264265266267268269270271272266267268269282 unmodified lines55255355456156255555655755855956056756856156256356456556657356756857556957057157225 unmodified lines598599600607601602603604145 unmodified lines # Sidebar for navigation with gr.Sidebar(position="left", open=True): gr.Markdown("# 🎞️ Video Model Studio") self.components["current_project_btn"] = gr.Button("Current Project", variant="primary") self.components["system_monitoring_btn"] = gr.Button("System Monitoring") self.components["current_project_btn"] = gr.Button("📂 Current Project", variant="primary") self.components["system_monitoring_btn"] = gr.Button("🌡️ System Monitoring")
# Main content area with tabs with gr.Column():20 unmodified lines tab_obj.create(project_tabs) # Monitoring View Tab with gr.Tab("📊 System Monitoring", id=1) as monitoring_view: with gr.Tab("🌡️ System Monitoring", id=1) as monitoring_view: # Create monitoring tabs with gr.Tabs() as monitoring_tabs: # Store reference to monitoring tabs component76 unmodified lines self.project_tabs["train_tab"].components["stop_btn"], self.project_tabs["train_tab"].components["delete_checkpoints_btn"] ]
button_timer.tick( fn=self.project_tabs["train_tab"].get_button_updates, outputs=button_outputs ) # Add delete_checkpoints_btn or pause_resume_btn as the third button if "delete_checkpoints_btn" in self.project_tabs["train_tab"].components: button_outputs.append(self.project_tabs["train_tab"].components["delete_checkpoints_btn"]) elif "pause_resume_btn" in self.project_tabs["train_tab"].components: button_outputs.append(self.project_tabs["train_tab"].components["pause_resume_btn"]) # Dataset refresh timer (every 5 seconds) dataset_timer = gr.Timer(value=5) dataset_timer.tick(282 unmodified lines if is_training: # Active training detected start_btn_props = {"interactive": False, "variant": "secondary", "value": "Start new training"} resume_btn_props = {"interactive": False, "variant": "secondary", "value": "Start from latest checkpoint"} start_btn_props = {"interactive": False, "variant": "secondary", "value": "🚀 Start new training"} resume_btn_props = {"interactive": False, "variant": "secondary", "value": "🛰️ Start from latest checkpoint"} stop_btn_props = {"interactive": True, "variant": "primary", "value": "Stop at Last Checkpoint"} delete_btn_props = {"interactive": False, "variant": "stop", "value": "Delete All Checkpoints"} else: # No active training start_btn_props = {"interactive": True, "variant": "primary", "value": "Start new training"} resume_btn_props = {"interactive": has_checkpoints, "variant": "primary", "value": "Start from latest checkpoint"} start_btn_props = {"interactive": True, "variant": "primary", "value": "🚀 Start new training"} resume_btn_props = {"interactive": has_checkpoints, "variant": "primary", "value": "🛰️ Start from latest checkpoint"} stop_btn_props = {"interactive": False, "variant": "secondary", "value": "Stop at Last Checkpoint"} delete_btn_props = {"interactive": has_checkpoints, "variant": "stop", "value": "Delete All Checkpoints"} else: # Use button states from recovery, adding the new resume button start_btn_props = ui_updates.get("start_btn", {"interactive": True, "variant": "primary", "value": "Start new training"}) start_btn_props = ui_updates.get("start_btn", {"interactive": True, "variant": "primary", "value": "🚀 Start new training"}) resume_btn_props = {"interactive": has_checkpoints and not self.training.is_training_running(), "variant": "primary", "value": "Start from latest checkpoint"} "variant": "primary", "value": "🛰️ Start from latest checkpoint"} stop_btn_props = ui_updates.get("stop_btn", {"interactive": False, "variant": "secondary", "value": "Stop at Last Checkpoint"}) delete_btn_props = ui_updates.get("delete_checkpoints_btn", {"interactive": has_checkpoints, "variant": "stop", "value": "Delete All Checkpoints"}) 25 unmodified lines return ( gr.Markdown(value=caption_title), gr.Markdown(value=f"{train_title} available for training") gr.Markdown(value=f"{train_title}") ) def refresh_dataset(self):31 unmodified lines323334353536373831 unmodified lines """Create the Monitor tab UI components""" with gr.TabItem(self.title, id=self.id) as tab: with gr.Row(): gr.Markdown("## System Monitoring") gr.Markdown("## 🌡️ System Monitoring") # Current metrics with gr.Row():28 unmodified lines29303132323334353637373839404142424344454647484849505113 unmodified lines656667686869707172737474757677787980808182834 unmodified lines88899091919293944 unmodified lines9910010110210310210310410510610710710810911028 unmodified lines with gr.TabItem(self.title, id=self.id) as tab: with gr.Row(): with gr.Column(): gr.Markdown("## Download your model") gr.Markdown("## 🏦 Backup your model") gr.Markdown("There is currently a bug, you might have to click multiple times to trigger a download.")
with gr.Row(): self.components["download_dataset_btn"] = gr.DownloadButton( "Download training dataset", "📦 Download training dataset (.zip)", variant="secondary", size="lg" ) self.components["download_model_btn"] = gr.DownloadButton( "Download model weights", "🧠 Download weights (.safetensors)", variant="secondary", size="lg" ) with gr.Row(): with gr.Column(): gr.Markdown("## Publish your model") gr.Markdown("## 📡 Publish your model") gr.Markdown("You model can be pushed to Hugging Face (this will use HF_API_TOKEN)")
with gr.Row():13 unmodified lines
with gr.Row(): with gr.Column(): gr.Markdown("## Delete your data") gr.Markdown("## ♻️ Delete your data") gr.Markdown("Make sure you have made a backup first.") gr.Markdown("If you are deleting because of a bug, remember you can use the Developer Mode on HF to inspect the working directory (in /data or .data)")
with gr.Row(): with gr.Column(): gr.Markdown("### Delete specific data") gr.Markdown("### 🧽 Delete specific data") gr.Markdown("You can selectively delete either the dataset and/or the last model data.")
with gr.Row(): with gr.Column(scale=1): self.components["delete_dataset_btn"] = gr.Button( "Delete dataset (images, video, captions)", "🚨 Delete dataset (images, video, captions)", variant="secondary" ) self.components["delete_dataset_status"] = gr.Textbox(4 unmodified lines with gr.Column(scale=1): self.components["delete_model_btn"] = gr.Button( "Delete model (checkpoints, weights, config)", "🚨 Delete model (checkpoints, weights, config)", variant="secondary" ) self.components["delete_model_status"] = gr.Textbox(4 unmodified lines with gr.Row(): with gr.Column(): gr.Markdown("### Delete everything") gr.Markdown("This will delete both the dataset (all images, videos and captions) AND the latest model (weights, checkpoints, settings). So use with care!") gr.Markdown("### ☢️ Nuke all project data") gr.Markdown("This will nuke the original dataset (all images, videos and captions), the training dataset, and the model outputs (weights, checkpoints, settings). So use with care!")
with gr.Row(): self.components["global_stop_btn"] = gr.Button( "Stop everything and delete my data", "🚨 Delete all project data and models (are you sure?!)", variant="stop" ) self.components["global_status"] = gr.Textbox(28 unmodified lines2930313232333435166 unmodified lines20220320420520520620720820920921021121228 unmodified lines """Create the Preview tab UI components""" with gr.TabItem(self.title, id=self.id) as tab: with gr.Row(): gr.Markdown("## Preview your model") gr.Markdown("## 🔬 Preview your model") with gr.Row(): with gr.Column(scale=2):166 unmodified lines interactive=False ) with gr.Accordion("Log", open=True): with gr.Accordion("Log", open=False): self.components["log"] = gr.TextArea( label="Generation Log", interactive=False, lines=20 lines=60 ) return tab43 unmodified lines4445464747484950130 unmodified lines181182183184185186187188189190191192193194184196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230185186187188189190191192193194195196197198232233234235236237238239240241242243244245246247248249250251199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245253254255246247248249250251252253254255256257258259260703 unmodified lines96496596696696796896997043 unmodified lines with gr.Row(): with gr.Column(): with gr.Row(): self.components["train_title"] = gr.Markdown("## 0 files available for training (0 bytes)") self.components["train_title"] = gr.Markdown("## 0 files in the training dataset")
with gr.Row(): with gr.Column():130 unmodified lines
with gr.Row(): with gr.Column(): # Add description of the training buttons self.components["training_buttons_info"] = gr.Markdown(""" ## Training Options - **Start new training**: Begins training from scratch (clears previous checkpoints) - **Start from latest checkpoint**: Continues training from the most recent checkpoint """) with gr.Row(): # Check for existing checkpoints to determine button text checkpoints = list(OUTPUT_PATH.glob("finetrainers_step_*")) has_checkpoints = len(checkpoints) > 0
# Rename "Start Training" to "Start new training" self.components["start_btn"] = gr.Button( "Start new training", variant="primary", interactive=not ASK_USER_TO_DUPLICATE_SPACE ) # Add new button for continuing from checkpoint self.components["resume_btn"] = gr.Button( "Start from latest checkpoint", variant="primary", interactive=has_checkpoints and not ASK_USER_TO_DUPLICATE_SPACE ) with gr.Row(): # Just use stop and pause buttons for now to ensure compatibility self.components["stop_btn"] = gr.Button( "Stop at Last Checkpoint", variant="primary", interactive=False ) self.components["pause_resume_btn"] = gr.Button( "Resume Training", variant="secondary", interactive=False, visible=False ) # Add delete checkpoints button self.components["delete_checkpoints_btn"] = gr.Button( "Delete All Checkpoints", variant="stop", interactive=has_checkpoints ) with gr.Row(): with gr.Column(): # Add description of the training buttons self.components["training_buttons_info"] = gr.Markdown(""" ## ⚗️ Train your model on your dataset - **Start new training**: Begins training from scratch (clears previous checkpoints) - **Start from latest checkpoint**: Continues training from the most recent checkpoint """) with gr.Row(): # Check for existing checkpoints to determine button text checkpoints = list(OUTPUT_PATH.glob("finetrainers_step_*")) has_checkpoints = len(checkpoints) > 0
with gr.Column(): with gr.Row(): with gr.Column(): self.components["status_box"] = gr.Textbox( label="Training Status", interactive=False, lines=4 ) # Add new component for current task progress self.components["current_task_box"] = gr.Textbox( label="Current Task Progress", interactive=False, lines=3, elem_id="current_task_display" ) with gr.Accordion("Finetrainers output (or see app logs for more details)"): self.components["log_box"] = gr.TextArea( #label="", self.components["start_btn"] = gr.Button( "🚀 Start new training", variant="primary", interactive=not ASK_USER_TO_DUPLICATE_SPACE ) # Add new button for continuing from checkpoint self.components["resume_btn"] = gr.Button( "🛰️ Start from latest checkpoint", variant="primary", interactive=has_checkpoints and not ASK_USER_TO_DUPLICATE_SPACE ) with gr.Row(): # Just use stop and pause buttons for now to ensure compatibility self.components["stop_btn"] = gr.Button( "Stop at Last Checkpoint", variant="primary", interactive=False ) self.components["pause_resume_btn"] = gr.Button( "Resume Training", variant="secondary", interactive=False, visible=False ) # Add delete checkpoints button self.components["delete_checkpoints_btn"] = gr.Button( "Delete All Checkpoints", variant="stop", interactive=has_checkpoints )
with gr.Row(): with gr.Column(): self.components["status_box"] = gr.Textbox( label="Training Status", interactive=False, lines=4 ) # Add new component for current task progress self.components["current_task_box"] = gr.Textbox( label="Current Task Progress", interactive=False, lines=60, max_lines=600, autoscroll=True lines=3, elem_id="current_task_display" ) with gr.Accordion("Finetrainers output (or see app logs for more details)", open=False): self.components["log_box"] = gr.TextArea( #label="", interactive=False, lines=60, max_lines=600, autoscroll=True ) return tab 703 unmodified lines # Create button updates start_btn = gr.Button( value="Start new training", value="🚀 Start new training", interactive=not is_training, variant="primary" if not is_training else "secondary" )finetrainers/args.py+3-2
finetrainers/patches/__init__.py+6-1
finetrainers/patches/models/ltx_video/patch.py+2-2
finetrainers/patches/models/wan/patch.pyAdded+33
finetrainers/trainer/sft_trainer/trainer.py+4-2
vms/ui/app_ui.py+12-18
vms/ui/monitoring/tabs/general_tab.py+1-1
vms/ui/project/tabs/manage_tab.py+11-11
vms/ui/project/tabs/preview_tab.py+3-3
vms/ui/project/tabs/train_tab.py+72-71