File size: 3,214 Bytes
ee762ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import shutil
import glob

def copy_checkpoints(indices, src_root, dst_root):
    for idx in indices:
        idx_str = f"{idx:04d}"
        # 1. ์ฒดํฌํฌ์ธํŠธ ํด๋” ์ฐพ๊ธฐ
        pattern = os.path.join(src_root, f"{idx_str}_HYVideo*")
        matches = glob.glob(pattern)
        if len(matches) == 0:
            print(f"[ERROR] No folder found for index {idx_str}")
            continue
        if len(matches) > 1:
            print(f"[ERROR] Multiple folders found for index {idx_str}: {matches}")
            continue
        src_folder = matches[0]
        dst_folder = os.path.join(dst_root, os.path.basename(src_folder))
        os.makedirs(dst_folder, exist_ok=True)

        # 2. checkpoints ํด๋” ์ฒ˜๋ฆฌ
        checkpoints_dir = os.path.join(src_folder, "checkpoints")
        dst_checkpoints_dir = os.path.join(dst_folder, "checkpoints")
        if os.path.isdir(checkpoints_dir):
            os.makedirs(dst_checkpoints_dir, exist_ok=True)
            # ๊ฐ€์žฅ ์ˆซ์ž๊ฐ€ ๋†’์€ ํ•˜์œ„ํด๋” ์ฐพ๊ธฐ
            subfolders = [f for f in os.listdir(checkpoints_dir) if os.path.isdir(os.path.join(checkpoints_dir, f))]
            max_num = -1
            max_folder = None
            for f in subfolders:
                try:
                    num = int(f)
                    if num > max_num:
                        max_num = num
                        max_folder = f
                except ValueError:
                    continue
            if max_folder is None:
                print(f"[ERROR] No valid subfolder in {checkpoints_dir}")
            else:
                src_max_folder = os.path.join(checkpoints_dir, max_folder)
                dst_max_folder = os.path.join(dst_checkpoints_dir, max_folder)
                os.makedirs(dst_max_folder, exist_ok=True)
                src_file = os.path.join(src_max_folder, "mp_rank_00_model_states.pt")
                dst_file = os.path.join(dst_max_folder, "mp_rank_00_model_states.pt")
                if os.path.isfile(src_file):
                    shutil.copy2(src_file, dst_file)
                    print(f"[OK] Copied {src_file} -> {dst_file}")
                else:
                    print(f"[ERROR] File not found: {src_file}")

        # 3. checkpoints ํด๋” ์™ธ์˜ ํŒŒ์ผ/ํด๋” ๋ณต์‚ฌ
        for item in os.listdir(src_folder):
            src_item = os.path.join(src_folder, item)
            dst_item = os.path.join(dst_folder, item)
            if item == "checkpoints":
                continue  # ์ด๋ฏธ ์ฒ˜๋ฆฌํ•จ
            if os.path.isdir(src_item):
                shutil.copytree(src_item, dst_item, dirs_exist_ok=True)
            else:
                shutil.copy2(src_item, dst_item)
        print(f"[OK] Finished copying for index {idx_str}")

# ์‚ฌ์šฉ ์˜ˆ์‹œ
if __name__ == "__main__":
    indices = [6, 9, 10, 12, 15, 17, 25, 33, 34, 42, 54, 64, 65, 66, 67, 72, 75, 76, 80, 89, 90, 92, 93, 109, 110]  # ๋ณต์‚ฌํ•  ์ธ๋ฑ์Šค ๋ฆฌ์ŠคํŠธ
    src_root = "/fsx/junyoung/my_checkpoints/hunyuan/log_EXP"  # ์ฒดํฌํฌ์ธํŠธ ํด๋”๋“ค์ด ์žˆ๋Š” ๊ฒฝ๋กœ
    dst_root = "/fsx/junyoung/my_checkpoints/important_checkpoints"       # ๋ณต์‚ฌํ•  ๋Œ€์ƒ ๊ฒฝ๋กœ
    copy_checkpoints(indices, src_root, dst_root)