-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheval.py
More file actions
105 lines (84 loc) · 2.88 KB
/
Copy patheval.py
File metadata and controls
105 lines (84 loc) · 2.88 KB
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
#!/usr/bin/env python3
"""
Unified evaluation entry point.
Usage:
python eval.py task=fixer llm=openai
python eval.py task=fixer llm=vllm data=fixer_val
python eval.py task=lemma_synth llm=openai data=lemma_val num_examples=50
python eval.py task=implement llm=vllm data=implement_val
python eval.py task=fixer llm=vllm data=glob glob="../dafny-vfp/autogen/bench*minimized/**/*.dfy"
"""
import json
import logging
import random
import sys
from hydra import main as hydra_main
from hydra.utils import instantiate
from omegaconf import DictConfig, OmegaConf
from eval_common import print_summary, save_results
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
try:
import wandb
WANDB_AVAILABLE = True
except ImportError:
WANDB_AVAILABLE = False
@hydra_main(config_path="config", config_name="eval", version_base=None)
def main(cfg: DictConfig) -> None:
# Instantiate the task
task = instantiate(cfg.task)
logger.info(f"Task: {task.name}")
# Instantiate the LLM
llm = instantiate(cfg.llm.code)
logger.info(f"LLM: {OmegaConf.to_yaml(cfg.llm.code)}")
# Extract examples from the data sources
sources = OmegaConf.to_container(cfg.data.sources, resolve=True)
examples = task.extract_examples(sources)
# Apply seed and limit
if cfg.seed is not None:
random.seed(cfg.seed)
random.shuffle(examples)
if cfg.num_examples is not None:
examples = examples[:cfg.num_examples]
logger.info(f"Evaluating on {len(examples)} examples")
if not examples:
logger.error("No examples to evaluate!")
return
# Initialize wandb
use_wandb = cfg.wandb and WANDB_AVAILABLE
if use_wandb:
wandb.init(
project=cfg.wandb_project,
name=f"{task.name}",
config=OmegaConf.to_container(cfg, resolve=True),
)
# Run evaluation
outcome = task.evaluate(
llm, examples,
use_wandb=use_wandb,
verbose=cfg.verbose,
)
# Print summary
print_summary(
f"{task.name} successes",
outcome["success_count"],
outcome["total"],
)
# Save results
if cfg.output:
save_results(cfg.output, outcome["results"], {
"task": task.name,
"num_examples": outcome["total"],
"success_count": outcome["success_count"],
"success_rate": outcome["success_count"] / outcome["total"] if outcome["total"] > 0 else 0,
})
# Finish wandb
if use_wandb:
wandb.summary["final_success_count"] = outcome["success_count"]
wandb.summary["final_success_rate"] = (
outcome["success_count"] / outcome["total"] if outcome["total"] > 0 else 0
)
wandb.summary["total_examples"] = outcome["total"]
wandb.finish()
if __name__ == "__main__":
main()