MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / main

Function main

AgentBench.old/evaluate.py:57–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

55
56
57def main():
58 args = parse_args()
59 create_time = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
60 if args.no_timestamp:
61 output_root_dir = args.output_dir
62 else:
63 output_root_dir = os.path.join(args.output_dir, create_time)
64
65 if not os.path.exists(output_root_dir):
66 os.makedirs(output_root_dir)
67
68 task_files = find_all_task_files(args.task)
69 tasks = []
70 task_configs = []
71
72 updt = {}
73 if args.max_new_tokens is not None:
74 updt["max_new_tokens"] = args.max_new_tokens
75 agent_config = YAMLConfig.init_from_yaml(args.agent, updt)
76 agent = agent_config.create()
77
78 print("> Loading task configs")
79 for task_config_path in task_files:
80 updt = {"output_root_dir": output_root_dir, "workers": args.workers}
81 print(updt)
82 task_config = YAMLConfig.init_from_yaml(task_config_path, updt)
83 task = task_config.create()
84 if not task.output_root_dir:
85 task.output_root_dir = output_root_dir
86 os.makedirs(task.get_output_dir()) # TODO: exist_ok=True for resume
87 config_path = os.path.join(task.get_output_dir(), "config.json")
88 with open(config_path, "w", encoding='utf-8') as f:
89 f.write(json.dumps({
90 "agent": args.agent,
91 "task": task_config_path,
92 }, indent=4, ensure_ascii=False))
93 # task.workers = args.workers or task.workers
94 print(f" Task '{task.name}' loaded from config {task_config_path}, output to {task.output_root_dir}")
95 tasks.append(task)
96 task_configs.append(task_config)
97 print(f"> Successfully load {len(tasks)} task{'s' if len(tasks) > 1 else ''}")
98
99 # model, tokenizer = initialize_model_and_tokenizer(args)
100 # model = ModelForEvaluation(model, args.position_encoding_2d)
101
102
103 with open(os.path.join(output_root_dir, "configs.json"), "w") as f:
104 json.dump({
105 "args": args.__dict__,
106 "command_line": sys.argv,
107 "create_time": create_time,
108 "output_root_dir": output_root_dir,
109 "tasks": [{
110 "class": str(type(task)),
111 "config": serialize(task_config),
112 } for task, task_config in zip(tasks, task_configs)],
113 "agent": {
114 "class": str(type(agent)),

Callers 1

evaluate.pyFile · 0.70

Calls 11

serializeFunction · 0.90
print_rank_0Function · 0.90
find_all_task_filesFunction · 0.85
evaluate_all_tasksFunction · 0.85
nowMethod · 0.80
joinMethod · 0.80
init_from_yamlMethod · 0.80
createMethod · 0.80
get_output_dirMethod · 0.80
parse_argsFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected