-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy patheval_single_runner.py
More file actions
77 lines (65 loc) · 2.02 KB
/
Copy patheval_single_runner.py
File metadata and controls
77 lines (65 loc) · 2.02 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
import argparse
import json
from pathlib import Path
from dataset import dataset
def parse_args():
parser = argparse.ArgumentParser(
description="Evaluate one generated response for one MultiKernelBench task."
)
parser.add_argument(
"-i",
"--input",
dest="input_path",
required=True,
help="Path to the generated response text file.",
)
parser.add_argument(
"-o",
"--op",
dest="op",
required=True,
help="Task/operator name, such as relu or 1_logical_and.",
)
parser.add_argument(
"-l",
"--language",
dest="language",
required=True,
help="Backend language name, such as cuda, ascendc, or ascendc_direct_launch.",
)
parser.add_argument(
"-r",
"--result",
dest="result_path",
required=True,
help="Path where the JSON result should be written.",
)
parser.add_argument(
"--indent",
type=int,
default=2,
help="JSON indentation for the result file. Defaults to 2.",
)
return parser.parse_args()
def main():
args = parse_args()
input_path = Path(args.input_path)
result_path = Path(args.result_path)
if args.op not in dataset:
raise ValueError(f"Unknown op: {args.op}")
if not input_path.is_file():
raise FileNotFoundError(f"Generated response file not found: {input_path}")
if result_path.parent.exists() and not result_path.parent.is_dir():
raise FileExistsError(
f"Result parent path exists but is not a directory: {result_path.parent}"
)
from utils.evaluation_utils import eval_single
response_txt = input_path.read_text(encoding="utf-8")
result = eval_single(response_txt, args.op, args.language)
result_path.parent.mkdir(parents=True, exist_ok=True)
result_path.write_text(
json.dumps(result, indent=args.indent, ensure_ascii=False) + "\n",
encoding="utf-8",
)
if __name__ == "__main__":
main()