Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,9 @@ import json
|
|
7 |
import tempfile
|
8 |
from huggingface_hub import snapshot_download
|
9 |
|
|
|
|
|
|
|
10 |
# Download All Required Models using `snapshot_download`
|
11 |
|
12 |
# Download Wan2.1-I2V-14B-480P model
|
@@ -79,7 +82,7 @@ GPU_TO_VRAM_PARAMS = {
|
|
79 |
"NVIDIA A100-SXM4-40GB": 11000000000,
|
80 |
"NVIDIA A100-SXM4-80GB": 22000000000,
|
81 |
"NVIDIA L4": 5000000000,
|
82 |
-
"NVIDIA L40S":
|
83 |
}
|
84 |
USED_VRAM_PARAMS = GPU_TO_VRAM_PARAMS[gpu_name]
|
85 |
print("Using", USED_VRAM_PARAMS, "for num_persistent_param_in_dit")
|
@@ -110,46 +113,51 @@ def create_temp_input_json(prompt: str, cond_image_path: str, cond_audio_path: s
|
|
110 |
return temp_json_path
|
111 |
|
112 |
|
113 |
-
def infer(prompt, cond_image_path, cond_audio_path):
|
114 |
-
|
115 |
input_json_path = create_temp_input_json(prompt, cond_image_path, cond_audio_path)
|
116 |
|
117 |
-
|
118 |
-
|
119 |
"--ckpt_dir", "weights/Wan2.1-I2V-14B-480P",
|
120 |
"--wav2vec_dir", "weights/chinese-wav2vec2-base",
|
121 |
"--input_json", input_json_path,
|
122 |
-
"--sample_steps", "
|
123 |
-
#"--motion_frame", "2",
|
124 |
-
"--num_persistent_param_in_dit", str(USED_VRAM_PARAMS),
|
125 |
"--mode", "streaming",
|
126 |
"--use_teacache",
|
127 |
-
"--save_file", "
|
128 |
]
|
129 |
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
process = subprocess.Popen(
|
136 |
cmd,
|
137 |
stdout=subprocess.PIPE,
|
138 |
stderr=subprocess.STDOUT,
|
139 |
text=True,
|
140 |
-
bufsize=1
|
141 |
)
|
142 |
-
|
143 |
for line in process.stdout:
|
144 |
-
print(line, end="")
|
145 |
-
log_file.write(line)
|
146 |
-
|
147 |
process.wait()
|
148 |
|
149 |
if process.returncode != 0:
|
150 |
raise RuntimeError("Inference failed. Check inference.log for details.")
|
151 |
|
152 |
-
return "
|
153 |
|
154 |
|
155 |
with gr.Blocks(title="MultiTalk Inference") as demo:
|
|
|
7 |
import tempfile
|
8 |
from huggingface_hub import snapshot_download
|
9 |
|
10 |
+
num_gpus = torch.cuda.device_count()
|
11 |
+
print(f"GPU AVAILABLE: {num_gpus}")
|
12 |
+
|
13 |
# Download All Required Models using `snapshot_download`
|
14 |
|
15 |
# Download Wan2.1-I2V-14B-480P model
|
|
|
82 |
"NVIDIA A100-SXM4-40GB": 11000000000,
|
83 |
"NVIDIA A100-SXM4-80GB": 22000000000,
|
84 |
"NVIDIA L4": 5000000000,
|
85 |
+
"NVIDIA L40S": 11000000000
|
86 |
}
|
87 |
USED_VRAM_PARAMS = GPU_TO_VRAM_PARAMS[gpu_name]
|
88 |
print("Using", USED_VRAM_PARAMS, "for num_persistent_param_in_dit")
|
|
|
113 |
return temp_json_path
|
114 |
|
115 |
|
116 |
+
def infer(prompt, cond_image_path, cond_audio_path):
|
117 |
+
# Prepare input JSON
|
118 |
input_json_path = create_temp_input_json(prompt, cond_image_path, cond_audio_path)
|
119 |
|
120 |
+
# Base args
|
121 |
+
common_args = [
|
122 |
"--ckpt_dir", "weights/Wan2.1-I2V-14B-480P",
|
123 |
"--wav2vec_dir", "weights/chinese-wav2vec2-base",
|
124 |
"--input_json", input_json_path,
|
125 |
+
"--sample_steps", "6",
|
|
|
|
|
126 |
"--mode", "streaming",
|
127 |
"--use_teacache",
|
128 |
+
"--save_file", "multi_long_multigpu_exp"
|
129 |
]
|
130 |
|
131 |
+
if num_gpus > 1:
|
132 |
+
cmd = [
|
133 |
+
"torchrun",
|
134 |
+
f"--nproc_per_node={num_gpus}",
|
135 |
+
"--standalone",
|
136 |
+
"generate_multitalk.py",
|
137 |
+
"--dit_fsdp", "--t5_fsdp",
|
138 |
+
"--ulysses_size", str(num_gpus),
|
139 |
+
] + common_args
|
140 |
+
else:
|
141 |
+
cmd = ["python3", "generate_multitalk.py"] + common_args
|
142 |
+
|
143 |
+
# Log to file and stream
|
144 |
+
with open("inference.log", "w") as log_file:
|
145 |
process = subprocess.Popen(
|
146 |
cmd,
|
147 |
stdout=subprocess.PIPE,
|
148 |
stderr=subprocess.STDOUT,
|
149 |
text=True,
|
150 |
+
bufsize=1
|
151 |
)
|
|
|
152 |
for line in process.stdout:
|
153 |
+
print(line, end="")
|
154 |
+
log_file.write(line)
|
|
|
155 |
process.wait()
|
156 |
|
157 |
if process.returncode != 0:
|
158 |
raise RuntimeError("Inference failed. Check inference.log for details.")
|
159 |
|
160 |
+
return "multi_long_multigpu_exp.mp4"
|
161 |
|
162 |
|
163 |
with gr.Blocks(title="MultiTalk Inference") as demo:
|