Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,66 +1,55 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
import subprocess
|
4 |
-
from huggingface_hub import hf_hub_download, hf_hub_list
|
5 |
from huggingface_hub import list_repo_files
|
6 |
-
|
7 |
-
import spaces
|
8 |
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
9 |
-
|
10 |
-
WEIGHTS_DIR = BASE_DIR / "weights"
|
11 |
-
CKPTS_DIR = WEIGHTS_DIR / "ckpts"
|
12 |
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
-
# List all files under the folder 'ckpts' in the repo (recursively)
|
17 |
def list_ckpt_files():
|
18 |
print(f"π Listing files under '{REPO_ROOT_FOLDER}' in repo {MODEL_REPO}...")
|
19 |
-
|
|
|
20 |
return files
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
# Download the file if not present
|
34 |
-
if not local_path.is_file():
|
35 |
-
print(f"Downloading {file} -> {local_path}")
|
36 |
-
hf_hub_download(
|
37 |
-
repo_id=MODEL_REPO,
|
38 |
-
filename=file,
|
39 |
-
repo_type="model",
|
40 |
-
cache_dir=str(WEIGHTS_DIR),
|
41 |
-
local_dir=str(WEIGHTS_DIR),
|
42 |
-
local_dir_use_symlinks=False,
|
43 |
-
force_filename=str(local_path.name),
|
44 |
-
revision="main",
|
45 |
-
)
|
46 |
-
else:
|
47 |
-
print(f"File {local_path} already exists, skipping download.")
|
48 |
-
print("β
All checkpoint files downloaded.")
|
49 |
-
|
50 |
-
@spaces.GPU(duration=1000)
|
51 |
def run_sample_gpu_poor():
|
52 |
-
checkpoint_fp8 =
|
53 |
-
if not
|
54 |
-
print(f"β Checkpoint file {checkpoint_fp8}
|
55 |
sys.exit(1)
|
56 |
|
57 |
-
OUTPUT_BASEPATH = BASE_DIR / "results-poor"
|
58 |
-
OUTPUT_BASEPATH.mkdir(parents=True, exist_ok=True)
|
59 |
-
|
60 |
cmd = [
|
61 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
62 |
"--input", "assets/test.csv",
|
63 |
-
"--ckpt",
|
64 |
"--sample-n-frames", "129",
|
65 |
"--seed", "128",
|
66 |
"--image-size", "704",
|
@@ -68,7 +57,7 @@ def run_sample_gpu_poor():
|
|
68 |
"--infer-steps", "50",
|
69 |
"--use-deepcache", "1",
|
70 |
"--flow-shift-eval-video", "5.0",
|
71 |
-
"--save-path",
|
72 |
"--use-fp8",
|
73 |
"--cpu-offload",
|
74 |
"--infer-min"
|
@@ -76,11 +65,11 @@ def run_sample_gpu_poor():
|
|
76 |
|
77 |
env = os.environ.copy()
|
78 |
env["PYTHONPATH"] = "./"
|
79 |
-
env["MODEL_BASE"] =
|
80 |
env["CPU_OFFLOAD"] = "1"
|
81 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
82 |
|
83 |
-
print("π¬ Running sample_gpu_poor.py...")
|
84 |
proc = subprocess.run(cmd, env=env)
|
85 |
if proc.returncode != 0:
|
86 |
print("β sample_gpu_poor.py failed.")
|
@@ -88,12 +77,7 @@ def run_sample_gpu_poor():
|
|
88 |
print("β
sample_gpu_poor.py completed successfully.")
|
89 |
|
90 |
def main():
|
91 |
-
|
92 |
-
if not files:
|
93 |
-
print("β No checkpoint files found in repo under ckpts folder.")
|
94 |
-
sys.exit(1)
|
95 |
-
|
96 |
-
download_ckpts(files)
|
97 |
run_sample_gpu_poor()
|
98 |
|
99 |
if __name__ == "__main__":
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
import subprocess
|
|
|
4 |
from huggingface_hub import list_repo_files
|
5 |
+
|
|
|
6 |
MODEL_REPO = "tencent/HunyuanVideo-Avatar"
|
7 |
+
REPO_ROOT_FOLDER = "ckpts" # folder inside repo to download
|
|
|
|
|
8 |
|
9 |
+
BASE_DIR = os.getcwd()
|
10 |
+
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
|
11 |
+
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")
|
12 |
|
|
|
13 |
def list_ckpt_files():
|
14 |
print(f"π Listing files under '{REPO_ROOT_FOLDER}' in repo {MODEL_REPO}...")
|
15 |
+
all_files = list_repo_files(repo_id=MODEL_REPO, repo_type="model", revision="main")
|
16 |
+
files = [f for f in all_files if f.startswith(REPO_ROOT_FOLDER + "/")]
|
17 |
return files
|
18 |
|
19 |
+
def download_ckpts():
|
20 |
+
os.makedirs(WEIGHTS_DIR, exist_ok=True)
|
21 |
+
for filepath in list_ckpt_files():
|
22 |
+
# Target path relative to weights directory
|
23 |
+
relative_path = os.path.relpath(filepath, REPO_ROOT_FOLDER)
|
24 |
+
target_path = os.path.join(WEIGHTS_DIR, REPO_ROOT_FOLDER, relative_path)
|
25 |
+
|
26 |
+
# Skip if already exists
|
27 |
+
if os.path.exists(target_path):
|
28 |
+
print(f"β
File exists: {target_path}")
|
29 |
+
continue
|
30 |
+
|
31 |
+
# Create dirs if needed
|
32 |
+
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
33 |
+
|
34 |
+
# Download the file blob from HF repo using huggingface_hub api (requires v0.14+)
|
35 |
+
print(f"β¬οΈ Downloading {filepath} to {target_path} ...")
|
36 |
+
try:
|
37 |
+
from huggingface_hub import hf_hub_download
|
38 |
+
hf_hub_download(repo_id=MODEL_REPO, filename=filepath, local_dir=os.path.dirname(target_path), local_dir_use_symlinks=False)
|
39 |
+
except ImportError:
|
40 |
+
print("β οΈ hf_hub_download not available, please upgrade huggingface_hub")
|
41 |
+
sys.exit(1)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def run_sample_gpu_poor():
|
44 |
+
checkpoint_fp8 = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")
|
45 |
+
if not os.path.isfile(checkpoint_fp8):
|
46 |
+
print(f"β Checkpoint file not found at {checkpoint_fp8}. Cannot run sampling.")
|
47 |
sys.exit(1)
|
48 |
|
|
|
|
|
|
|
49 |
cmd = [
|
50 |
"python3", "hymm_sp/sample_gpu_poor.py",
|
51 |
"--input", "assets/test.csv",
|
52 |
+
"--ckpt", checkpoint_fp8,
|
53 |
"--sample-n-frames", "129",
|
54 |
"--seed", "128",
|
55 |
"--image-size", "704",
|
|
|
57 |
"--infer-steps", "50",
|
58 |
"--use-deepcache", "1",
|
59 |
"--flow-shift-eval-video", "5.0",
|
60 |
+
"--save-path", OUTPUT_BASEPATH,
|
61 |
"--use-fp8",
|
62 |
"--cpu-offload",
|
63 |
"--infer-min"
|
|
|
65 |
|
66 |
env = os.environ.copy()
|
67 |
env["PYTHONPATH"] = "./"
|
68 |
+
env["MODEL_BASE"] = WEIGHTS_DIR
|
69 |
env["CPU_OFFLOAD"] = "1"
|
70 |
env["CUDA_VISIBLE_DEVICES"] = "0"
|
71 |
|
72 |
+
print("π¬ Running sample_gpu_poor.py ...")
|
73 |
proc = subprocess.run(cmd, env=env)
|
74 |
if proc.returncode != 0:
|
75 |
print("β sample_gpu_poor.py failed.")
|
|
|
77 |
print("β
sample_gpu_poor.py completed successfully.")
|
78 |
|
79 |
def main():
|
80 |
+
download_ckpts()
|
|
|
|
|
|
|
|
|
|
|
81 |
run_sample_gpu_poor()
|
82 |
|
83 |
if __name__ == "__main__":
|