File size: 1,783 Bytes
c1f7300
d491e94
 
093967b
b74bc4e
 
62066bc
c1f7300
093967b
fedb718
093967b
fedb718
b74bc4e
 
 
 
 
 
 
 
 
 
 
 
 
 
956b411
b74bc4e
 
 
 
 
c1f7300
d491e94
b74bc4e
093967b
edc3608
62066bc
 
 
b74bc4e
 
62066bc
edc3608
d491e94
b74bc4e
d491e94
fedb718
b74bc4e
fedb718
d491e94
b74bc4e
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
import os
import sys
import subprocess
import time
import shutil
import psutil
from huggingface_hub import snapshot_download

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")
CUSTOM_CACHE_DIR = "/data/hf_cache"  # βœ… change if different
HF_HOME_ENV = {"HF_HOME": CUSTOM_CACHE_DIR}

# Paths to required checkpoints
CHECKPOINT_FILE = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states.pt")
CHECKPOINT_FP8_FILE = os.path.join(WEIGHTS_DIR, "ckpts", "hunyuan-video-t2v-720p", "transformers", "mp_rank_00_model_states_fp8.pt")

def check_disk_space(min_free_gb=10):
    total, used, free = shutil.disk_usage("/")
    free_gb = free // (2**30)
    print(f"πŸ’Ύ Disk space: {free_gb}GB free")
    if free_gb < min_free_gb:
        print(f"❌ Not enough disk space. {free_gb}GB available, {min_free_gb}GB required.")
        sys.exit(1)

def clear_hf_cache():
    hf_cache = os.path.expanduser("~/.cache/huggingface")
    if os.path.exists(hf_cache):
        print("🧹 Cleaning Hugging Face cache...")
        shutil.rmtree(hf_cache)

def download_model():
    print("⬇️  Downloading model to weights directory...")
    os.makedirs(WEIGHTS_DIR, exist_ok=True)

    snapshot_download(
        repo_id=MODEL_REPO,
        local_dir=WEIGHTS_DIR,
        local_dir_use_symlinks=False,
        **HF_HOME_ENV
    )

    if not os.path.isfile(CHECKPOINT_FILE):
        print(f"❌ Checkpoint missing at {CHECKPOINT_FILE}")
        sys.exit(1)
    if not os.path.isfile(CHECKPOINT_FP8_FILE):
        print(f"❌ FP8 Checkpoint missing at {CHECKPOINT_FP8_FILE}")
        sys.exit(1)

    print("βœ… Model downloaded suc