Skip to content

Commit c120a9e

Browse files
authored
Merge pull request #9 from ppak10/v0.0.21
V0.0.21
2 parents 2fd5669 + 9bd8a66 commit c120a9e

18 files changed

Lines changed: 3296 additions & 857 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,6 @@ workspaces
175175
.claude/
176176
.gemini/
177177
.vscode/
178+
179+
junit.xml
180+
junitxml

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Additive Manufacturing related software modules
1010
<p align="center">
11-
<img src="./icon.svg" alt="Logo" width="50%">
11+
<img src="./public/logo.svg" alt="Logo" width="50%">
1212
</p>
1313

1414
## Getting Started
@@ -46,3 +46,14 @@ am workspace create test
4646

4747
#### Example
4848
An example implementation can be found [here](https://github.com/ppak10/additive-manufacturing-agent)
49+
50+
## Benchmark
51+
To run the benchmark commands, install the optional `benchmark` dependencies:
52+
53+
```bash
54+
uv pip install "additive-manufacturing[benchmark]"
55+
```
56+
57+
```bash
58+
am benchmark <model>
59+
```

icon.svg

Lines changed: 0 additions & 139 deletions
This file was deleted.

junit.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

junitxml

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ Issues = "https://github.com/ppak10/additive-manufacturing/issues"
3333
am = "am.cli:app"
3434

3535
[project.optional-dependencies]
36+
benchmark = [
37+
"accelerate>=1.12.0",
38+
"datasets>=4.6.0",
39+
"sentence-transformers>=5.2.3",
40+
"torch>=2.10.0",
41+
"transformers>=5.2.0",
42+
]
3643
cuda12 = [
3744
"jax[cuda12]>=0.6.2",
3845
]

src/am/benchmark/__init__.py

Whitespace-only changes.

src/am/benchmark/cli.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import typer
2+
3+
4+
def register_benchmark(app: typer.Typer):
5+
from pathlib import Path
6+
from rich import print as rprint
7+
8+
from am.benchmark.llm import benchmark_llm, TASKS
9+
from am.cli.options import NumProc
10+
from wa.cli.options import WorkspaceOption
11+
12+
@app.command(name="benchmark", rich_help_panel="Benchmark Commands")
13+
def benchmark(
14+
model: str,
15+
tasks: list[str] = typer.Option(TASKS, help="Tasks to benchmark"),
16+
batch_size: int = typer.Option(
17+
8, help="Number of prompts to process in parallel."
18+
),
19+
url: str = typer.Option(
20+
None, help="URL of a running vLLM server (e.g. http://localhost:8000/v1)."
21+
),
22+
workspace_option: WorkspaceOption = None,
23+
num_proc: NumProc = 1,
24+
) -> None:
25+
"""
26+
Runs additive manufacturing benchmark for large language models.
27+
"""
28+
29+
from wa.cli.utils import get_workspace
30+
31+
workspace = get_workspace(workspace_option)
32+
33+
try:
34+
workspace_folder_path = None
35+
if workspace:
36+
model_name = model.replace("/", "--")
37+
workspace_folder = workspace.create_folder(
38+
name_or_path=Path("benchmarks") / model_name, append_timestamp=True
39+
)
40+
workspace_folder_path = workspace_folder.path
41+
42+
benchmark_llm(
43+
model=model,
44+
tasks=tasks,
45+
batch_size=batch_size,
46+
url=url,
47+
num_proc=num_proc,
48+
out_path=workspace_folder_path,
49+
)
50+
51+
except Exception as e:
52+
import traceback
53+
54+
traceback.print_exc()
55+
rprint(f"⚠️ [yellow]Unable to run benchmark for {model}: {e}[/yellow]")
56+
raise typer.Exit(code=1)
57+
58+
return benchmark

src/am/benchmark/llm/__init__.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import importlib
2+
from pathlib import Path
3+
4+
from .constants import TASKS
5+
from .inference import _run_openai_compatible, _run_transformers
6+
from .general_knowledge_multiple_choice import (
7+
_benchmark_general_knowledge_multiple_choice,
8+
)
9+
from .general_knowledge_short_answer import _benchmark_general_knowledge_short_answer
10+
from .melt_pool_geometry_prediction import _benchmark_melt_pool_geometry_prediction
11+
12+
13+
def benchmark_llm(
14+
model: str,
15+
tasks: list[str] = TASKS,
16+
num_proc: int = 1,
17+
batch_size: int = 8,
18+
url: str | None = None,
19+
out_path: Path | None = None,
20+
) -> dict:
21+
22+
missing = [
23+
pkg
24+
for pkg in ("datasets", "sentence_transformers", "transformers")
25+
if importlib.util.find_spec(pkg) is None
26+
]
27+
if missing:
28+
raise ImportError(
29+
f"Missing benchmark packages: {', '.join(missing)}. "
30+
'Run: uv pip install "additive-manufacturing[benchmark]"'
31+
)
32+
33+
if url is not None:
34+
print(f"Using vLLM server: {url}")
35+
runner = lambda questions, max_tokens: _run_openai_compatible(
36+
url, model, questions, max_tokens
37+
)
38+
else:
39+
from transformers import pipeline
40+
41+
print(f"Loading model: {model}")
42+
llm_pipeline = pipeline(
43+
"text-generation",
44+
model=model,
45+
return_full_text=False,
46+
device_map="auto",
47+
)
48+
runner = lambda questions, max_tokens: _run_transformers(
49+
llm_pipeline, questions, batch_size, max_tokens
50+
)
51+
52+
reports = {}
53+
for task in tasks:
54+
if task == "general_knowledge_multiple_choice":
55+
reports[task] = _benchmark_general_knowledge_multiple_choice(
56+
runner, model, num_proc, out_path
57+
)
58+
elif task == "general_knowledge_short_answer":
59+
reports[task] = _benchmark_general_knowledge_short_answer(
60+
runner, model, num_proc, out_path
61+
)
62+
elif task == "melt_pool_geometry_prediction":
63+
reports[task] = _benchmark_melt_pool_geometry_prediction(
64+
runner, model, num_proc, out_path
65+
)
66+
else:
67+
print(f"Unknown task '{task}', skipping.")
68+
69+
return reports

0 commit comments

Comments
 (0)