Spaces:
Runtime error
Runtime error
File size: 1,642 Bytes
70ea05e |
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 |
import json
import os
from datetime import datetime
from src.evaluation.perplexity_eval import evaluate_perplexity, create_perplexity_result
from src.envs import EVAL_RESULTS_PATH, API, RESULTS_REPO
def run_dynamic_perplexity_eval(model_name, revision="main", precision="float16"):
"""
Run perplexity evaluation and save results.
"""
try:
# Run evaluation
perplexity_score = evaluate_perplexity(model_name, revision)
# Create result structure
result = create_perplexity_result(model_name, revision, precision, perplexity_score)
# Save result file
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
result_filename = f"results_{model_name.replace('/', '_')}_{timestamp}.json"
# Create directory structure
org, model = model_name.split("/") if "/" in model_name else ("", model_name)
result_dir = os.path.join(EVAL_RESULTS_PATH, org) if org else EVAL_RESULTS_PATH
os.makedirs(result_dir, exist_ok=True)
result_path = os.path.join(result_dir, result_filename)
with open(result_path, "w") as f:
json.dump(result, f, indent=2)
# Upload to Hugging Face dataset
API.upload_file(
path_or_fileobj=result_path,
path_in_repo=result_path.split("eval-results/")[1],
repo_id=RESULTS_REPO,
repo_type="dataset",
commit_message=f"Add perplexity results for {model_name}",
)
return True, perplexity_score
except Exception as e:
return False, str(e) |