Skip to content

Commit 36d7478

Browse files
committed
Run from yaml, details preview
1 parent 1f05452 commit 36d7478

File tree

6 files changed

+147
-7
lines changed

6 files changed

+147
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.py[cod]
44
*$py.class
55
*.sqlite
6+
*.db
67

78
# C extensions
89
*.so

resources/experiments.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- openai_url: https://api.qdrant.mil-team.ru/chat-1/v1/
2+
model_name: Compressa-Qwen2-72B-Instruct
3+
experiment_name: "File Prompts Run 1"
4+
description: "Experiment using prompts from a file with 10 tasks and 5 runners"
5+
prompts_file: resources/prompts.csv
6+
num_tasks: 10
7+
num_runners: 5
8+
generate_prompts: false
9+
num_prompts: 0
10+
prompt_length: 0
11+
max_tokens: 1000
12+
13+
- openai_url: https://api.qdrant.mil-team.ru/chat-1/v1/
14+
model_name: Compressa-Qwen2-72B-Instruct
15+
experiment_name: "Qwen2-72B Long Input / Short Output"
16+
description: "Experiment using prompts from a file with 20 tasks and 10 runners"
17+
prompts_file: resources/prompts.csv
18+
num_tasks: 20
19+
num_runners: 10
20+
generate_prompts: true
21+
num_prompts: 10
22+
prompt_length: 10000
23+
max_tokens: 100

src/compressa/perf/cli/__main__.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
run_experiment,
44
report_experiment,
55
list_experiments,
6+
run_experiments_from_yaml,
67
DEFAULT_DB_PATH,
78
)
89

@@ -34,7 +35,18 @@ def report_experiment_args(args):
3435

3536

3637
def list_experiments_args(args):
37-
list_experiments(db=args.db)
38+
list_experiments(
39+
db=args.db,
40+
show_parameters=args.show_parameters
41+
)
42+
43+
44+
def run_experiments_from_yaml_args(args):
45+
run_experiments_from_yaml(
46+
yaml_file=args.yaml_file,
47+
db=args.db,
48+
openai_api_key=args.openai_api_key
49+
)
3850

3951

4052
def main():
@@ -159,10 +171,38 @@ def main():
159171
default=DEFAULT_DB_PATH,
160172
help="Path to the SQLite database",
161173
)
174+
parser_list.add_argument(
175+
"--show-parameters",
176+
action="store_true",
177+
help="Show all parameters for each experiment"
178+
)
162179
parser_list.set_defaults(func=list_experiments_args)
163180

181+
parser_yaml = subparsers.add_parser(
182+
"measure-from-yaml",
183+
help="Run experiments from a YAML configuration file",
184+
)
185+
parser_yaml.add_argument(
186+
"yaml_file",
187+
help="YAML configuration file for experiments",
188+
)
189+
parser_yaml.add_argument(
190+
"--db",
191+
type=str,
192+
default=DEFAULT_DB_PATH,
193+
help="Path to the SQLite database",
194+
)
195+
parser_yaml.add_argument(
196+
"--openai_api_key",
197+
type=str,
198+
required=True,
199+
help="OpenAI API key",
200+
)
201+
parser_yaml.set_defaults(func=run_experiments_from_yaml_args)
202+
164203
args = parser.parse_args()
165204
args.func(args)
166205

206+
167207
if __name__ == "__main__":
168208
main()

src/compressa/perf/cli/tools.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sqlite3
22
from tabulate import tabulate
3+
from typing import List
34
from compressa.perf.experiment.inference import ExperimentRunner
45
from compressa.perf.experiment.analysis import Analyzer
56
from compressa.perf.data.models import Experiment
@@ -15,6 +16,7 @@
1516
import sys
1617
import random
1718
import string
19+
from compressa.perf.experiment.config import load_yaml_configs, ExperimentConfig
1820

1921
DEFAULT_DB_PATH = "compressa-perf-db.sqlite"
2022

@@ -175,6 +177,7 @@ def report_experiment(
175177

176178
def list_experiments(
177179
db: str = DEFAULT_DB_PATH,
180+
show_parameters: bool = False,
178181
):
179182
with sqlite3.connect(db) as conn:
180183
ensure_db_initialized(conn)
@@ -185,17 +188,59 @@ def list_experiments(
185188
print("No experiments found in the database.")
186189
return
187190

188-
table_data = [
189-
[
191+
table_data = []
192+
headers = ["ID", "Name", "Date", "Description"]
193+
194+
if show_parameters:
195+
headers.extend(["Parameters"])
196+
197+
desciptiont_length = 20 if show_parameters else 50
198+
for exp in experiments:
199+
row = [
190200
exp.id,
191201
exp.experiment_name,
192202
exp.experiment_date.strftime("%Y-%m-%d %H:%M:%S") if exp.experiment_date else "N/A",
193-
exp.description[:50] + "..." if exp.description and len(exp.description) > 50 else exp.description
203+
exp.description[:desciptiont_length] + "..." if exp.description and len(exp.description) > desciptiont_length else exp.description
194204
]
195-
for exp in experiments
196-
]
205+
206+
if show_parameters:
207+
parameters = fetch_parameters_by_experiment(conn, exp.id)
208+
param_str = "\n".join([f"{p.key}: {format_value(p.value, precision=2)}" for p in parameters])
209+
row.append(param_str)
210+
211+
table_data.append(row)
197212

198213
print("\nList of Experiments:")
199-
print(tabulate(table_data, headers=["ID", "Name", "Date", "Description"], tablefmt="grid"))
214+
print(tabulate(table_data, headers=headers, tablefmt="grid"))
200215

201216

217+
218+
def run_experiments_from_yaml(
219+
yaml_file: str,
220+
db: str = DEFAULT_DB_PATH,
221+
openai_api_key: str = None,
222+
):
223+
if not openai_api_key:
224+
raise ValueError("OPENAI_API_KEY is not set")
225+
226+
configs = load_yaml_configs(yaml_file)
227+
228+
for config in configs:
229+
run_experiment(
230+
db=db,
231+
openai_api_key=openai_api_key,
232+
openai_url=config.openai_url,
233+
model_name=config.model_name,
234+
experiment_name=config.experiment_name,
235+
description=config.description,
236+
prompts_file=config.prompts_file,
237+
num_tasks=config.num_tasks,
238+
num_runners=config.num_runners,
239+
generate_prompts=config.generate_prompts,
240+
num_prompts=config.num_prompts,
241+
prompt_length=config.prompt_length,
242+
max_tokens=config.max_tokens,
243+
)
244+
245+
# List experiments after running them
246+
list_experiments(db=db)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import yaml
2+
from typing import (
3+
List,
4+
Dict,
5+
)
6+
from dataclasses import dataclass
7+
8+
@dataclass
9+
class ExperimentConfig:
10+
openai_url: str
11+
model_name: str
12+
experiment_name: str
13+
description: str
14+
num_tasks: int
15+
num_runners: int
16+
generate_prompts: bool
17+
num_prompts: int
18+
prompt_length: int
19+
max_tokens: int
20+
prompts_file: str = None
21+
22+
def load_yaml_configs(file_path: str) -> List[ExperimentConfig]:
23+
with open(file_path, 'r') as file:
24+
config_data = yaml.safe_load(file)
25+
26+
if not isinstance(config_data, list):
27+
config_data = [config_data]
28+
29+
return [ExperimentConfig(**experiment) for experiment in config_data]
30+

tests/test_inference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_inference(self):
4646
measurement = runner.run_inference(
4747
experiment_id=experiment.id,
4848
prompt="Hello, world!",
49+
max_tokens=100,
4950
)
5051

5152
if measurement:

0 commit comments

Comments
 (0)