File size: 3,192 Bytes
c1f7300
47783c0
abcba3a
47783c0
 
 
 
 
 
 
abcba3a
 
a98af42
 
 
47783c0
abcba3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47783c0
abcba3a
 
 
 
 
 
 
a98af42
abcba3a
47783c0
 
abcba3a
19a018b
55d5b92
47783c0
abcba3a
318e971
a98af42
55d5b92
 
abcba3a
a98af42
47783c0
 
a98af42
 
 
abcba3a
 
47783c0
 
 
 
a98af42
47783c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
abcba3a
47783c0
abcba3a
47783c0
abcba3a
 
 
 
 
 
 
 
 
 
47783c0
abcba3a
 
47783c0
41394ac
 
abcba3a
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import os
import sys
from huggingface_hub import hf_hub_download, list_repo_files
import subprocess

MODEL_REPO = "tencent/HunyuanVideo-Avatar"
BASE_DIR = os.getcwd()
WEIGHTS_DIR = os.path.join(BASE_DIR, "weights")
OUTPUT_BASEPATH = os.path.join(BASE_DIR, "results-poor")


# Only download this specific file from transformers
ESSENTIAL_PATHS = [
    "hunyuan-video-t2v-720p/transformers/mp_rank_00_model_states_fp8.pt",
]

# Download everything from these folders
FULL_DIRS = [
    "hunyuan-video-t2v-720p/vae",
    #"llava_llama_image",
    "text_encoder_2",
    "whisper-tiny",
    "det_align",
]


def list_ckpt_files():
    """Return a list of files to download: specific files + all from some folders."""
    try:
        all_files = list_repo_files(MODEL_REPO)
    except Exception as e:
        print(f"❌ Failed to list files from {MODEL_REPO}: {e}")
        return []

    files_to_download = ESSENTIAL_PATHS.copy()
    for path in all_files:
        if any(path.startswith(folder + "/") for folder in FULL_DIRS):
            files_to_download.append(path)

    return files_to_download


def download_ckpts(files):
    """Download selected files to local directory, preserving structure."""
    for file_path in files:
        local_path = os.path.join(WEIGHTS_DIR, file_path)
        if os.path.exists(local_path):
            print(f"βœ… Already exists: {local_path}")
            continue

        print(f"⬇️  Downloading: {file_path}")
        try:
            hf_hub_download(
                repo_id=MODEL_REPO,
                filename=file_path,
                local_dir=WEIGHTS_DIR,
                local_dir_use_symlinks=False,
            )
        except Exception as e:
            print(f"❌ Failed to download {file_path}: {e}")


def run_sample_gpu_poor():
    ckpt_fp8 = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")

    if not os.path.isfile(ckpt_fp8):
        print(f"❌ Missing checkpoint: {ckpt_fp8}")
        return

    cmd = [
        "python3", "hymm_sp/sample_gpu_poor.py",
        "--input", "assets/test.csv",
        "--ckpt", ckpt_fp8,
        "--sample-n-frames", "129",
        "--seed", "128",
        "--image-size", "704",
        "--cfg-scale", "7.5",
        "--infer-steps", "50",
        "--use-deepcache", "1",
        "--flow-shift-eval-video", "5.0",
        "--save-path", OUTPUT_BASEPATH,
        "--use-fp8",
        "--cpu-offload",
        "--infer-min"
    ]

    env = os.environ.copy()
    env["PYTHONPATH"] = "./"
    env["MODEL_BASE"] = WEIGHTS_DIR
    env["CPU_OFFLOAD"] = "1"
    env["CUDA_VISIBLE_DEVICES"] = "0"

    print("πŸš€ Running sample_gpu_poor.py...")
    result = subprocess.run(cmd, env=env, capture_output=True, text=True)

    if result.returncode != 0:
        print(f"❌ sample_gpu_poor.py failed:\n{result.stderr}")
    else:
        print("βœ… sample_gpu_poor.py ran successfully!")


def main():
    files = list_ckpt_files()
    if not files:
        print("❌ No checkpoint files found in repo under ckpts folder.")
        sys.exit(1)

    download_ckpts(files)
    run_sample_gpu_poor()


if __name__ == "__main__":
    main()