HAL1993 commited on
Commit
20cb0aa
·
verified ·
1 Parent(s): 700003e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -31
app.py CHANGED
@@ -9,8 +9,14 @@ import numpy as np
9
  from PIL import Image
10
  import random
11
  import gc
12
- import torchao.quantization
 
13
  import aoti
 
 
 
 
 
14
 
15
  # Model configuration
16
  MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
@@ -26,6 +32,7 @@ MIN_DURATION = round(MIN_FRAMES_MODEL / FIXED_FPS, 1)
26
  MAX_DURATION = round(MAX_FRAMES_MODEL / FIXED_FPS, 1)
27
 
28
  # Initialize pipeline
 
29
  pipe = WanImageToVideoPipeline.from_pretrained(
30
  MODEL_ID,
31
  transformer=WanTransformer3DModel.from_pretrained(
@@ -43,30 +50,31 @@ pipe = WanImageToVideoPipeline.from_pretrained(
43
  torch_dtype=torch.bfloat16,
44
  ).to('cuda')
45
 
46
- # Load LoRA weights
47
- pipe.load_lora_weights(
48
- "Kijai/WanVideo_comfy",
49
- weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors",
50
- adapter_name="lightx2v"
51
- )
52
- kwargs_lora = {"load_into_transformer_2": True}
53
- pipe.load_lora_weights(
54
- "Kijai/WanVideo_comfy",
55
- weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors",
56
- adapter_name="lightx2v_2",
57
- **kwargs_lora
58
- )
59
- pipe.set_adapters(["lightx2v", "lightx2v_2"], adapter_weights=[1., 1.])
60
- pipe.fuse_lora(adapter_names=["lightx2v"], lora_scale=3., components=["transformer"])
61
- pipe.fuse_lora(adapter_names=["lightx2v_2"], lora_scale=1., components=["transformer_2"])
62
- pipe.unload_lora_weights()
63
 
64
  # Quantization
65
- quantize_(pipe.text_encoder, torchao.quantization.Int8WeightOnlyConfig())
66
- quantize_(pipe.transformer, torchao.quantization.Float8DynamicActivationFloat8WeightConfig())
67
- quantize_(pipe.transformer_2, torchao.quantization.Float8DynamicActivationFloat8WeightConfig())
68
- aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
69
- aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
 
 
 
 
70
 
71
  # Default prompts
72
  default_prompt_i2v = {
@@ -200,7 +208,7 @@ def generate_video(
200
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
201
  return video_path, current_seed
202
 
203
- # Updated UI with pretranslated texts and enhanced tab logic
204
  def create_demo():
205
  with gr.Blocks(css="", title="Fast Image to Video") as demo:
206
  gr.HTML("""
@@ -547,13 +555,6 @@ def create_demo():
547
  return false;
548
  };
549
 
550
- const observer = new MutationObserver((mutations, obs) => {
551
- const tabElements = document.querySelectorAll('[role="tab"], button, div, .gr-tab-item, .tab-item, [data-testid="tab"], [aria-selected], .nav-item, [data-tab]');
552
- if (selectTab(tabElements, tab)) {
553
- obs.disconnect();
554
- }
555
- });
556
-
557
  const tryObserveTabs = (attempt = 1, maxAttempts = 3) => {
558
  const tabs = document.querySelector('.gr-tabs, .tabs');
559
  if (tabs) {
@@ -585,6 +586,13 @@ def create_demo():
585
  }
586
  };
587
 
 
 
 
 
 
 
 
588
  tryObserveTabs();
589
 
590
  const toolbarSelectors = [
 
9
  from PIL import Image
10
  import random
11
  import gc
12
+ import torchao
13
+ from torchao.quantization import quantize, Int8WeightOnlyConfig, Float8DynamicActivationFloat8WeightConfig
14
  import aoti
15
+ import logging
16
+
17
+ # Set up logging
18
+ logging.basicConfig(level=logging.INFO)
19
+ logger = logging.getLogger(__name__)
20
 
21
  # Model configuration
22
  MODEL_ID = "Wan-AI/Wan2.2-I2V-A14B-Diffusers"
 
32
  MAX_DURATION = round(MAX_FRAMES_MODEL / FIXED_FPS, 1)
33
 
34
  # Initialize pipeline
35
+ logger.info("Loading WanImageToVideoPipeline...")
36
  pipe = WanImageToVideoPipeline.from_pretrained(
37
  MODEL_ID,
38
  transformer=WanTransformer3DModel.from_pretrained(
 
50
  torch_dtype=torch.bfloat16,
51
  ).to('cuda')
52
 
53
+ # Load LoRA weights (simplified to single adapter)
54
+ logger.info("Loading LoRA weights...")
55
+ try:
56
+ pipe.load_lora_weights(
57
+ "Kijai/WanVideo_comfy",
58
+ weight_name="Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors",
59
+ adapter_name="lightx2v"
60
+ )
61
+ pipe.set_adapters(["lightx2v"], adapter_weights=[1.0])
62
+ pipe.fuse_lora(adapter_names=["lightx2v"], lora_scale=3.0, components=["transformer", "transformer_2"])
63
+ pipe.unload_lora_weights()
64
+ except Exception as e:
65
+ logger.error(f"Failed to load LoRA weights: {str(e)}")
66
+ raise
 
 
 
67
 
68
  # Quantization
69
+ logger.info(f"Using torchao version: {torchao.__version__}")
70
+ try:
71
+ quantize(pipe.text_encoder, Int8WeightOnlyConfig())
72
+ quantize(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
73
+ quantize(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
74
+ aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
75
+ aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
76
+ except Exception as e:
77
+ logger.warning(f"Quantization failed: {str(e)}. Proceeding without quantization.")
78
 
79
  # Default prompts
80
  default_prompt_i2v = {
 
208
  export_to_video(output_frames_list, video_path, fps=FIXED_FPS)
209
  return video_path, current_seed
210
 
211
+ # UI with pretranslated texts and tab logic
212
  def create_demo():
213
  with gr.Blocks(css="", title="Fast Image to Video") as demo:
214
  gr.HTML("""
 
555
  return false;
556
  };
557
 
 
 
 
 
 
 
 
558
  const tryObserveTabs = (attempt = 1, maxAttempts = 3) => {
559
  const tabs = document.querySelector('.gr-tabs, .tabs');
560
  if (tabs) {
 
586
  }
587
  };
588
 
589
+ const observer = new MutationObserver((mutations, obs) => {
590
+ const tabElements = document.querySelectorAll('[role="tab"], button, div, .gr-tab-item, .tab-item, [data-testid="tab"], [aria-selected], .nav-item, [data-tab]');
591
+ if (selectTab(tabElements, tab)) {
592
+ obs.disconnect();
593
+ }
594
+ });
595
+
596
  tryObserveTabs();
597
 
598
  const toolbarSelectors = [