jbilcke-hf HF staff commited on
Commit
883eb72
·
1 Parent(s): 3bdc963

Fix for #22

Browse files
docs/vms/Investigating issues in production.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Investigating issue in production
2
+
3
+ Note: the following document is meant for maintainers of VMS.
4
+
5
+ It describe things that are normally only useful during development, for instance if there are bugs.
6
+
7
+ Normal VMS users do not need to read this document and perform those steps, since in theory VMS is already taking care of things (eg. automatic fix of corrupted internal JSON files) or providing ways to solve common issues (eg. buttons to download or delete data).
8
+
9
+ ## Backuping data
10
+
11
+ During development of VMs, there might be bugs creating data corruption.
12
+
13
+ To avoid reseting the /data folder all the time, I suggest simply doing backups of what you need.
14
+
15
+ 1. run the space in developer mode
16
+ 2. open vscode from the dev mode panel
17
+ 3. go to the data dir (eg /data if you have persistence, or .data otherwise)
18
+ 4. do whatever you want (you are the developer, after all)
19
+ 5. for instance you can edit files, delete stuff etc
20
+
21
+ ### Manual backout of the output dir
22
+
23
+ ```bash
24
+ mkdir /data/backup
25
+
26
+ # to copy training data
27
+ cp -r /data/training /data/backup/training
28
+
29
+ # to copy generated models and checkpoints
30
+ cp -r /data/output /data/backup/output
31
+ ```
32
+
33
+ ### Manual restore of a backup
34
+
35
+ ```bash
36
+ # if you already have a backup of output/ then you can delete its content
37
+ rm -Rf output/*
38
+
39
+ # restore the backup, for instance the weights and checkpoints
40
+ cp -r backup/output/* output/
41
+ ```
42
+
43
+ ### Manual restore of UI state
44
+
45
+ Restoring the UI state can be tricky as it is being modified by Gradio.
46
+
47
+ I recommend shutting Gradio down, but this will kill the space and the VS Code session.
48
+
49
+ So a tricky is to restart Gradio and immediately perform this command:
50
+
51
+ ```bash
52
+ cp backup/output/ui_state.json output/
53
+ ```
54
+
55
+ That way Gradio will inialize itself with the backuped UI state.
vms/ui/project/services/previewing.py CHANGED
@@ -69,7 +69,7 @@ class PreviewingService:
69
  num_frames: int,
70
  guidance_scale: float,
71
  flow_shift: float,
72
- lora_weight: float,
73
  inference_steps: int,
74
  seed: int = -1,
75
  enable_cpu_offload: bool = True,
@@ -87,15 +87,15 @@ class PreviewingService:
87
  # Return updated log string for UI updates
88
  return "\n".join(log_messages)
89
 
90
- # Find latest LoRA weights if lora_weight > 0
91
  lora_path = None
92
- using_lora = lora_weight > 0
93
 
94
  if using_lora:
95
  lora_path = self.find_latest_lora_weights()
96
  if not lora_path:
97
  return None, "Error: No LoRA weights found", log("Error: No LoRA weights found in output directory")
98
- log(f"Using LoRA weights with weight {lora_weight}")
99
  else:
100
  log("Using original model without LoRA weights")
101
 
@@ -155,7 +155,7 @@ class PreviewingService:
155
  if using_lora and lora_path:
156
  log(f"Using LoRA weights from: {lora_path}")
157
  log(f"Resolution: {width}x{height}, Frames: {num_frames}, FPS: {fps}")
158
- log(f"Guidance Scale: {guidance_scale}, Flow Shift: {flow_shift}, LoRA Weight: {lora_weight if using_lora else 0}")
159
  log(f"Generation Seed: {seed}")
160
  #log(f"Prompt: {full_prompt}")
161
  #log(f"Negative Prompt: {negative_prompt}")
@@ -164,21 +164,21 @@ class PreviewingService:
164
  if internal_model_type == "wan":
165
  return self.generate_wan_video(
166
  full_prompt, negative_prompt, width, height, num_frames,
167
- guidance_scale, flow_shift, lora_path, lora_weight,
168
  inference_steps, seed, enable_cpu_offload, fps, log,
169
  model_version, conditioning_image
170
  )
171
  elif internal_model_type == "ltx_video":
172
  return self.generate_ltx_video(
173
  full_prompt, negative_prompt, width, height, num_frames,
174
- guidance_scale, flow_shift, lora_path, lora_weight,
175
  inference_steps, seed, enable_cpu_offload, fps, log,
176
  model_version, conditioning_image
177
  )
178
  elif internal_model_type == "hunyuan_video":
179
  return self.generate_hunyuan_video(
180
  full_prompt, negative_prompt, width, height, num_frames,
181
- guidance_scale, flow_shift, lora_path, lora_weight,
182
  inference_steps, seed, enable_cpu_offload, fps, log,
183
  model_version, conditioning_image
184
  )
@@ -199,7 +199,7 @@ class PreviewingService:
199
  guidance_scale: float,
200
  flow_shift: float,
201
  lora_path: str,
202
- lora_weight: float,
203
  inference_steps: int,
204
  seed: int = -1,
205
  enable_cpu_offload: bool = True,
@@ -257,11 +257,9 @@ class PreviewingService:
257
  pipe.enable_model_cpu_offload()
258
 
259
  # Apply LoRA weights if using them
260
- if lora_weight > 0 and lora_path:
261
- log_fn(f"Loading LoRA weights from {lora_path} with weight {lora_weight}...")
262
  pipe.load_lora_weights(lora_path)
263
- # TODO: Set the lora scale directly instead of using fuse_lora
264
- #pipe._lora_scale = lora_weight
265
  else:
266
  log_fn("Using base model without LoRA weights")
267
 
@@ -290,6 +288,7 @@ class PreviewingService:
290
  num_frames=num_frames,
291
  guidance_scale=guidance_scale,
292
  num_inference_steps=inference_steps,
 
293
  generator=generator,
294
  ).frames[0]
295
  else:
@@ -339,7 +338,7 @@ class PreviewingService:
339
  guidance_scale: float,
340
  flow_shift: float,
341
  lora_path: str,
342
- lora_weight: float,
343
  inference_steps: int,
344
  seed: int = -1,
345
  enable_cpu_offload: bool = True,
@@ -385,10 +384,9 @@ class PreviewingService:
385
  pipe.enable_model_cpu_offload()
386
 
387
  # Apply LoRA weights if using them
388
- if lora_weight > 0 and lora_path:
389
- log_fn(f"Loading LoRA weights from {lora_path} with weight {lora_weight}...")
390
  pipe.load_lora_weights(lora_path)
391
- pipe.fuse_lora(lora_weight)
392
  else:
393
  log_fn("Using base model without LoRA weights")
394
 
@@ -410,6 +408,7 @@ class PreviewingService:
410
  decode_timestep=0.03,
411
  decode_noise_scale=0.025,
412
  num_inference_steps=inference_steps,
 
413
  generator=generator,
414
  ).frames[0]
415
 
@@ -446,7 +445,7 @@ class PreviewingService:
446
  guidance_scale: float,
447
  flow_shift: float,
448
  lora_path: str,
449
- lora_weight: float,
450
  inference_steps: int,
451
  seed: int = -1,
452
  enable_cpu_offload: bool = True,
@@ -506,10 +505,9 @@ class PreviewingService:
506
  pipe.enable_model_cpu_offload()
507
 
508
  # Apply LoRA weights if using them
509
- if lora_weight > 0 and lora_path:
510
- log_fn(f"Loading LoRA weights from {lora_path} with weight {lora_weight}...")
511
  pipe.load_lora_weights(lora_path)
512
- pipe.fuse_lora(lora_weight)
513
  else:
514
  log_fn("Using base model without LoRA weights")
515
 
@@ -532,6 +530,7 @@ class PreviewingService:
532
  guidance_scale=guidance_scale,
533
  true_cfg_scale=1.0,
534
  num_inference_steps=inference_steps,
 
535
  generator=generator,
536
  ).frames[0]
537
 
 
69
  num_frames: int,
70
  guidance_scale: float,
71
  flow_shift: float,
72
+ lora_scale: float,
73
  inference_steps: int,
74
  seed: int = -1,
75
  enable_cpu_offload: bool = True,
 
87
  # Return updated log string for UI updates
88
  return "\n".join(log_messages)
89
 
90
+ # Find latest LoRA weights if lora_scale > 0
91
  lora_path = None
92
+ using_lora = lora_scale > 0
93
 
94
  if using_lora:
95
  lora_path = self.find_latest_lora_weights()
96
  if not lora_path:
97
  return None, "Error: No LoRA weights found", log("Error: No LoRA weights found in output directory")
98
+ log(f"Using LoRA weights with scale {lora_scale}")
99
  else:
100
  log("Using original model without LoRA weights")
101
 
 
155
  if using_lora and lora_path:
156
  log(f"Using LoRA weights from: {lora_path}")
157
  log(f"Resolution: {width}x{height}, Frames: {num_frames}, FPS: {fps}")
158
+ log(f"Guidance Scale: {guidance_scale}, Flow Shift: {flow_shift}, LoRA Scale: {lora_scale if using_lora else 0}")
159
  log(f"Generation Seed: {seed}")
160
  #log(f"Prompt: {full_prompt}")
161
  #log(f"Negative Prompt: {negative_prompt}")
 
164
  if internal_model_type == "wan":
165
  return self.generate_wan_video(
166
  full_prompt, negative_prompt, width, height, num_frames,
167
+ guidance_scale, flow_shift, lora_path, lora_scale,
168
  inference_steps, seed, enable_cpu_offload, fps, log,
169
  model_version, conditioning_image
170
  )
171
  elif internal_model_type == "ltx_video":
172
  return self.generate_ltx_video(
173
  full_prompt, negative_prompt, width, height, num_frames,
174
+ guidance_scale, flow_shift, lora_path, lora_scale,
175
  inference_steps, seed, enable_cpu_offload, fps, log,
176
  model_version, conditioning_image
177
  )
178
  elif internal_model_type == "hunyuan_video":
179
  return self.generate_hunyuan_video(
180
  full_prompt, negative_prompt, width, height, num_frames,
181
+ guidance_scale, flow_shift, lora_path, lora_scale,
182
  inference_steps, seed, enable_cpu_offload, fps, log,
183
  model_version, conditioning_image
184
  )
 
199
  guidance_scale: float,
200
  flow_shift: float,
201
  lora_path: str,
202
+ lora_scale: float,
203
  inference_steps: int,
204
  seed: int = -1,
205
  enable_cpu_offload: bool = True,
 
257
  pipe.enable_model_cpu_offload()
258
 
259
  # Apply LoRA weights if using them
260
+ if lora_scale > 0 and lora_path:
261
+ log_fn(f"Loading LoRA weights from {lora_path} with lora scale {lora_scale}...")
262
  pipe.load_lora_weights(lora_path)
 
 
263
  else:
264
  log_fn("Using base model without LoRA weights")
265
 
 
288
  num_frames=num_frames,
289
  guidance_scale=guidance_scale,
290
  num_inference_steps=inference_steps,
291
+ cross_attention_kwargs={"scale": lora_scale},
292
  generator=generator,
293
  ).frames[0]
294
  else:
 
338
  guidance_scale: float,
339
  flow_shift: float,
340
  lora_path: str,
341
+ lora_scale: float,
342
  inference_steps: int,
343
  seed: int = -1,
344
  enable_cpu_offload: bool = True,
 
384
  pipe.enable_model_cpu_offload()
385
 
386
  # Apply LoRA weights if using them
387
+ if lora_scale > 0 and lora_path:
388
+ log_fn(f"Loading LoRA weights from {lora_path} with lora scale {lora_scale}...")
389
  pipe.load_lora_weights(lora_path)
 
390
  else:
391
  log_fn("Using base model without LoRA weights")
392
 
 
408
  decode_timestep=0.03,
409
  decode_noise_scale=0.025,
410
  num_inference_steps=inference_steps,
411
+ cross_attention_kwargs={"scale": lora_scale},
412
  generator=generator,
413
  ).frames[0]
414
 
 
445
  guidance_scale: float,
446
  flow_shift: float,
447
  lora_path: str,
448
+ lora_scale: float,
449
  inference_steps: int,
450
  seed: int = -1,
451
  enable_cpu_offload: bool = True,
 
505
  pipe.enable_model_cpu_offload()
506
 
507
  # Apply LoRA weights if using them
508
+ if lora_scale > 0 and lora_path:
509
+ log_fn(f"Loading LoRA weights from {lora_path} with lora scale {lora_scale}...")
510
  pipe.load_lora_weights(lora_path)
 
511
  else:
512
  log_fn("Using base model without LoRA weights")
513
 
 
530
  guidance_scale=guidance_scale,
531
  true_cfg_scale=1.0,
532
  num_inference_steps=inference_steps,
533
+ cross_attention_kwargs={"scale": lora_scale},
534
  generator=generator,
535
  ).frames[0]
536
 
vms/ui/project/tabs/preview_tab.py CHANGED
@@ -164,8 +164,8 @@ class PreviewTab(BaseTab):
164
  )
165
 
166
  with gr.Row():
167
- self.components["lora_weight"] = gr.Slider(
168
- label="LoRA Weight",
169
  minimum=0.0,
170
  maximum=1.0,
171
  step=0.01,
@@ -236,7 +236,7 @@ class PreviewTab(BaseTab):
236
  is_using_lora = "Use LoRA model" in use_lora_value
237
 
238
  return {
239
- self.components["lora_weight"]: gr.Slider(visible=is_using_lora)
240
  }
241
 
242
  def get_model_version_choices(self, model_type: str) -> List[str]:
@@ -379,7 +379,7 @@ class PreviewTab(BaseTab):
379
  self.components["use_lora"].change(
380
  fn=self.update_lora_ui,
381
  inputs=[self.components["use_lora"]],
382
- outputs=[self.components["lora_weight"]]
383
  )
384
 
385
  # Load preview UI state when the tab is selected
@@ -397,7 +397,7 @@ class PreviewTab(BaseTab):
397
  self.components["fps"],
398
  self.components["guidance_scale"],
399
  self.components["flow_shift"],
400
- self.components["lora_weight"],
401
  self.components["inference_steps"],
402
  self.components["enable_cpu_offload"],
403
  self.components["model_version"],
@@ -410,7 +410,7 @@ class PreviewTab(BaseTab):
410
  for component_name in [
411
  "prompt", "negative_prompt", "prompt_prefix", "model_version", "resolution_preset",
412
  "width", "height", "num_frames", "fps", "guidance_scale", "flow_shift",
413
- "lora_weight", "inference_steps", "enable_cpu_offload", "seed", "use_lora"
414
  ]:
415
  if component_name in self.components:
416
  self.components[component_name].change(
@@ -433,7 +433,7 @@ class PreviewTab(BaseTab):
433
  self.components["num_frames"],
434
  self.components["guidance_scale"],
435
  self.components["flow_shift"],
436
- self.components["lora_weight"],
437
  self.components["inference_steps"],
438
  self.components["enable_cpu_offload"],
439
  self.components["fps"],
@@ -535,7 +535,7 @@ class PreviewTab(BaseTab):
535
  preview_state.get("fps", 16),
536
  preview_state.get("guidance_scale", 5.0),
537
  preview_state.get("flow_shift", 3.0),
538
- preview_state.get("lora_weight", 0.7),
539
  preview_state.get("inference_steps", 30),
540
  preview_state.get("enable_cpu_offload", True),
541
  model_version,
@@ -603,7 +603,7 @@ class PreviewTab(BaseTab):
603
  num_frames: int,
604
  guidance_scale: float,
605
  flow_shift: float,
606
- lora_weight: float,
607
  inference_steps: int,
608
  enable_cpu_offload: bool,
609
  fps: int,
@@ -635,7 +635,7 @@ class PreviewTab(BaseTab):
635
  "fps": fps,
636
  "guidance_scale": guidance_scale,
637
  "flow_shift": flow_shift,
638
- "lora_weight": lora_weight,
639
  "inference_steps": inference_steps,
640
  "enable_cpu_offload": enable_cpu_offload,
641
  "seed": seed,
@@ -657,8 +657,8 @@ class PreviewTab(BaseTab):
657
  use_lora_model = use_lora == "Use LoRA model"
658
 
659
  # Start actual generation
660
- # If not using LoRA, set lora_weight to 0 to disable it
661
- effective_lora_weight = lora_weight if use_lora_model else 0.0
662
 
663
  result = self.app.previewing.generate_video(
664
  model_type=model_type,
@@ -671,7 +671,7 @@ class PreviewTab(BaseTab):
671
  num_frames=num_frames,
672
  guidance_scale=guidance_scale,
673
  flow_shift=flow_shift,
674
- lora_weight=effective_lora_weight, # Use 0.0 if not using LoRA
675
  inference_steps=inference_steps,
676
  enable_cpu_offload=enable_cpu_offload,
677
  fps=fps,
 
164
  )
165
 
166
  with gr.Row():
167
+ self.components["lora_scale"] = gr.Slider(
168
+ label="LoRA Scale",
169
  minimum=0.0,
170
  maximum=1.0,
171
  step=0.01,
 
236
  is_using_lora = "Use LoRA model" in use_lora_value
237
 
238
  return {
239
+ self.components["lora_scale"]: gr.Slider(visible=is_using_lora)
240
  }
241
 
242
  def get_model_version_choices(self, model_type: str) -> List[str]:
 
379
  self.components["use_lora"].change(
380
  fn=self.update_lora_ui,
381
  inputs=[self.components["use_lora"]],
382
+ outputs=[self.components["lora_scale"]]
383
  )
384
 
385
  # Load preview UI state when the tab is selected
 
397
  self.components["fps"],
398
  self.components["guidance_scale"],
399
  self.components["flow_shift"],
400
+ self.components["lora_scale"],
401
  self.components["inference_steps"],
402
  self.components["enable_cpu_offload"],
403
  self.components["model_version"],
 
410
  for component_name in [
411
  "prompt", "negative_prompt", "prompt_prefix", "model_version", "resolution_preset",
412
  "width", "height", "num_frames", "fps", "guidance_scale", "flow_shift",
413
+ "lora_scale", "inference_steps", "enable_cpu_offload", "seed", "use_lora"
414
  ]:
415
  if component_name in self.components:
416
  self.components[component_name].change(
 
433
  self.components["num_frames"],
434
  self.components["guidance_scale"],
435
  self.components["flow_shift"],
436
+ self.components["lora_scale"],
437
  self.components["inference_steps"],
438
  self.components["enable_cpu_offload"],
439
  self.components["fps"],
 
535
  preview_state.get("fps", 16),
536
  preview_state.get("guidance_scale", 5.0),
537
  preview_state.get("flow_shift", 3.0),
538
+ preview_state.get("lora_scale", 0.7),
539
  preview_state.get("inference_steps", 30),
540
  preview_state.get("enable_cpu_offload", True),
541
  model_version,
 
603
  num_frames: int,
604
  guidance_scale: float,
605
  flow_shift: float,
606
+ lora_scale: float,
607
  inference_steps: int,
608
  enable_cpu_offload: bool,
609
  fps: int,
 
635
  "fps": fps,
636
  "guidance_scale": guidance_scale,
637
  "flow_shift": flow_shift,
638
+ "lora_scale": lora_scale,
639
  "inference_steps": inference_steps,
640
  "enable_cpu_offload": enable_cpu_offload,
641
  "seed": seed,
 
657
  use_lora_model = use_lora == "Use LoRA model"
658
 
659
  # Start actual generation
660
+ # If not using LoRA, set lora_scale to 0 to disable it
661
+ effective_lora_scale = lora_scale if use_lora_model else 0.0
662
 
663
  result = self.app.previewing.generate_video(
664
  model_type=model_type,
 
671
  num_frames=num_frames,
672
  guidance_scale=guidance_scale,
673
  flow_shift=flow_shift,
674
+ lora_scale=effective_lora_scale, # Use 0.0 if not using LoRA
675
  inference_steps=inference_steps,
676
  enable_cpu_offload=enable_cpu_offload,
677
  fps=fps,