Zrelv commited on
Commit
ceaddbf
·
1 Parent(s): d998a7d

Make identical to wan777: base Wan2.2-I2V-A14B + wan777 code/deps/gradio

Browse files

User wants all 5 like wan777 (base Wan2.2). Copy wan777's exact stack (app.py,
release requirements, gradio 5.44.1) and unset REPO_ID so it uses the hardcoded
base model. README title/emoji preserved.

Files changed (2) hide show
  1. app.py +48 -23
  2. requirements.txt +7 -9
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import os
2
  import spaces
3
  import shutil
4
  import subprocess
@@ -126,10 +126,10 @@ def interpolate_bits(frames_np, multiplier=2, scale=1.0):
126
  """
127
  Interpolation maintaining Numpy Float 0-1 format.
128
  Args:
129
- frames_np: Numpy Array (Time, Height, Width, Channels) - Float32 [0.0, 1.0]
130
  multiplier: int (2, 4, 8)
131
  Returns:
132
- List of Numpy Arrays (Height, Width, Channels) - Float32 [0.0, 1.0]
133
  """
134
 
135
  # Handle input shape
@@ -175,7 +175,7 @@ def interpolate_bits(frames_np, multiplier=2, scale=1.0):
175
 
176
  def make_inference(I0, I1, n):
177
  if rife_model.version >= 3.9:
178
- res = []
179
  for i in range(n):
180
  res.append(rife_model.inference(I0, I1, (i+1) * 1. / (n+1), scale))
181
  return res
@@ -186,11 +186,11 @@ def interpolate_bits(frames_np, multiplier=2, scale=1.0):
186
  first_half = make_inference(I0, middle, n=n//2)
187
  second_half = make_inference(middle, I1, n=n//2)
188
  if n % 2:
189
- return [*first_half, middle, *second_half]
190
  else:
191
- return [*first_half, *second_half]
192
 
193
- output_frames = []
194
 
195
  # Process Frames
196
  # Load first frame into GPU
@@ -270,11 +270,20 @@ original_scheduler = copy.deepcopy(pipe.scheduler)
270
  # print("No hub cache found.")
271
 
272
  quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
 
273
  quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
 
274
  quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
 
275
 
276
- aoti.aoti_blocks_load(pipe.transformer, 'zerogpu-aoti/Wan2', variant='fp8da')
277
- aoti.aoti_blocks_load(pipe.transformer_2, 'zerogpu-aoti/Wan2', variant='fp8da')
 
 
 
 
 
 
278
 
279
  # pipe.vae.enable_slicing()
280
  # pipe.vae.enable_tiling()
@@ -355,6 +364,7 @@ def get_inference_duration(
355
  frame_multiplier,
356
  quality,
357
  duration_seconds,
 
358
  progress
359
  ):
360
  BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
@@ -365,7 +375,7 @@ def get_inference_duration(
365
  gen_time = int(steps) * step_duration
366
 
367
  if guidance_scale > 1:
368
- gen_time = gen_time * 1.8
369
 
370
  frame_factor = frame_multiplier // FIXED_FPS
371
  if frame_factor > 1:
@@ -373,14 +383,22 @@ def get_inference_duration(
373
  inter_time = (total_out_frames * 0.02)
374
  gen_time += inter_time
375
 
376
- # Cap reserved GPU duration so the reported reservation stays under free-tier
377
- # ZeroGPU's ~300s per-call limit — the padded worst-case was tripping
378
- # "requested GPU duration larger than the maximum allowed". 145 still covers
379
- # real p90 (~107s) and the 150s caller timeout.
380
- return min(15 + gen_time, 145)
 
 
 
 
 
 
 
 
381
 
382
 
383
- @spaces.GPU(duration=get_inference_duration)
384
  def run_inference(
385
  resized_image,
386
  processed_last_image,
@@ -396,6 +414,7 @@ def run_inference(
396
  frame_multiplier,
397
  quality,
398
  duration_seconds,
 
399
  progress=gr.Progress(track_tqdm=True),
400
  ):
401
  scheduler_class = SCHEDULER_MAP.get(scheduler_name)
@@ -469,6 +488,7 @@ def generate_video(
469
  flow_shift=6.0,
470
  frame_multiplier=16,
471
  video_component=True,
 
472
  progress=gr.Progress(track_tqdm=True),
473
  ):
474
  """
@@ -542,8 +562,10 @@ def generate_video(
542
  frame_multiplier,
543
  quality,
544
  duration_seconds,
 
545
  progress,
546
  )
 
547
  print(f"GPU complete: {task_n}")
548
 
549
  return (video_path if video_component else None), video_path, current_seed
@@ -563,10 +585,8 @@ CSS = """
563
  """
564
 
565
 
566
- with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 10800)) as demo:
567
- gr.Markdown("## WAMU V2 - Wan 2.2 I2V (14B) 🐢🐢")
568
- gr.Markdown("#### ℹ️ **A Note on Performance:** This version prioritizes a straightforward setup over maximum speed, so performance may vary.")
569
- gr.Markdown('Try the alternative version: [WAMU space](https://huggingface.co/spaces/r3gm/wan2-2-fp8da-aoti-preview2)')
570
  gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU.")
571
 
572
  with gr.Row():
@@ -575,11 +595,16 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 10800)) as d
575
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
576
  duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
577
  frame_multi = gr.Dropdown(
578
- choices=[FIXED_FPS, FIXED_FPS*2, FIXED_FPS*4],
579
  value=FIXED_FPS,
580
  label="Video Fluidity (Frames per Second)",
581
  info="Extra frames will be generated using flow estimation, which estimates motion between frames to make the video smoother."
582
  )
 
 
 
 
 
583
  with gr.Accordion("Advanced Settings", open=False):
584
  last_image_component = gr.Image(type="pil", label="Last Image (Optional)", sources=["upload", "clipboard"])
585
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, info="Used if any Guidance Scale > 1.", lines=3)
@@ -612,12 +637,12 @@ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 10800)) as d
612
 
613
  file_output = gr.File(label="Download Video")
614
 
615
- ui_inputs = [
616
  input_image_component, last_image_component, prompt_input, steps_slider,
617
  negative_prompt_input, duration_seconds_input,
618
  guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox,
619
  quality_slider, scheduler_dropdown, flow_shift_slider, frame_multi,
620
- play_result_video
621
  ]
622
 
623
  generate_button.click(
 
1
+ import os; os.system('pip install --upgrade --no-deps spaces')
2
  import spaces
3
  import shutil
4
  import subprocess
 
126
  """
127
  Interpolation maintaining Numpy Float 0-1 format.
128
  Args:
129
+ frames_np: Numpy Array (Time, Height, Width, Channels) - Float32[0.0, 1.0]
130
  multiplier: int (2, 4, 8)
131
  Returns:
132
+ List of Numpy Arrays (Height, Width, Channels) - Float32[0.0, 1.0]
133
  """
134
 
135
  # Handle input shape
 
175
 
176
  def make_inference(I0, I1, n):
177
  if rife_model.version >= 3.9:
178
+ res =[]
179
  for i in range(n):
180
  res.append(rife_model.inference(I0, I1, (i+1) * 1. / (n+1), scale))
181
  return res
 
186
  first_half = make_inference(I0, middle, n=n//2)
187
  second_half = make_inference(middle, I1, n=n//2)
188
  if n % 2:
189
+ return[*first_half, middle, *second_half]
190
  else:
191
+ return[*first_half, *second_half]
192
 
193
+ output_frames =[]
194
 
195
  # Process Frames
196
  # Load first frame into GPU
 
270
  # print("No hub cache found.")
271
 
272
  quantize_(pipe.text_encoder, Int8WeightOnlyConfig())
273
+ torch._dynamo.reset()
274
  quantize_(pipe.transformer, Float8DynamicActivationFloat8WeightConfig())
275
+ torch._dynamo.reset()
276
  quantize_(pipe.transformer_2, Float8DynamicActivationFloat8WeightConfig())
277
+ torch._dynamo.reset()
278
 
279
+ spaces.aoti_load(
280
+ module=pipe.transformer,
281
+ repo_id='cbensimon/WanTransformer3DModel-sm120-cu130-raa',
282
+ )
283
+ spaces.aoti_load(
284
+ module=pipe.transformer_2,
285
+ repo_id='cbensimon/WanTransformer3DModel-sm120-cu130-raa',
286
+ )
287
 
288
  # pipe.vae.enable_slicing()
289
  # pipe.vae.enable_tiling()
 
364
  frame_multiplier,
365
  quality,
366
  duration_seconds,
367
+ safe_mode,
368
  progress
369
  ):
370
  BASE_FRAMES_HEIGHT_WIDTH = 81 * 832 * 624
 
375
  gen_time = int(steps) * step_duration
376
 
377
  if guidance_scale > 1:
378
+ gen_time = gen_time * 2.4
379
 
380
  frame_factor = frame_multiplier // FIXED_FPS
381
  if frame_factor > 1:
 
383
  inter_time = (total_out_frames * 0.02)
384
  gen_time += inter_time
385
 
386
+ total_time = 15 + gen_time
387
+ if safe_mode:
388
+ total_time = total_time * 1.3
389
+
390
+ # Cap the reserved GPU duration so the reported reservation (×2 for xlarge)
391
+ # stays under free-tier ZeroGPU's ~300s per-call limit. The padded worst-case
392
+ # estimate ran 3-10x the real p90 (~107s) and tripped "The requested GPU
393
+ # duration (…) is larger than the maximum allowed". 145 → ~290s reported,
394
+ # still covers p90 and matches the caller's 150s hard timeout. Revert to 140
395
+ # if the cap turns out stricter than 300s.
396
+ total_time = min(total_time, 145)
397
+ return total_time
398
+
399
 
400
 
401
+ @spaces.GPU(duration=get_inference_duration, size='xlarge')
402
  def run_inference(
403
  resized_image,
404
  processed_last_image,
 
414
  frame_multiplier,
415
  quality,
416
  duration_seconds,
417
+ safe_mode,
418
  progress=gr.Progress(track_tqdm=True),
419
  ):
420
  scheduler_class = SCHEDULER_MAP.get(scheduler_name)
 
488
  flow_shift=6.0,
489
  frame_multiplier=16,
490
  video_component=True,
491
+ safe_mode=False,
492
  progress=gr.Progress(track_tqdm=True),
493
  ):
494
  """
 
562
  frame_multiplier,
563
  quality,
564
  duration_seconds,
565
+ safe_mode,
566
  progress,
567
  )
568
+
569
  print(f"GPU complete: {task_n}")
570
 
571
  return (video_path if video_component else None), video_path, current_seed
 
585
  """
586
 
587
 
588
+ with gr.Blocks(theme=gr.themes.Soft(), css=CSS, delete_cache=(3600, 3700)) as demo:
589
+ gr.Markdown("## Wan 2.2 I2V (14B) — Fast ⚡")
 
 
590
  gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU.")
591
 
592
  with gr.Row():
 
595
  prompt_input = gr.Textbox(label="Prompt", value=default_prompt_i2v)
596
  duration_seconds_input = gr.Slider(minimum=MIN_DURATION, maximum=MAX_DURATION, step=0.1, value=3.5, label="Duration (seconds)", info=f"Clamped to model's {MIN_FRAMES_MODEL}-{MAX_FRAMES_MODEL} frames at {FIXED_FPS}fps.")
597
  frame_multi = gr.Dropdown(
598
+ choices=[FIXED_FPS, FIXED_FPS*2, FIXED_FPS*4, FIXED_FPS*8],
599
  value=FIXED_FPS,
600
  label="Video Fluidity (Frames per Second)",
601
  info="Extra frames will be generated using flow estimation, which estimates motion between frames to make the video smoother."
602
  )
603
+ safe_mode_checkbox = gr.Checkbox(
604
+ label="🛠️ Safe Mode",
605
+ value=True,
606
+ info="Safe Mode: Requests 30% extra processing time to try to prevent unfinished tasks when the server is busy."
607
+ )
608
  with gr.Accordion("Advanced Settings", open=False):
609
  last_image_component = gr.Image(type="pil", label="Last Image (Optional)", sources=["upload", "clipboard"])
610
  negative_prompt_input = gr.Textbox(label="Negative Prompt", value=default_negative_prompt, info="Used if any Guidance Scale > 1.", lines=3)
 
637
 
638
  file_output = gr.File(label="Download Video")
639
 
640
+ ui_inputs =[
641
  input_image_component, last_image_component, prompt_input, steps_slider,
642
  negative_prompt_input, duration_seconds_input,
643
  guidance_scale_input, guidance_scale_2_input, seed_input, randomize_seed_checkbox,
644
  quality_slider, scheduler_dropdown, flow_shift_slider, frame_multi,
645
+ play_result_video, safe_mode_checkbox
646
  ]
647
 
648
  generate_button.click(
requirements.txt CHANGED
@@ -1,21 +1,19 @@
1
- git+https://github.com/linoytsaban/diffusers.git@wan22-loras
2
-
3
- transformers<5
4
- accelerate
5
  safetensors
6
  sentencepiece
7
- peft
8
  ftfy
9
  imageio
10
  imageio-ffmpeg
11
  opencv-python
12
- torchao==0.11.0
13
 
14
  numpy>=1.16, <=1.23.5
15
  # tqdm>=4.35.0
16
  # sk-video>=1.1.10
17
  # opencv-python>=4.1.2
18
  # moviepy>=1.0.3
19
- torchvision
20
-
21
-
 
1
+ diffusers==0.38.0
2
+ transformers==4.57.6
3
+ accelerate===1.13.0
 
4
  safetensors
5
  sentencepiece
6
+ peft==0.19.1
7
  ftfy
8
  imageio
9
  imageio-ffmpeg
10
  opencv-python
11
+ torchao==0.17.0
12
 
13
  numpy>=1.16, <=1.23.5
14
  # tqdm>=4.35.0
15
  # sk-video>=1.1.10
16
  # opencv-python>=4.1.2
17
  # moviepy>=1.0.3
18
+ torch==2.11.0
19
+ torchvision==0.26.0