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 lines853854855856857858859860852 unmodified linesdef _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.")def _display_helper_messages(args: argparse.Namespace):852 unmodified lines853854855856857858859860861852 unmodified linesdef _validate_validation_args(args: BaseArgs):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 lines1718192021222316 unmodified linesif parallel_backend.tensor_parallel_enabled:patch.patch_apply_rotary_emb_for_tp_compatibility()if args.training_type == TrainingType.LORA and len(args.layerwise_upcasting_modules) > 0:from dependencies.peft import patchpatch.patch_peft_move_adapter_to_device_of_base_layer()16 unmodified lines17181920212223242526272816 unmodified linesif 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 patchpatch.patch_time_text_image_embedding_forward()if args.training_type == TrainingType.LORA and len(args.layerwise_upcasting_modules) > 0:from .dependencies.peft import patchpatch.patch_peft_move_adapter_to_device_of_base_layer()
15 unmodified lines1617181920212212 unmodified lines3536373839404115 unmodified linesdef _perform_ltx_transformer_forward_patch() -> None:LTXVideoTransformer3DModel.forward = _patched_LTXVideoTransformer3Dforwarddef _perform_ltx_apply_rotary_emb_tensor_parallel_compatibility_patch() -> None:12 unmodified linesdiffusers.models.transformers.transformer_ltx.apply_rotary_emb = apply_rotary_embdef _patched_LTXVideoTransformer3Dforward(self,hidden_states: torch.Tensor,encoder_hidden_states: torch.Tensor,15 unmodified lines1617181920212212 unmodified lines3536373839404115 unmodified linesdef _perform_ltx_transformer_forward_patch() -> None:LTXVideoTransformer3DModel.forward = _patched_LTXVideoTransformer3D_forwarddef _perform_ltx_apply_rotary_emb_tensor_parallel_compatibility_patch() -> None:12 unmodified linesdiffusers.models.transformers.transformer_ltx.apply_rotary_emb = apply_rotary_embdef _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 lines334335336337338339107 unmodified lines447448449450451452453454274 unmodified lines729730731732733734333 unmodified linesparallel_backend = self.state.parallel_backendtrain_state = self.state.train_statedevice = parallel_backend.devicememory_statistics = utils.get_memory_statistics()logger.info(f"Memory before training start: {json.dumps(memory_statistics, indent=4)}")107 unmodified lineslogger.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.make_contiguous(latent_model_conditions)condition_model_conditions = utils.make_contiguous(condition_model_conditions)274 unmodified linesparallel_backend.wait_for_everyone()if not final_validation:self.transformer.train()def _evaluate(self) -> None:333 unmodified lines334335336337338339340107 unmodified lines448449450451452453454455274 unmodified lines730731732733734735736333 unmodified linesparallel_backend = self.state.parallel_backendtrain_state = self.state.train_statedevice = parallel_backend.devicedtype = self.args.transformer_dtypememory_statistics = utils.get_memory_statistics()logger.info(f"Memory before training start: {json.dumps(memory_statistics, indent=4)}")107 unmodified lineslogger.debug(f"Starting training step ({train_state.step}/{self.args.train_steps})")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 linesparallel_backend.wait_for_everyone()if not final_validation:self._move_components_to_device()self.transformer.train()def _evaluate(self) -> None:
145 unmodified lines14614714814915015115215320 unmodified lines17417517617717817918076 unmodified lines257258259260261262263264265266267268269270271272273274275282 unmodified lines55855956056156256356456556656756856957057157257357457557657757825 unmodified lines604605606607608609610145 unmodified lines# Sidebar for navigationwith 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")# Main content area with tabswith gr.Column():20 unmodified linestab_obj.create(project_tabs)# Monitoring View Tabwith gr.Tab("📊 System Monitoring", id=1) as monitoring_view:# Create monitoring tabswith gr.Tabs() as monitoring_tabs:# Store reference to monitoring tabs component76 unmodified linesself.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 buttonif "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 linesif is_training:# Active training detectedstart_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 trainingstart_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 buttonstart_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"}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 linesreturn (gr.Markdown(value=caption_title),gr.Markdown(value=f"{train_title} available for training"))def refresh_dataset(self):145 unmodified lines14614714814915015115215320 unmodified lines17417517617717817918076 unmodified lines257258259260261262263264265266267268269282 unmodified lines55255355455555655755855956056156256356456556656756856957057157225 unmodified lines598599600601602603604145 unmodified lines# Sidebar for navigationwith 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")# Main content area with tabswith gr.Column():20 unmodified linestab_obj.create(project_tabs)# Monitoring View Tabwith gr.Tab("🌡️ System Monitoring", id=1) as monitoring_view:# Create monitoring tabswith gr.Tabs() as monitoring_tabs:# Store reference to monitoring tabs component76 unmodified linesself.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)# Dataset refresh timer (every 5 seconds)dataset_timer = gr.Timer(value=5)dataset_timer.tick(282 unmodified linesif is_training:# Active training detectedstart_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 trainingstart_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 buttonstart_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"}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 linesreturn (gr.Markdown(value=caption_title),gr.Markdown(value=f"{train_title}"))def refresh_dataset(self):
31 unmodified lines3233343536373831 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")# Current metricswith gr.Row():31 unmodified lines3233343536373831 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")# Current metricswith gr.Row():
28 unmodified lines293031323334353637383940414243444546474849505113 unmodified lines656667686970717273747576777879808182834 unmodified lines888990919293944 unmodified lines9910010110210310410510610710810911028 unmodified lineswith gr.TabItem(self.title, id=self.id) as tab:with gr.Row():with gr.Column():gr.Markdown("## Download 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",variant="secondary",size="lg")self.components["download_model_btn"] = gr.DownloadButton("Download model weights",variant="secondary",size="lg")with gr.Row():with gr.Column():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 lineswith gr.Row():with gr.Column():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("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)",variant="secondary")self.components["delete_dataset_status"] = gr.Textbox(4 unmodified lineswith gr.Column(scale=1):self.components["delete_model_btn"] = gr.Button("Delete model (checkpoints, weights, config)",variant="secondary")self.components["delete_model_status"] = gr.Textbox(4 unmodified lineswith 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!")with gr.Row():self.components["global_stop_btn"] = gr.Button("Stop everything and delete my data",variant="stop")self.components["global_status"] = gr.Textbox(28 unmodified lines293031323334353637383940414243444546474849505113 unmodified lines656667686970717273747576777879808182834 unmodified lines888990919293944 unmodified lines9910010110210310410510610710810911028 unmodified lineswith gr.TabItem(self.title, id=self.id) as tab:with gr.Row():with gr.Column():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 (.zip)",variant="secondary",size="lg")self.components["download_model_btn"] = gr.DownloadButton("🧠 Download weights (.safetensors)",variant="secondary",size="lg")with gr.Row():with gr.Column():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 lineswith gr.Row():with gr.Column():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("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)",variant="secondary")self.components["delete_dataset_status"] = gr.Textbox(4 unmodified lineswith gr.Column(scale=1):self.components["delete_model_btn"] = gr.Button("🚨 Delete model (checkpoints, weights, config)",variant="secondary")self.components["delete_model_status"] = gr.Textbox(4 unmodified lineswith gr.Row():with gr.Column():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("🚨 Delete all project data and models (are you sure?!)",variant="stop")self.components["global_status"] = gr.Textbox(
28 unmodified lines29303132333435166 unmodified lines20220320420520620720820921021121228 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")with gr.Row():with gr.Column(scale=2):166 unmodified linesinteractive=False)with gr.Accordion("Log", open=True):self.components["log"] = gr.TextArea(label="Generation Log",interactive=False,lines=20)return tab28 unmodified lines29303132333435166 unmodified lines20220320420520620720820921021121228 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")with gr.Row():with gr.Column(scale=2):166 unmodified linesinteractive=False)with gr.Accordion("Log", open=False):self.components["log"] = gr.TextArea(label="Generation Log",interactive=False,lines=60)return tab
43 unmodified lines44454647484950130 unmodified lines181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259703 unmodified lines96396496596696796896943 unmodified lineswith gr.Row():with gr.Column():with gr.Row():self.components["train_title"] = gr.Markdown("## 0 files available for training (0 bytes)")with gr.Row():with gr.Column():130 unmodified lineswith gr.Row():with gr.Column():# Add description of the training buttonsself.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 textcheckpoints = 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 checkpointself.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 compatibilityself.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 buttonself.components["delete_checkpoints_btn"] = gr.Button("Delete All Checkpoints",variant="stop",interactive=has_checkpoints)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 progressself.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="",interactive=False,lines=60,max_lines=600,autoscroll=True)return tab703 unmodified lines# Create button updatesstart_btn = gr.Button(value="Start new training",interactive=not is_training,variant="primary" if not is_training else "secondary")43 unmodified lines44454647484950130 unmodified lines181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260703 unmodified lines96496596696796896997043 unmodified lineswith gr.Row():with gr.Column():with gr.Row():self.components["train_title"] = gr.Markdown("## 0 files in the training dataset")with gr.Row():with gr.Column():130 unmodified lineswith gr.Row():with gr.Column():with gr.Row():with gr.Column():# Add description of the training buttonsself.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 textcheckpoints = list(OUTPUT_PATH.glob("finetrainers_step_*"))has_checkpoints = len(checkpoints) > 0self.components["start_btn"] = gr.Button("🚀 Start new training",variant="primary",interactive=not ASK_USER_TO_DUPLICATE_SPACE)# Add new button for continuing from checkpointself.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 compatibilityself.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 buttonself.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 progressself.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)", open=False):self.components["log_box"] = gr.TextArea(#label="",interactive=False,lines=60,max_lines=600,autoscroll=True)return tab703 unmodified lines# Create button updatesstart_btn = gr.Button(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