lmbench-llm 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lmbench_llm-0.1.0/LICENSE +21 -0
- lmbench_llm-0.1.0/PKG-INFO +163 -0
- lmbench_llm-0.1.0/README.md +132 -0
- lmbench_llm-0.1.0/pyproject.toml +87 -0
- lmbench_llm-0.1.0/pyproject.toml.orig +70 -0
- lmbench_llm-0.1.0/src/lmbench/__init__.py +7 -0
- lmbench_llm-0.1.0/src/lmbench/__main__.py +4 -0
- lmbench_llm-0.1.0/src/lmbench/backends/__init__.py +0 -0
- lmbench_llm-0.1.0/src/lmbench/backends/base.py +45 -0
- lmbench_llm-0.1.0/src/lmbench/backends/ollama.py +137 -0
- lmbench_llm-0.1.0/src/lmbench/bench/__init__.py +0 -0
- lmbench_llm-0.1.0/src/lmbench/bench/context.py +79 -0
- lmbench_llm-0.1.0/src/lmbench/bench/memory.py +137 -0
- lmbench_llm-0.1.0/src/lmbench/bench/offload.py +33 -0
- lmbench_llm-0.1.0/src/lmbench/bench/speed.py +76 -0
- lmbench_llm-0.1.0/src/lmbench/cli.py +392 -0
- lmbench_llm-0.1.0/src/lmbench/hardware.py +75 -0
- lmbench_llm-0.1.0/src/lmbench/pipeline.py +43 -0
- lmbench_llm-0.1.0/src/lmbench/quality/__init__.py +0 -0
- lmbench_llm-0.1.0/src/lmbench/quality/graders.py +294 -0
- lmbench_llm-0.1.0/src/lmbench/quality/runner.py +73 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites/coding.json +31 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites/instruct.json +20 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites/json.json +23 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites/reasoning.json +20 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites/summarize.json +27 -0
- lmbench_llm-0.1.0/src/lmbench/quality/suites.py +31 -0
- lmbench_llm-0.1.0/src/lmbench/render.py +106 -0
- lmbench_llm-0.1.0/src/lmbench/results.py +52 -0
- lmbench_llm-0.1.0/src/lmbench/scoring.py +177 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pravir Nihar Maity
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lmbench-llm
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Benchmark the LLMs installed in Ollama on your own machine: speed, memory, context scaling and task quality, then pick the best one.
|
|
5
|
+
Keywords: llm,benchmark,ollama,local-llm,inference,cli,gpu,vram
|
|
6
|
+
Author: Pravir Nihar Maity
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: System :: Benchmark
|
|
20
|
+
Requires-Dist: httpx>=0.27
|
|
21
|
+
Requires-Dist: nvidia-ml-py>=12.0
|
|
22
|
+
Requires-Dist: psutil>=5.9
|
|
23
|
+
Requires-Dist: rich>=13.7
|
|
24
|
+
Requires-Dist: typer>=0.15
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Project-URL: Homepage, https://github.com/Pravir-005/lmbench
|
|
27
|
+
Project-URL: Repository, https://github.com/Pravir-005/lmbench
|
|
28
|
+
Project-URL: Issues, https://github.com/Pravir-005/lmbench/issues
|
|
29
|
+
Project-URL: Changelog, https://github.com/Pravir-005/lmbench/blob/main/CHANGELOG.md
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# lmbench
|
|
33
|
+
|
|
34
|
+
[](https://github.com/Pravir-005/lmbench/actions/workflows/ci.yml)
|
|
35
|
+
[](https://pypi.org/project/lmbench-llm/)
|
|
36
|
+
[](https://pypi.org/project/lmbench-llm/)
|
|
37
|
+
[](LICENSE)
|
|
38
|
+
|
|
39
|
+
**Measure which of your local LLMs works best on *your* machine.**
|
|
40
|
+
lmbench benchmarks the models installed in [Ollama](https://ollama.com): speed, memory, CPU offload, how performance
|
|
41
|
+
changes as the context window grows, and answer quality on small tasks graded by code. Then it ranks them and
|
|
42
|
+
recommends one for what you need ("best coding model that fits in 4 GB of VRAM").
|
|
43
|
+
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
## Why
|
|
47
|
+
|
|
48
|
+
Leaderboard scores come from datacenter GPUs. On a laptop GPU with 4 to 8 GB of VRAM, the interesting questions are
|
|
49
|
+
different: does this 7B model fit, how much of it spills onto the CPU, what happens to speed at 8k context, and is it
|
|
50
|
+
actually good enough at *my* tasks? lmbench answers those with measurements from your own hardware.
|
|
51
|
+
|
|
52
|
+
- **Fully local and free.** No cloud APIs. Quality is graded by deterministic code, not by another model.
|
|
53
|
+
- **Small-VRAM aware.** Reports peak RAM and VRAM, how much of each model is offloaded to the CPU, and a context-size
|
|
54
|
+
sweep that shows where speed falls off a cliff.
|
|
55
|
+
- **One decision.** Combines speed, memory and quality into a score with profiles (`coding`, `interactive`, ...) and
|
|
56
|
+
hard limits (`--max-vram`, `--min-tps`, ...).
|
|
57
|
+
|
|
58
|
+
## Install
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
uv tool install lmbench-llm # recommended
|
|
62
|
+
# or: pipx install lmbench-llm
|
|
63
|
+
# or: pip install lmbench-llm
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The package is called `lmbench-llm` on PyPI; the command it installs is `lmbench`. Requires Python 3.11+ and a
|
|
67
|
+
running Ollama (`ollama serve`) with at least one model pulled.
|
|
68
|
+
|
|
69
|
+
From source:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
git clone https://github.com/Pravir-005/lmbench && cd lmbench
|
|
73
|
+
uv sync && uv run lmbench --help
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick start
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
lmbench hardware # what lmbench detects: CPU, RAM, NVIDIA GPU + VRAM
|
|
80
|
+
lmbench run --quick # fast trial of every installed model (a few minutes each)
|
|
81
|
+
lmbench run -o results.json # full benchmark, saved
|
|
82
|
+
lmbench recommend results.json -p coding --max-vram 4
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Example result (format only; run it to get your own numbers):
|
|
86
|
+
|
|
87
|
+
```text
|
|
88
|
+
Recommended (coding): <model> scores NN/100 (quality NN%, NN.N tok/s, N.N GB loaded, NN% offloaded to the CPU).
|
|
89
|
+
Ruled out:
|
|
90
|
+
<model>: needs N.N GB to fit entirely in VRAM (limit 4 GB)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Results measured on the author's machine are in [RESULTS.md](RESULTS.md).
|
|
94
|
+
|
|
95
|
+
## Commands
|
|
96
|
+
|
|
97
|
+
| Command | What it does |
|
|
98
|
+
|---|---|
|
|
99
|
+
| `lmbench hardware` | Show detected CPU, RAM and NVIDIA GPU |
|
|
100
|
+
| `lmbench models` | List models installed in Ollama |
|
|
101
|
+
| `lmbench speed` | Tokens/sec, time to first token, peak RAM/VRAM, CPU offload |
|
|
102
|
+
| `lmbench context` | Speed and memory at different context-window sizes |
|
|
103
|
+
| `lmbench quality` | 25 tasks in 5 suites (coding, json, reasoning, instruct, summarize) |
|
|
104
|
+
| `lmbench run` | All of the above for every model, then a ranking |
|
|
105
|
+
| `lmbench report` | Rank models from saved result files (terminal, Markdown, HTML) |
|
|
106
|
+
| `lmbench recommend` | Pick the best model for your needs, with the reasons |
|
|
107
|
+
|
|
108
|
+
Every option, column and term is explained in the [command reference](docs/command-reference.pdf).
|
|
109
|
+
Result files from separate commands can be combined: `lmbench report speed.json quality.json context.json`.
|
|
110
|
+
|
|
111
|
+
## How it measures
|
|
112
|
+
|
|
113
|
+
- **Speed** comes from Ollama's own timing data: tokens/sec = output tokens / generation time (median of several runs
|
|
114
|
+
after a discarded warm-up). Time to first token is measured on the streamed response.
|
|
115
|
+
- **Memory.** Peak RAM is the resident memory of the Ollama processes; peak VRAM is the extra GPU memory used during
|
|
116
|
+
the run (NVML). Offload comes from Ollama's `/api/ps`: the share of the loaded model that is not in VRAM.
|
|
117
|
+
- **Context scaling.** The model is reloaded at each size and given a prompt that fills about 60% of the window. Each
|
|
118
|
+
prompt is slightly different so Ollama's prompt cache cannot flatter the result.
|
|
119
|
+
- **Quality.** Temperature 0, fixed seed. Coding answers run against hidden unit tests; JSON is validated; reasoning
|
|
120
|
+
needs a final `Answer:` line; instruction and summary tasks are rule-checked. Scores have partial credit.
|
|
121
|
+
|
|
122
|
+
## Scoring
|
|
123
|
+
|
|
124
|
+
`score = weighted mean of quality, speed and memory`, where speed is tok/s relative to a target (`--target-tps`,
|
|
125
|
+
default 30) and memory compares the loaded size to your VRAM. Models below 60% quality are scaled down so a fast model
|
|
126
|
+
that gets most tasks wrong cannot win. Profiles change the weights:
|
|
127
|
+
|
|
128
|
+
| Profile | Quality | Speed | Memory |
|
|
129
|
+
|---|---|---|---|
|
|
130
|
+
| `balanced` (default) | 0.50 | 0.30 | 0.20 |
|
|
131
|
+
| `coding` | 0.65 | 0.25 | 0.10 |
|
|
132
|
+
| `interactive` | 0.35 | 0.50 | 0.15 |
|
|
133
|
+
| `tight-memory` | 0.40 | 0.20 | 0.40 |
|
|
134
|
+
|
|
135
|
+
The weights are defaults, not truths. Adjust `--target-tps` and the profile until the ranking matches your judgement.
|
|
136
|
+
|
|
137
|
+
## Limitations
|
|
138
|
+
|
|
139
|
+
- **Ollama only** for now, and **VRAM sampling is NVIDIA only** (AMD and Apple Silicon report RAM only).
|
|
140
|
+
- **The quality suites are small** (25 tasks). One task moves a suite score by 20 points, so use them to compare
|
|
141
|
+
models, not as an absolute grade. They are also fairly easy: strong models may all score near 100%.
|
|
142
|
+
- **Reasoning models** (deepseek-r1, qwen3) can use many tokens thinking. Answers that hit the token limit are flagged
|
|
143
|
+
and scores marked as lower bounds; raise `--num-predict` if you see the warning.
|
|
144
|
+
- **Results are only comparable on the same machine.** `report` warns if files come from different hardware.
|
|
145
|
+
- **The coding suite executes model-written code on your machine.** It runs in a separate process with a 10-second
|
|
146
|
+
time limit and a memory limit where the OS allows, but it is not network-isolated. Run it on a machine you control.
|
|
147
|
+
|
|
148
|
+
## Related tools
|
|
149
|
+
|
|
150
|
+
lmbench measures models you have installed. If you want to know which models *could* run on your hardware before you
|
|
151
|
+
download them, see [whichllm](https://github.com/Andyyyy64/whichllm), which estimates this from your specs and
|
|
152
|
+
published benchmark results. Other Ollama benchmarking tools exist on PyPI, for example `local-inferbench` and
|
|
153
|
+
`ollama-spark`; lmbench's focus is the context-scaling and offload view, deterministic task grading and a
|
|
154
|
+
recommendation with explicit memory and speed limits.
|
|
155
|
+
|
|
156
|
+
## Contributing
|
|
157
|
+
|
|
158
|
+
Bug reports, new quality tasks, new backends (llama.cpp, LM Studio) and AMD/Apple memory sampling are all welcome.
|
|
159
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Sharing a results file from your hardware is a useful contribution too.
|
|
160
|
+
|
|
161
|
+
## License
|
|
162
|
+
|
|
163
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# lmbench
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Pravir-005/lmbench/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/lmbench-llm/)
|
|
5
|
+
[](https://pypi.org/project/lmbench-llm/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
**Measure which of your local LLMs works best on *your* machine.**
|
|
9
|
+
lmbench benchmarks the models installed in [Ollama](https://ollama.com): speed, memory, CPU offload, how performance
|
|
10
|
+
changes as the context window grows, and answer quality on small tasks graded by code. Then it ranks them and
|
|
11
|
+
recommends one for what you need ("best coding model that fits in 4 GB of VRAM").
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
Leaderboard scores come from datacenter GPUs. On a laptop GPU with 4 to 8 GB of VRAM, the interesting questions are
|
|
18
|
+
different: does this 7B model fit, how much of it spills onto the CPU, what happens to speed at 8k context, and is it
|
|
19
|
+
actually good enough at *my* tasks? lmbench answers those with measurements from your own hardware.
|
|
20
|
+
|
|
21
|
+
- **Fully local and free.** No cloud APIs. Quality is graded by deterministic code, not by another model.
|
|
22
|
+
- **Small-VRAM aware.** Reports peak RAM and VRAM, how much of each model is offloaded to the CPU, and a context-size
|
|
23
|
+
sweep that shows where speed falls off a cliff.
|
|
24
|
+
- **One decision.** Combines speed, memory and quality into a score with profiles (`coding`, `interactive`, ...) and
|
|
25
|
+
hard limits (`--max-vram`, `--min-tps`, ...).
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
uv tool install lmbench-llm # recommended
|
|
31
|
+
# or: pipx install lmbench-llm
|
|
32
|
+
# or: pip install lmbench-llm
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The package is called `lmbench-llm` on PyPI; the command it installs is `lmbench`. Requires Python 3.11+ and a
|
|
36
|
+
running Ollama (`ollama serve`) with at least one model pulled.
|
|
37
|
+
|
|
38
|
+
From source:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
git clone https://github.com/Pravir-005/lmbench && cd lmbench
|
|
42
|
+
uv sync && uv run lmbench --help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
lmbench hardware # what lmbench detects: CPU, RAM, NVIDIA GPU + VRAM
|
|
49
|
+
lmbench run --quick # fast trial of every installed model (a few minutes each)
|
|
50
|
+
lmbench run -o results.json # full benchmark, saved
|
|
51
|
+
lmbench recommend results.json -p coding --max-vram 4
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Example result (format only; run it to get your own numbers):
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
Recommended (coding): <model> scores NN/100 (quality NN%, NN.N tok/s, N.N GB loaded, NN% offloaded to the CPU).
|
|
58
|
+
Ruled out:
|
|
59
|
+
<model>: needs N.N GB to fit entirely in VRAM (limit 4 GB)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Results measured on the author's machine are in [RESULTS.md](RESULTS.md).
|
|
63
|
+
|
|
64
|
+
## Commands
|
|
65
|
+
|
|
66
|
+
| Command | What it does |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `lmbench hardware` | Show detected CPU, RAM and NVIDIA GPU |
|
|
69
|
+
| `lmbench models` | List models installed in Ollama |
|
|
70
|
+
| `lmbench speed` | Tokens/sec, time to first token, peak RAM/VRAM, CPU offload |
|
|
71
|
+
| `lmbench context` | Speed and memory at different context-window sizes |
|
|
72
|
+
| `lmbench quality` | 25 tasks in 5 suites (coding, json, reasoning, instruct, summarize) |
|
|
73
|
+
| `lmbench run` | All of the above for every model, then a ranking |
|
|
74
|
+
| `lmbench report` | Rank models from saved result files (terminal, Markdown, HTML) |
|
|
75
|
+
| `lmbench recommend` | Pick the best model for your needs, with the reasons |
|
|
76
|
+
|
|
77
|
+
Every option, column and term is explained in the [command reference](docs/command-reference.pdf).
|
|
78
|
+
Result files from separate commands can be combined: `lmbench report speed.json quality.json context.json`.
|
|
79
|
+
|
|
80
|
+
## How it measures
|
|
81
|
+
|
|
82
|
+
- **Speed** comes from Ollama's own timing data: tokens/sec = output tokens / generation time (median of several runs
|
|
83
|
+
after a discarded warm-up). Time to first token is measured on the streamed response.
|
|
84
|
+
- **Memory.** Peak RAM is the resident memory of the Ollama processes; peak VRAM is the extra GPU memory used during
|
|
85
|
+
the run (NVML). Offload comes from Ollama's `/api/ps`: the share of the loaded model that is not in VRAM.
|
|
86
|
+
- **Context scaling.** The model is reloaded at each size and given a prompt that fills about 60% of the window. Each
|
|
87
|
+
prompt is slightly different so Ollama's prompt cache cannot flatter the result.
|
|
88
|
+
- **Quality.** Temperature 0, fixed seed. Coding answers run against hidden unit tests; JSON is validated; reasoning
|
|
89
|
+
needs a final `Answer:` line; instruction and summary tasks are rule-checked. Scores have partial credit.
|
|
90
|
+
|
|
91
|
+
## Scoring
|
|
92
|
+
|
|
93
|
+
`score = weighted mean of quality, speed and memory`, where speed is tok/s relative to a target (`--target-tps`,
|
|
94
|
+
default 30) and memory compares the loaded size to your VRAM. Models below 60% quality are scaled down so a fast model
|
|
95
|
+
that gets most tasks wrong cannot win. Profiles change the weights:
|
|
96
|
+
|
|
97
|
+
| Profile | Quality | Speed | Memory |
|
|
98
|
+
|---|---|---|---|
|
|
99
|
+
| `balanced` (default) | 0.50 | 0.30 | 0.20 |
|
|
100
|
+
| `coding` | 0.65 | 0.25 | 0.10 |
|
|
101
|
+
| `interactive` | 0.35 | 0.50 | 0.15 |
|
|
102
|
+
| `tight-memory` | 0.40 | 0.20 | 0.40 |
|
|
103
|
+
|
|
104
|
+
The weights are defaults, not truths. Adjust `--target-tps` and the profile until the ranking matches your judgement.
|
|
105
|
+
|
|
106
|
+
## Limitations
|
|
107
|
+
|
|
108
|
+
- **Ollama only** for now, and **VRAM sampling is NVIDIA only** (AMD and Apple Silicon report RAM only).
|
|
109
|
+
- **The quality suites are small** (25 tasks). One task moves a suite score by 20 points, so use them to compare
|
|
110
|
+
models, not as an absolute grade. They are also fairly easy: strong models may all score near 100%.
|
|
111
|
+
- **Reasoning models** (deepseek-r1, qwen3) can use many tokens thinking. Answers that hit the token limit are flagged
|
|
112
|
+
and scores marked as lower bounds; raise `--num-predict` if you see the warning.
|
|
113
|
+
- **Results are only comparable on the same machine.** `report` warns if files come from different hardware.
|
|
114
|
+
- **The coding suite executes model-written code on your machine.** It runs in a separate process with a 10-second
|
|
115
|
+
time limit and a memory limit where the OS allows, but it is not network-isolated. Run it on a machine you control.
|
|
116
|
+
|
|
117
|
+
## Related tools
|
|
118
|
+
|
|
119
|
+
lmbench measures models you have installed. If you want to know which models *could* run on your hardware before you
|
|
120
|
+
download them, see [whichllm](https://github.com/Andyyyy64/whichllm), which estimates this from your specs and
|
|
121
|
+
published benchmark results. Other Ollama benchmarking tools exist on PyPI, for example `local-inferbench` and
|
|
122
|
+
`ollama-spark`; lmbench's focus is the context-scaling and offload view, deterministic task grading and a
|
|
123
|
+
recommendation with explicit memory and speed limits.
|
|
124
|
+
|
|
125
|
+
## Contributing
|
|
126
|
+
|
|
127
|
+
Bug reports, new quality tasks, new backends (llama.cpp, LM Studio) and AMD/Apple memory sampling are all welcome.
|
|
128
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Sharing a results file from your hardware is a useful contribution too.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lmbench-llm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Benchmark the LLMs installed in Ollama on your own machine: speed, memory, context scaling and task quality, then pick the best one."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
keywords = [
|
|
10
|
+
"llm",
|
|
11
|
+
"benchmark",
|
|
12
|
+
"ollama",
|
|
13
|
+
"local-llm",
|
|
14
|
+
"inference",
|
|
15
|
+
"cli",
|
|
16
|
+
"gpu",
|
|
17
|
+
"vram",
|
|
18
|
+
]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Environment :: Console",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Intended Audience :: Science/Research",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
30
|
+
"Topic :: System :: Benchmark",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"httpx>=0.27",
|
|
34
|
+
"nvidia-ml-py>=12.0",
|
|
35
|
+
"psutil>=5.9",
|
|
36
|
+
"rich>=13.7",
|
|
37
|
+
"typer>=0.15",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[[project.authors]]
|
|
41
|
+
name = "Pravir Nihar Maity"
|
|
42
|
+
|
|
43
|
+
[project.urls]
|
|
44
|
+
Homepage = "https://github.com/Pravir-005/lmbench"
|
|
45
|
+
Repository = "https://github.com/Pravir-005/lmbench"
|
|
46
|
+
Issues = "https://github.com/Pravir-005/lmbench/issues"
|
|
47
|
+
Changelog = "https://github.com/Pravir-005/lmbench/blob/main/CHANGELOG.md"
|
|
48
|
+
|
|
49
|
+
[project.scripts]
|
|
50
|
+
lmbench = "lmbench.cli:app"
|
|
51
|
+
|
|
52
|
+
[build-system]
|
|
53
|
+
requires = ["uv_build>=0.11.32,<0.12.0"]
|
|
54
|
+
build-backend = "uv_build"
|
|
55
|
+
|
|
56
|
+
[tool.uv.build-backend]
|
|
57
|
+
module-name = "lmbench"
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
61
|
+
pythonpath = ["."]
|
|
62
|
+
|
|
63
|
+
[tool.ruff]
|
|
64
|
+
line-length = 120
|
|
65
|
+
target-version = "py311"
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint]
|
|
68
|
+
select = [
|
|
69
|
+
"E",
|
|
70
|
+
"F",
|
|
71
|
+
"W",
|
|
72
|
+
"I",
|
|
73
|
+
"B",
|
|
74
|
+
"UP",
|
|
75
|
+
]
|
|
76
|
+
ignore = [
|
|
77
|
+
"E501",
|
|
78
|
+
"B008",
|
|
79
|
+
"B904",
|
|
80
|
+
"B905",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[dependency-groups]
|
|
84
|
+
dev = [
|
|
85
|
+
"pytest>=9.2.0",
|
|
86
|
+
"ruff>=0.6",
|
|
87
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lmbench-llm"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Benchmark the LLMs installed in Ollama on your own machine: speed, memory, context scaling and task quality, then pick the best one."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Pravir Nihar Maity" }]
|
|
9
|
+
requires-python = ">=3.11"
|
|
10
|
+
keywords = ["llm", "benchmark", "ollama", "local-llm", "inference", "cli", "gpu", "vram"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Environment :: Console",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
"Topic :: System :: Benchmark",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"httpx>=0.27",
|
|
26
|
+
"nvidia-ml-py>=12.0",
|
|
27
|
+
"psutil>=5.9",
|
|
28
|
+
"rich>=13.7",
|
|
29
|
+
"typer>=0.15",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/Pravir-005/lmbench"
|
|
34
|
+
Repository = "https://github.com/Pravir-005/lmbench"
|
|
35
|
+
Issues = "https://github.com/Pravir-005/lmbench/issues"
|
|
36
|
+
Changelog = "https://github.com/Pravir-005/lmbench/blob/main/CHANGELOG.md"
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
lmbench = "lmbench.cli:app"
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["uv_build>=0.11.32,<0.12.0"]
|
|
43
|
+
build-backend = "uv_build"
|
|
44
|
+
|
|
45
|
+
[tool.uv.build-backend]
|
|
46
|
+
# The PyPI name is "lmbench-llm" (plain "lmbench" is taken); the import name and command stay "lmbench".
|
|
47
|
+
module-name = "lmbench"
|
|
48
|
+
|
|
49
|
+
[dependency-groups]
|
|
50
|
+
dev = [
|
|
51
|
+
"pytest>=9.2.0",
|
|
52
|
+
"ruff>=0.6",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
pythonpath = ["."]
|
|
58
|
+
|
|
59
|
+
[tool.ruff]
|
|
60
|
+
line-length = 120
|
|
61
|
+
target-version = "py311"
|
|
62
|
+
|
|
63
|
+
[tool.ruff.lint]
|
|
64
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
65
|
+
ignore = [
|
|
66
|
+
"E501", # long lines: some test data and prompts are intentionally one line
|
|
67
|
+
"B008", # typer's idiom is typer.Option(...) as a default value
|
|
68
|
+
"B904", # CLI code re-raises as typer.BadParameter / typer.Exit inside except blocks
|
|
69
|
+
"B905", # zip(strict=...) is not needed here
|
|
70
|
+
]
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""lmbench: benchmark local LLMs on your own hardware."""
|
|
2
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
__version__ = version("lmbench-llm") # the name on PyPI; single source of truth is pyproject.toml
|
|
6
|
+
except PackageNotFoundError: # running from a source tree that was never installed
|
|
7
|
+
__version__ = "0.0.0+unknown"
|
|
File without changes
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Protocol
|
|
5
|
+
|
|
6
|
+
NS = 1_000_000_000 # Ollama reports durations in nanoseconds
|
|
7
|
+
|
|
8
|
+
class BackendError(RuntimeError):
|
|
9
|
+
"""Raised when a backend is unreachable or returns an error."""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass(frozen=True)
|
|
13
|
+
class ModelInfo:
|
|
14
|
+
name: str
|
|
15
|
+
size_bytes: int | None = None
|
|
16
|
+
parameter_size: str | None = None # e.g. "7.6B"
|
|
17
|
+
quantization: str | None = None # e.g. "Q4_K_M"
|
|
18
|
+
family: str | None = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class GenerationResult:
|
|
23
|
+
"""Raw timings for one generation. Durations are in seconds."""
|
|
24
|
+
model: str
|
|
25
|
+
text: str
|
|
26
|
+
prompt_tokens: int
|
|
27
|
+
output_tokens: int
|
|
28
|
+
total_s: float
|
|
29
|
+
load_s: float
|
|
30
|
+
prompt_eval_s: float
|
|
31
|
+
eval_s: float
|
|
32
|
+
ttft_s: float | None # wall-clock time to first streamed token
|
|
33
|
+
done_reason: str | None = None # Ollama: 'stop' (finished) or 'length' (hit num_predict)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Backend(Protocol):
|
|
37
|
+
def list_models(self) -> list[ModelInfo]: ...
|
|
38
|
+
|
|
39
|
+
def generate(self, model: str, prompt: str, *, num_ctx: int | None = None,
|
|
40
|
+
num_predict: int = 128, seed: int = 42,
|
|
41
|
+
temperature: float = 0.0, think: bool | None = None) -> GenerationResult: ...
|
|
42
|
+
|
|
43
|
+
def running(self) -> list[dict]: ...
|
|
44
|
+
|
|
45
|
+
def unload(self, model: str) -> None: ...
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import httpx
|
|
7
|
+
|
|
8
|
+
from .base import NS, BackendError, GenerationResult, ModelInfo
|
|
9
|
+
|
|
10
|
+
DEFAULT_URL = "http://localhost:11434"
|
|
11
|
+
|
|
12
|
+
def _norm(name: str) -> str:
|
|
13
|
+
"""'qwen2.5' and 'qwen2.5:latest' are the same model."""
|
|
14
|
+
return name if ":" in name else f"{name}:latest"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class OllamaBackend:
|
|
18
|
+
def __init__(self, base_url: str = DEFAULT_URL, *, timeout: float = 600.0,
|
|
19
|
+
transport: httpx.BaseTransport | None = None) -> None:
|
|
20
|
+
# `transport` lets tests inject httpx.MockTransport (no real server needed).
|
|
21
|
+
self._client = httpx.Client(base_url=base_url, timeout=timeout, transport=transport)
|
|
22
|
+
|
|
23
|
+
# ---- discovery -------------------------------------------------------
|
|
24
|
+
def list_models(self) -> list[ModelInfo]:
|
|
25
|
+
data = self._get("/api/tags")
|
|
26
|
+
out = []
|
|
27
|
+
for m in data.get("models", []):
|
|
28
|
+
d = m.get("details") or {}
|
|
29
|
+
out.append(ModelInfo(
|
|
30
|
+
name=m["name"],
|
|
31
|
+
size_bytes=m.get("size"),
|
|
32
|
+
parameter_size=d.get("parameter_size"),
|
|
33
|
+
quantization=d.get("quantization_level"),
|
|
34
|
+
family=d.get("family"),
|
|
35
|
+
))
|
|
36
|
+
return out
|
|
37
|
+
|
|
38
|
+
def version(self) -> str | None:
|
|
39
|
+
try:
|
|
40
|
+
return self._get("/api/version").get("version")
|
|
41
|
+
except BackendError:
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
def running(self) -> list[dict]:
|
|
45
|
+
"""Models currently loaded (includes size and size_vram). Used on Day 2."""
|
|
46
|
+
return self._get("/api/ps").get("models", [])
|
|
47
|
+
|
|
48
|
+
# ---- generation ------------------------------------------------------
|
|
49
|
+
def generate(self, model: str, prompt: str, *, num_ctx: int | None = None,
|
|
50
|
+
num_predict: int = 128, seed: int = 42,
|
|
51
|
+
temperature: float = 0.0, think: bool | None = None) -> GenerationResult:
|
|
52
|
+
options: dict = {"temperature": temperature, "seed": seed, "num_predict": num_predict}
|
|
53
|
+
if num_ctx:
|
|
54
|
+
options["num_ctx"] = num_ctx
|
|
55
|
+
payload = {"model": model, "prompt": prompt, "stream": True, "options": options}
|
|
56
|
+
if think is not None:
|
|
57
|
+
payload["think"]=think
|
|
58
|
+
|
|
59
|
+
text_parts: list[str] = []
|
|
60
|
+
final: dict = {}
|
|
61
|
+
ttft: float | None = None
|
|
62
|
+
start = time.perf_counter()
|
|
63
|
+
try:
|
|
64
|
+
with self._client.stream("POST", "/api/generate", json=payload) as r:
|
|
65
|
+
if r.status_code != 200:
|
|
66
|
+
r.read()
|
|
67
|
+
raise BackendError(f"Ollama returned {r.status_code}: {r.text[:200]}")
|
|
68
|
+
for line in r.iter_lines():
|
|
69
|
+
if not line:
|
|
70
|
+
continue
|
|
71
|
+
chunk = json.loads(line)
|
|
72
|
+
if chunk.get("error"):
|
|
73
|
+
raise BackendError(chunk["error"])
|
|
74
|
+
piece = chunk.get("response") or chunk.get("thinking") or ""
|
|
75
|
+
if piece and ttft is None:
|
|
76
|
+
ttft = time.perf_counter() - start
|
|
77
|
+
if chunk.get("response"):
|
|
78
|
+
text_parts.append(chunk["response"])
|
|
79
|
+
if chunk.get("done"):
|
|
80
|
+
final = chunk
|
|
81
|
+
except httpx.ConnectError as e:
|
|
82
|
+
raise BackendError("Cannot reach Ollama. Is it running? (try: ollama serve)") from e
|
|
83
|
+
except httpx.HTTPError as e:
|
|
84
|
+
raise BackendError(f"HTTP error talking to Ollama: {e}") from e
|
|
85
|
+
|
|
86
|
+
if not final:
|
|
87
|
+
raise BackendError("Stream ended without a final 'done' message.")
|
|
88
|
+
return GenerationResult(
|
|
89
|
+
model=model,
|
|
90
|
+
text="".join(text_parts),
|
|
91
|
+
prompt_tokens=final.get("prompt_eval_count", 0),
|
|
92
|
+
output_tokens=final.get("eval_count", 0),
|
|
93
|
+
total_s=final.get("total_duration", 0) / NS,
|
|
94
|
+
load_s=final.get("load_duration", 0) / NS,
|
|
95
|
+
prompt_eval_s=final.get("prompt_eval_duration", 0) / NS,
|
|
96
|
+
eval_s=final.get("eval_duration", 0) / NS,
|
|
97
|
+
ttft_s=ttft,
|
|
98
|
+
done_reason=final.get("done_reason"),
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def unload(self, model: str, *, wait_s: float = 15.0) -> None:
|
|
102
|
+
"""Evict the model from memory (keep_alive = 0) and wait until Ollama reports it gone.
|
|
103
|
+
|
|
104
|
+
Ollama unloads asynchronously. Without waiting, the next measurement would take its
|
|
105
|
+
VRAM baseline while the old model still occupies the GPU, and report about 0 GB.
|
|
106
|
+
"""
|
|
107
|
+
self._post("/api/generate", {"model": model, "keep_alive": 0})
|
|
108
|
+
target = _norm(model)
|
|
109
|
+
deadline = time.monotonic() + wait_s
|
|
110
|
+
while time.monotonic() < deadline:
|
|
111
|
+
still_loaded = any(target in {_norm(m[k]) for k in ("name", "model") if m.get(k)}
|
|
112
|
+
for m in self.running())
|
|
113
|
+
if not still_loaded:
|
|
114
|
+
time.sleep(0.3) # give the driver a moment to release the memory
|
|
115
|
+
return
|
|
116
|
+
time.sleep(0.2)
|
|
117
|
+
|
|
118
|
+
# ---- helpers ---------------------------------------------------------
|
|
119
|
+
def _get(self, path: str) -> dict:
|
|
120
|
+
try:
|
|
121
|
+
r = self._client.get(path)
|
|
122
|
+
r.raise_for_status()
|
|
123
|
+
return r.json()
|
|
124
|
+
except httpx.ConnectError as e:
|
|
125
|
+
raise BackendError("Cannot reach Ollama. Is it running? (try: ollama serve)") from e
|
|
126
|
+
except httpx.HTTPError as e:
|
|
127
|
+
raise BackendError(f"HTTP error talking to Ollama: {e}") from e
|
|
128
|
+
|
|
129
|
+
def _post(self, path: str, payload: dict) -> dict:
|
|
130
|
+
try:
|
|
131
|
+
r = self._client.post(path, json=payload)
|
|
132
|
+
r.raise_for_status()
|
|
133
|
+
return r.json()
|
|
134
|
+
except httpx.ConnectError as e:
|
|
135
|
+
raise BackendError("Cannot reach Ollama. Is it running? (try: ollama serve)") from e
|
|
136
|
+
except httpx.HTTPError as e:
|
|
137
|
+
raise BackendError(f"HTTP error talking to Ollama: {e}") from e
|
|
File without changes
|