File size: 2,539 Bytes
897f552
 
 
147b690
897f552
 
 
 
4e485ec
 
897f552
 
4e485ec
897f552
4e485ec
 
 
897f552
 
4e485ec
 
 
 
 
 
 
 
 
 
 
 
897f552
 
4e485ec
 
897f552
 
 
 
 
 
 
4e485ec
 
897f552
 
 
 
 
 
 
 
 
 
 
 
4e485ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import argparse
import os
import torch
import subprocess
from huggingface_hub import snapshot_download

# Arguments
parser = argparse.ArgumentParser()
parser.add_argument("--task", type=str, default="t2v-1.3B")
parser.add_argument("--size", type=str, default="832*480")
parser.add_argument("--frame_num", type=int, default=60)
parser.add_argument("--sample_steps", type=int, default=20)
parser.add_argument("--ckpt_dir", type=str, default="./Wan2.1-T2V-1.3B")
parser.add_argument("--offload_model", type=str, default="True")
parser.add_argument("--t5_cpu", action="store_true", help="Use CPU for T5 model (optional)")
parser.add_argument("--sample_shift", type=int, default=8, help="Sampling shift for generation")
parser.add_argument("--sample_guide_scale", type=int, default=6, help="Sampling guide scale for generation")
parser.add_argument("--prompt", type=str, required=True)
args = parser.parse_args()

# Log input parameters
print(f"Generating video with the following settings:\n"
      f"Task: {args.task}\n"
      f"Resolution: {args.size}\n"
      f"Frames: {args.frame_num}\n"
      f"Sample Steps: {args.sample_steps}\n"
      f"Prompt: {args.prompt}\n"
      f"Sample Shift: {args.sample_shift}\n"
      f"Sample Guide Scale: {args.sample_guide_scale}\n"
      f"Using T5 on CPU: {args.t5_cpu}")

# Ensure the model is downloaded
if not os.path.exists(args.ckpt_dir):
    print("πŸ”„ Downloading WAN 2.1 - 1.3B model from Hugging Face...")
    snapshot_download(repo_id="Wan-AI/Wan2.1-T2V-1.3B", local_dir=args.ckpt_dir)

# Free up GPU memory
if torch.cuda.is_available():
    torch.cuda.empty_cache()
    torch.backends.cudnn.benchmark = False
    torch.backends.cudnn.deterministic = True

# Run the model (Ensure that `generate.py` includes these new params in its model call)
command = f"python generate.py --task {args.task} --size {args.size} --frame_num {args.frame_num} --sample_steps {args.sample_steps} --ckpt_dir {args.ckpt_dir} --offload_model {args.offload_model} --t5_cpu {args.t5_cpu} --sample_shift {args.sample_shift} --sample_guide_scale {args.sample_guide_scale} --prompt \"{args.prompt}\""

process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()

# Print logs for debugging
print("πŸ”Ή Output:", stdout.decode())
print("πŸ”Ί Error:", stderr.decode())

# Verify if video was created
if os.path.exists("output.mp4"):
    print("βœ… Video generated successfully: output.mp4")
else:
    print("❌ Error: Video file not found!")