forked from agiresearch/AIOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
132 lines (99 loc) · 4.6 KB
/
eval.py
File metadata and controls
132 lines (99 loc) · 4.6 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# This file is used to evaluate the configuration passed through arguments to the simulation of the kernel
import os
import sys
import json
from src.scheduler.fifo_scheduler import FIFOScheduler
from src.scheduler.rr_scheduler import RRScheduler
from pyopenagi.agents.agent_factory import AgentFactory
from pyopenagi.agents.agent_process import AgentProcessFactory
import warnings
from src.llm_kernel import llms
from concurrent.futures import ThreadPoolExecutor, as_completed
from multiprocessing import Process
from src.utils.utils import delete_directories
from src.utils.calculator import get_numbers_concurrent, get_numbers_sequential, comparison
import argparse
import random
import numpy as np
from dotenv import find_dotenv, load_dotenv
# Construct help message and parse argumets using argparse
def parse_global_args():
""" parser in src/utils/utils.py with --agents and --agent-log-mode argument """
parser = argparse.ArgumentParser(description="Parse global parameters")
parser.add_argument('--llm_name', type=str, default="gemma-2b-it", help="Specify the LLM name of AIOS")
parser.add_argument('--max_gpu_memory', type=json.loads, help="Max gpu memory allocated for the LLM")
parser.add_argument('--eval_device', type=str, help="Evaluation device (example: \"conda:0\" for 2 GPUs)")
parser.add_argument('--max_new_tokens', type=int, default=256,
help="The maximum number of new tokens for generation")
parser.add_argument("--scheduler_log_mode", type=str, default="console", choices=["console", "file"])
parser.add_argument("--agent_log_mode", type=str, default="console", choices=["console", "file"])
parser.add_argument("--mode", type=str, default="compare", choices=["compare", "concurrent-only", "sequential-only"])
parser.add_argument("--llm_kernel_log_mode", type=str, default="console", choices=["console", "file"])
parser.add_argument("--agents", type=str, required=True,
help="following the format of <agent1>:<agent1_num>,<agent2>:<agent2_num>")
return parser
def clean_cache(root_directory):
targets = {'.ipynb_checkpoints', '__pycache__', ".pytest_cache", "context_restoration"}
delete_directories(root_directory, targets)
def main():
warnings.filterwarnings("ignore")
parser = parse_global_args()
args = parser.parse_args()
llm_name = args.llm_name
max_gpu_memory = args.max_gpu_memory
eval_device = args.eval_device
max_new_tokens = args.max_new_tokens
scheduler_log_mode = args.scheduler_log_mode
agent_log_mode = args.agent_log_mode
llm_kernel_log_mode = args.llm_kernel_log_mode
load_dotenv()
llm = llms.LLMKernel(
llm_name=llm_name,
max_gpu_memory=max_gpu_memory,
eval_device=eval_device,
max_new_tokens=max_new_tokens,
log_mode=llm_kernel_log_mode
)
scheduler = FIFOScheduler(
llm=llm,
log_mode=scheduler_log_mode
)
agent_process_factory = AgentProcessFactory()
agent_factory = AgentFactory(
llm=llm,
agent_process_queue=scheduler.agent_process_queue,
agent_process_factory=agent_process_factory,
agent_log_mode=agent_log_mode
)
agent_thread_pool = ThreadPoolExecutor(max_workers=2000)
scheduler.start()
agents = args.agents
agent_list = []
for agent in agents.split(","):
agent = agent.split(":")
agent_name = agent[0]
agent_num = int(agent[1])
agent_list.append((agent_name, agent_num))
def execute_mode(mode, agent_list, agent_factory, agent_thread_pool=None):
print(f"**** {mode} Execution Statistics Starts ****\n")
if mode == "concurrent":
metrics = get_numbers_concurrent(agent_list, agent_factory, agent_thread_pool)
else:
metrics = get_numbers_sequential(agent_list, agent_factory)
print(f"{mode.capitalize()} Metrics:", metrics)
print(f"**** {mode} Execution Statistics Ends ****\n")
return metrics
if args.mode == "compare":
concurrent_metrics = execute_mode("concurrent", agent_list, agent_factory, agent_thread_pool)
sequential_metrics = execute_mode("sequential", agent_list, agent_factory)
comparison(concurrent_metrics, sequential_metrics)
elif args.mode == "concurrent-only":
execute_mode("concurrent", agent_list, agent_factory, agent_thread_pool)
elif args.mode == "sequential-only":
execute_mode("sequential", agent_list, agent_factory)
else:
print("Error: Invalid mode")
clean_cache(root_directory="./")
scheduler.stop()
if __name__ == "__main__":
main()