import os
import re

# 根目录路径
base_dir = "/opt/dpcvol/datasets/8625883998351850434/ckpt/minillm/learngene/llama3-8b/eval/downstream_task/winogrande/"

# 要匹配的目录结构
sub_models = [
    "138M", "220M", "277M", "380M", "537M",
    "138M-LInit-100Mtoken", "220M-LInit-100Mtoken", "277M-LInit-100Mtoken", "380M-LInit-100Mtoken", "537M-LInit-100Mtoken",
    "138M-LInit-500Mtoken", "220M-LInit-500Mtoken", "277M-LInit-500Mtoken", "380M-LInit-500Mtoken", "537M-LInit-500Mtoken",
    "138M-LInit-78Mtoken",  "220M-LInit-78Mtoken",  "277M-LInit-78Mtoken",  "380M-LInit-78Mtoken",  "537M-LInit-78Mtoken"
]


results = {}

# 遍历模型目录
for model_name in sub_models:
    log_path = os.path.join(base_dir, f"{model_name}/winogrande-512/{model_name}/10/log.txt")
    if os.path.exists(log_path):
        with open(log_path, 'r') as f:
            content = f.read()
            # 使用正则提取rougeL
            match = re.search(r"'rougeL':\s*([0-9.]+)", content)
            if match:
                rouge_l_value = float(match.group(1))
                results[model_name] = rouge_l_value
            else:
                results[model_name] = "Not Found"
    else:
        results[model_name] = "Missing log.txt"

# 排序后打印
for name in sorted(results.keys()):
    print(f"{name}: {results[name]}")
