inferbench-cli 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.
Files changed (41) hide show
  1. inferbench_cli-0.1.0/.gitignore +8 -0
  2. inferbench_cli-0.1.0/LICENSE +202 -0
  3. inferbench_cli-0.1.0/PKG-INFO +221 -0
  4. inferbench_cli-0.1.0/README.md +186 -0
  5. inferbench_cli-0.1.0/examples/README.md +31 -0
  6. inferbench_cli-0.1.0/pyproject.toml +65 -0
  7. inferbench_cli-0.1.0/src/inferbench/__init__.py +59 -0
  8. inferbench_cli-0.1.0/src/inferbench/benchmark.py +121 -0
  9. inferbench_cli-0.1.0/src/inferbench/cli.py +173 -0
  10. inferbench_cli-0.1.0/src/inferbench/cost/__init__.py +0 -0
  11. inferbench_cli-0.1.0/src/inferbench/cost/cloud_comparison.py +42 -0
  12. inferbench_cli-0.1.0/src/inferbench/engines/__init__.py +0 -0
  13. inferbench_cli-0.1.0/src/inferbench/engines/llamacpp.py +61 -0
  14. inferbench_cli-0.1.0/src/inferbench/engines/omlx.py +97 -0
  15. inferbench_cli-0.1.0/src/inferbench/engines/registry.py +31 -0
  16. inferbench_cli-0.1.0/src/inferbench/errors.py +48 -0
  17. inferbench_cli-0.1.0/src/inferbench/hardware/__init__.py +0 -0
  18. inferbench_cli-0.1.0/src/inferbench/hardware/detect.py +109 -0
  19. inferbench_cli-0.1.0/src/inferbench/harness/__init__.py +0 -0
  20. inferbench_cli-0.1.0/src/inferbench/harness/measure.py +103 -0
  21. inferbench_cli-0.1.0/src/inferbench/harness/spawn_server.py +69 -0
  22. inferbench_cli-0.1.0/src/inferbench/prompts.py +22 -0
  23. inferbench_cli-0.1.0/src/inferbench/py.typed +0 -0
  24. inferbench_cli-0.1.0/src/inferbench/recommend/__init__.py +0 -0
  25. inferbench_cli-0.1.0/src/inferbench/recommend/config.py +29 -0
  26. inferbench_cli-0.1.0/src/inferbench/report/__init__.py +0 -0
  27. inferbench_cli-0.1.0/src/inferbench/report/json_report.py +66 -0
  28. inferbench_cli-0.1.0/src/inferbench/types.py +95 -0
  29. inferbench_cli-0.1.0/tests/__init__.py +0 -0
  30. inferbench_cli-0.1.0/tests/conftest.py +84 -0
  31. inferbench_cli-0.1.0/tests/test_benchmark.py +131 -0
  32. inferbench_cli-0.1.0/tests/test_cli.py +43 -0
  33. inferbench_cli-0.1.0/tests/test_cloud_comparison.py +22 -0
  34. inferbench_cli-0.1.0/tests/test_detect.py +19 -0
  35. inferbench_cli-0.1.0/tests/test_json_report.py +49 -0
  36. inferbench_cli-0.1.0/tests/test_llamacpp.py +33 -0
  37. inferbench_cli-0.1.0/tests/test_measure.py +127 -0
  38. inferbench_cli-0.1.0/tests/test_omlx.py +33 -0
  39. inferbench_cli-0.1.0/tests/test_recommend.py +55 -0
  40. inferbench_cli-0.1.0/tests/test_registry.py +30 -0
  41. inferbench_cli-0.1.0/tests/test_spawn_server.py +37 -0
@@ -0,0 +1,8 @@
1
+ .venv/
2
+ .venv-freshinstall/
3
+ dist/
4
+ build/
5
+ *.egg-info/
6
+ __pycache__/
7
+ *.pyc
8
+ .pytest_cache/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,221 @@
1
+ Metadata-Version: 2.4
2
+ Name: inferbench-cli
3
+ Version: 0.1.0
4
+ Summary: Vendor-neutral local-LLM-inference benchmark and hardware-config advisor for omlx and llama.cpp -- measures real tokens/second on your own hardware, live.
5
+ Project-URL: Homepage, https://github.com/RudrenduPaul/InferBench
6
+ Project-URL: Repository, https://github.com/RudrenduPaul/InferBench
7
+ Project-URL: Bug Tracker, https://github.com/RudrenduPaul/InferBench/issues
8
+ Project-URL: Changelog, https://github.com/RudrenduPaul/InferBench/blob/main/CHANGELOG.md
9
+ Project-URL: Documentation, https://github.com/RudrenduPaul/InferBench/blob/main/docs/getting-started.md
10
+ Project-URL: Author - Rudrendu Paul, https://github.com/RudrenduPaul
11
+ Project-URL: Author - Sourav Nandy, https://github.com/Sourav-nandy-ai
12
+ Author: Rudrendu Paul, Sourav Nandy
13
+ License-Expression: Apache-2.0
14
+ License-File: LICENSE
15
+ Keywords: apple-silicon,benchmark,cli,inference,llama.cpp,llm,local-llm,mlx,omlx
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Environment :: Console
18
+ Classifier: Intended Audience :: Developers
19
+ Classifier: License :: OSI Approved :: Apache Software License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Programming Language :: Python :: 3.13
27
+ Classifier: Topic :: Software Development :: Testing
28
+ Classifier: Topic :: System :: Benchmark
29
+ Requires-Python: >=3.9
30
+ Provides-Extra: dev
31
+ Requires-Dist: build<2,>=1.0; extra == 'dev'
32
+ Requires-Dist: pytest<10,>=7.0; extra == 'dev'
33
+ Requires-Dist: twine<7,>=5.0; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # inferbench-cli (Python)
37
+
38
+ Vendor-neutral benchmark for local-LLM-inference engines -- measures real
39
+ tokens/second for `omlx` and `llama.cpp` on your own hardware, live, and
40
+ recommends the faster engine for your exact machine and model. This
41
+ package is the Python distribution -- a genuine, independent port of the
42
+ npm package's TypeScript source, not a wrapper around the Node binary.
43
+
44
+ [![PyPI version](https://img.shields.io/pypi/v/inferbench-cli.svg)](https://pypi.org/project/inferbench-cli/)
45
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/RudrenduPaul/InferBench/blob/main/LICENSE)
46
+ [![Python versions](https://img.shields.io/pypi/pyversions/inferbench-cli.svg)](https://pypi.org/project/inferbench-cli/)
47
+ [![CI](https://github.com/RudrenduPaul/InferBench/actions/workflows/ci.yml/badge.svg)](https://github.com/RudrenduPaul/InferBench/actions/workflows/ci.yml)
48
+
49
+ ## Why this exists
50
+
51
+ Every local-inference engine publishes its own benchmark numbers, on its
52
+ own hardware, in its own README. None of them tell you which engine is
53
+ actually fastest on the machine sitting in front of you. InferBench starts
54
+ each engine's own OpenAI-compatible HTTP server on `127.0.0.1`, runs a
55
+ fixed, varied 8-prompt set through the exact same measurement code against
56
+ every engine, and reports the real, measured tokens/second -- not a number
57
+ copied from a blog post.
58
+
59
+ **Supported engines today: `omlx` and `llama.cpp`.** That is the complete
60
+ list this v0.1 release supports -- see [docs/concepts.md](https://github.com/RudrenduPaul/InferBench/blob/main/docs/concepts.md)
61
+ for why each engine needed its own adapter and what each one's real
62
+ constraints are.
63
+
64
+ ## Install
65
+
66
+ ```bash
67
+ pip install inferbench-cli
68
+ ```
69
+
70
+ or with [uv](https://docs.astral.sh/uv/):
71
+
72
+ ```bash
73
+ uv add inferbench-cli
74
+ ```
75
+
76
+ **Publish status, stated plainly**: this package is built, tested, and
77
+ verified end to end (see "Verified" in
78
+ [CHANGELOG.md](https://github.com/RudrenduPaul/InferBench/blob/main/CHANGELOG.md)),
79
+ but the first publish attempt was rejected by PyPI with `429 Too many new
80
+ projects created` -- a registry-side abuse throttle on this account, not a
81
+ problem with the package. Publish will be retried once that limit clears;
82
+ until then, `pip install inferbench-cli` will 404. Build it yourself from
83
+ source in the meantime: `pip install
84
+ git+https://github.com/RudrenduPaul/InferBench.git#subdirectory=python`.
85
+
86
+ Zero third-party dependencies -- the CLI, the HTTP harness, and the
87
+ hardware detector are all built on the Python standard library
88
+ (`argparse`, `urllib.request`, `subprocess`, `os`). The complementary
89
+ JS/TS distribution installs the same way on the npm side:
90
+ `npm install -g inferbench-cli` (or `npx inferbench-cli run ...` to run it
91
+ once without installing) -- see the
92
+ [project README](https://github.com/RudrenduPaul/InferBench#readme) for
93
+ that package. Both are meant to be first-class, maintained together.
94
+ **Honest note on the npm package's current status**: at the time of this
95
+ Python release, the npm package's own publish was blocked by a transient
96
+ npm-registry rate limit (`E429`), unrelated to code readiness -- the code
97
+ itself was already built and verified from a local tarball install. That
98
+ is a registry-side issue tracked separately from this PyPI release, which
99
+ is unaffected by it.
100
+
101
+ Either package still requires at least one supported engine already
102
+ installed on your machine -- neither package installs an inference engine
103
+ for you:
104
+
105
+ - **llama.cpp**: `brew install llama.cpp` (macOS) or build from
106
+ [ggml-org/llama.cpp](https://github.com/ggml-org/llama.cpp)
107
+ - **omlx**: `brew tap jundot/omlx https://github.com/jundot/omlx && brew install omlx`
108
+ (Apple Silicon only)
109
+
110
+ ## Quickstart
111
+
112
+ ```bash
113
+ # llama.cpp -- pass a Hugging Face repo spec; llama.cpp downloads and
114
+ # caches it automatically, no manual step required
115
+ inferbench run --engines llama.cpp --model "bartowski/Qwen2.5-1.5B-Instruct-GGUF:Q4_K_M"
116
+
117
+ # omlx -- pass the model-directory subdirectory name under ~/.omlx/models/;
118
+ # omlx has no CLI download flow, so the model must already be present there
119
+ inferbench run --engines omlx --model "qwen2.5-1.5b-instruct-4bit"
120
+
121
+ # Both installed engines, machine-readable output, saved to a file
122
+ inferbench run --model "<spec>" --json --out report.json
123
+ ```
124
+
125
+ **Known v0.1 limitation, carried over from the npm package and equally
126
+ true here:** `--model` means something different per engine (a
127
+ downloadable Hugging Face spec for llama.cpp, a pre-downloaded local
128
+ directory name for omlx), because the two engines have genuinely different
129
+ model-acquisition capabilities.
130
+
131
+ Or call the library directly (the agent-native path):
132
+
133
+ ```python
134
+ from inferbench import benchmark_engine, detect_hardware, all_engines, recommend
135
+
136
+ hardware = detect_hardware()
137
+ results = [
138
+ benchmark_engine(adapter, model="qwen2.5-1.5b-instruct-4bit")
139
+ for adapter in all_engines()
140
+ ]
141
+ best = recommend(results)
142
+ if best:
143
+ print(f"{best.engine}: {best.reason}")
144
+ ```
145
+
146
+ ## CLI command reference
147
+
148
+ ```
149
+ inferbench run [options]
150
+
151
+ Options:
152
+ --model <spec> Model spec (engine-specific, see Quickstart above) [required]
153
+ --engines <list> Comma-separated engines to test (default: all installed --
154
+ omlx, llama.cpp)
155
+ --max-tokens <n> Max completion tokens per prompt (default: 200)
156
+ --json Output machine-readable JSON instead of a human table
157
+ --out <file> Also write the full JSON report to this file
158
+ --verbose Show raw engine server stdout/stderr
159
+ ```
160
+
161
+ Exit code `0` on a successful run with at least one engine tested; `1` on
162
+ a resolvable usage error (e.g. an unknown `--engines` name) or when no
163
+ supported engine is installed. **One documented divergence from the npm
164
+ CLI**: a missing required flag (e.g. no `--model` at all) exits `2` here,
165
+ the standard `argparse`/Unix convention for a parse-time error, rather than
166
+ the npm CLI's `1` for the same case -- see
167
+ [docs/concepts.md](https://github.com/RudrenduPaul/InferBench/blob/main/docs/concepts.md)
168
+ for the full exit-code table.
169
+
170
+ ## How the measurement works
171
+
172
+ Same architecture as the npm package, ported faithfully: InferBench does
173
+ not shell out to each engine's own benchmark tool and parse its output --
174
+ `omlx` has no CLI benchmark command at all (verified against its real
175
+ README; its "Performance Benchmark" feature is a GUI-only, one-click
176
+ action in its admin dashboard). Instead, this package starts each engine's
177
+ own already-standardized OpenAI-compatible HTTP server (`omlx serve`,
178
+ `llama-server`) and sends the exact same prompts through the exact same
179
+ measurement code to every engine, timing the full response -- not just
180
+ time-to-first-byte. The original TypeScript harness had a real bug here
181
+ once (measuring right after `fetch()` resolved, which only captures HTTP
182
+ headers arriving, produced a physically impossible 64,646 tok/s during a
183
+ live end-to-end run before it was caught and fixed); this port measures
184
+ after the full response body is read, and a regression test
185
+ (`tests/test_measure.py`) asserts that gap is never reintroduced.
186
+
187
+ ## What "recommended" means (and doesn't)
188
+
189
+ The recommendation names the engine with the highest measured average
190
+ tokens/second **on this specific run, this specific hardware, this
191
+ specific model** -- not a general claim about which engine is best. A
192
+ different model, a different machine, or different thermal conditions can
193
+ change the answer.
194
+
195
+ ## Security
196
+
197
+ Neither this package nor the npm package ever `eval()`s, dynamically
198
+ imports, or shells through a string -- every subprocess call
199
+ (`llama-server`, `omlx`) is a fixed argv list (`subprocess.Popen([command,
200
+ *args], ...)`), never a shell string, so a `--model` value cannot inject
201
+ additional shell commands. **Honest note**: this project does not
202
+ currently publish SLSA provenance, Sigstore signatures, or an SBOM, and
203
+ has no OpenSSF Scorecard badge set up -- none of that infrastructure
204
+ exists yet for either distribution, so it isn't claimed here. See
205
+ [SECURITY.md](https://github.com/RudrenduPaul/InferBench/blob/main/SECURITY.md)
206
+ for the vulnerability-reporting process.
207
+
208
+ ## Contributing
209
+
210
+ See [CONTRIBUTING.md](https://github.com/RudrenduPaul/InferBench/blob/main/CONTRIBUTING.md).
211
+
212
+ ```bash
213
+ cd python
214
+ python3 -m venv .venv && source .venv/bin/activate
215
+ pip install -e ".[dev]"
216
+ pytest
217
+ ```
218
+
219
+ ## License
220
+
221
+ Apache 2.0, see [LICENSE](https://github.com/RudrenduPaul/InferBench/blob/main/LICENSE).
@@ -0,0 +1,186 @@
1
+ # inferbench-cli (Python)
2
+
3
+ Vendor-neutral benchmark for local-LLM-inference engines -- measures real
4
+ tokens/second for `omlx` and `llama.cpp` on your own hardware, live, and
5
+ recommends the faster engine for your exact machine and model. This
6
+ package is the Python distribution -- a genuine, independent port of the
7
+ npm package's TypeScript source, not a wrapper around the Node binary.
8
+
9
+ [![PyPI version](https://img.shields.io/pypi/v/inferbench-cli.svg)](https://pypi.org/project/inferbench-cli/)
10
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/RudrenduPaul/InferBench/blob/main/LICENSE)
11
+ [![Python versions](https://img.shields.io/pypi/pyversions/inferbench-cli.svg)](https://pypi.org/project/inferbench-cli/)
12
+ [![CI](https://github.com/RudrenduPaul/InferBench/actions/workflows/ci.yml/badge.svg)](https://github.com/RudrenduPaul/InferBench/actions/workflows/ci.yml)
13
+
14
+ ## Why this exists
15
+
16
+ Every local-inference engine publishes its own benchmark numbers, on its
17
+ own hardware, in its own README. None of them tell you which engine is
18
+ actually fastest on the machine sitting in front of you. InferBench starts
19
+ each engine's own OpenAI-compatible HTTP server on `127.0.0.1`, runs a
20
+ fixed, varied 8-prompt set through the exact same measurement code against
21
+ every engine, and reports the real, measured tokens/second -- not a number
22
+ copied from a blog post.
23
+
24
+ **Supported engines today: `omlx` and `llama.cpp`.** That is the complete
25
+ list this v0.1 release supports -- see [docs/concepts.md](https://github.com/RudrenduPaul/InferBench/blob/main/docs/concepts.md)
26
+ for why each engine needed its own adapter and what each one's real
27
+ constraints are.
28
+
29
+ ## Install
30
+
31
+ ```bash
32
+ pip install inferbench-cli
33
+ ```
34
+
35
+ or with [uv](https://docs.astral.sh/uv/):
36
+
37
+ ```bash
38
+ uv add inferbench-cli
39
+ ```
40
+
41
+ **Publish status, stated plainly**: this package is built, tested, and
42
+ verified end to end (see "Verified" in
43
+ [CHANGELOG.md](https://github.com/RudrenduPaul/InferBench/blob/main/CHANGELOG.md)),
44
+ but the first publish attempt was rejected by PyPI with `429 Too many new
45
+ projects created` -- a registry-side abuse throttle on this account, not a
46
+ problem with the package. Publish will be retried once that limit clears;
47
+ until then, `pip install inferbench-cli` will 404. Build it yourself from
48
+ source in the meantime: `pip install
49
+ git+https://github.com/RudrenduPaul/InferBench.git#subdirectory=python`.
50
+
51
+ Zero third-party dependencies -- the CLI, the HTTP harness, and the
52
+ hardware detector are all built on the Python standard library
53
+ (`argparse`, `urllib.request`, `subprocess`, `os`). The complementary
54
+ JS/TS distribution installs the same way on the npm side:
55
+ `npm install -g inferbench-cli` (or `npx inferbench-cli run ...` to run it
56
+ once without installing) -- see the
57
+ [project README](https://github.com/RudrenduPaul/InferBench#readme) for
58
+ that package. Both are meant to be first-class, maintained together.
59
+ **Honest note on the npm package's current status**: at the time of this
60
+ Python release, the npm package's own publish was blocked by a transient
61
+ npm-registry rate limit (`E429`), unrelated to code readiness -- the code
62
+ itself was already built and verified from a local tarball install. That
63
+ is a registry-side issue tracked separately from this PyPI release, which
64
+ is unaffected by it.
65
+
66
+ Either package still requires at least one supported engine already
67
+ installed on your machine -- neither package installs an inference engine
68
+ for you:
69
+
70
+ - **llama.cpp**: `brew install llama.cpp` (macOS) or build from
71
+ [ggml-org/llama.cpp](https://github.com/ggml-org/llama.cpp)
72
+ - **omlx**: `brew tap jundot/omlx https://github.com/jundot/omlx && brew install omlx`
73
+ (Apple Silicon only)
74
+
75
+ ## Quickstart
76
+
77
+ ```bash
78
+ # llama.cpp -- pass a Hugging Face repo spec; llama.cpp downloads and
79
+ # caches it automatically, no manual step required
80
+ inferbench run --engines llama.cpp --model "bartowski/Qwen2.5-1.5B-Instruct-GGUF:Q4_K_M"
81
+
82
+ # omlx -- pass the model-directory subdirectory name under ~/.omlx/models/;
83
+ # omlx has no CLI download flow, so the model must already be present there
84
+ inferbench run --engines omlx --model "qwen2.5-1.5b-instruct-4bit"
85
+
86
+ # Both installed engines, machine-readable output, saved to a file
87
+ inferbench run --model "<spec>" --json --out report.json
88
+ ```
89
+
90
+ **Known v0.1 limitation, carried over from the npm package and equally
91
+ true here:** `--model` means something different per engine (a
92
+ downloadable Hugging Face spec for llama.cpp, a pre-downloaded local
93
+ directory name for omlx), because the two engines have genuinely different
94
+ model-acquisition capabilities.
95
+
96
+ Or call the library directly (the agent-native path):
97
+
98
+ ```python
99
+ from inferbench import benchmark_engine, detect_hardware, all_engines, recommend
100
+
101
+ hardware = detect_hardware()
102
+ results = [
103
+ benchmark_engine(adapter, model="qwen2.5-1.5b-instruct-4bit")
104
+ for adapter in all_engines()
105
+ ]
106
+ best = recommend(results)
107
+ if best:
108
+ print(f"{best.engine}: {best.reason}")
109
+ ```
110
+
111
+ ## CLI command reference
112
+
113
+ ```
114
+ inferbench run [options]
115
+
116
+ Options:
117
+ --model <spec> Model spec (engine-specific, see Quickstart above) [required]
118
+ --engines <list> Comma-separated engines to test (default: all installed --
119
+ omlx, llama.cpp)
120
+ --max-tokens <n> Max completion tokens per prompt (default: 200)
121
+ --json Output machine-readable JSON instead of a human table
122
+ --out <file> Also write the full JSON report to this file
123
+ --verbose Show raw engine server stdout/stderr
124
+ ```
125
+
126
+ Exit code `0` on a successful run with at least one engine tested; `1` on
127
+ a resolvable usage error (e.g. an unknown `--engines` name) or when no
128
+ supported engine is installed. **One documented divergence from the npm
129
+ CLI**: a missing required flag (e.g. no `--model` at all) exits `2` here,
130
+ the standard `argparse`/Unix convention for a parse-time error, rather than
131
+ the npm CLI's `1` for the same case -- see
132
+ [docs/concepts.md](https://github.com/RudrenduPaul/InferBench/blob/main/docs/concepts.md)
133
+ for the full exit-code table.
134
+
135
+ ## How the measurement works
136
+
137
+ Same architecture as the npm package, ported faithfully: InferBench does
138
+ not shell out to each engine's own benchmark tool and parse its output --
139
+ `omlx` has no CLI benchmark command at all (verified against its real
140
+ README; its "Performance Benchmark" feature is a GUI-only, one-click
141
+ action in its admin dashboard). Instead, this package starts each engine's
142
+ own already-standardized OpenAI-compatible HTTP server (`omlx serve`,
143
+ `llama-server`) and sends the exact same prompts through the exact same
144
+ measurement code to every engine, timing the full response -- not just
145
+ time-to-first-byte. The original TypeScript harness had a real bug here
146
+ once (measuring right after `fetch()` resolved, which only captures HTTP
147
+ headers arriving, produced a physically impossible 64,646 tok/s during a
148
+ live end-to-end run before it was caught and fixed); this port measures
149
+ after the full response body is read, and a regression test
150
+ (`tests/test_measure.py`) asserts that gap is never reintroduced.
151
+
152
+ ## What "recommended" means (and doesn't)
153
+
154
+ The recommendation names the engine with the highest measured average
155
+ tokens/second **on this specific run, this specific hardware, this
156
+ specific model** -- not a general claim about which engine is best. A
157
+ different model, a different machine, or different thermal conditions can
158
+ change the answer.
159
+
160
+ ## Security
161
+
162
+ Neither this package nor the npm package ever `eval()`s, dynamically
163
+ imports, or shells through a string -- every subprocess call
164
+ (`llama-server`, `omlx`) is a fixed argv list (`subprocess.Popen([command,
165
+ *args], ...)`), never a shell string, so a `--model` value cannot inject
166
+ additional shell commands. **Honest note**: this project does not
167
+ currently publish SLSA provenance, Sigstore signatures, or an SBOM, and
168
+ has no OpenSSF Scorecard badge set up -- none of that infrastructure
169
+ exists yet for either distribution, so it isn't claimed here. See
170
+ [SECURITY.md](https://github.com/RudrenduPaul/InferBench/blob/main/SECURITY.md)
171
+ for the vulnerability-reporting process.
172
+
173
+ ## Contributing
174
+
175
+ See [CONTRIBUTING.md](https://github.com/RudrenduPaul/InferBench/blob/main/CONTRIBUTING.md).
176
+
177
+ ```bash
178
+ cd python
179
+ python3 -m venv .venv && source .venv/bin/activate
180
+ pip install -e ".[dev]"
181
+ pytest
182
+ ```
183
+
184
+ ## License
185
+
186
+ Apache 2.0, see [LICENSE](https://github.com/RudrenduPaul/InferBench/blob/main/LICENSE).
@@ -0,0 +1,31 @@
1
+ # Python examples
2
+
3
+ Each numbered subdirectory is a real, runnable script against the actual
4
+ `inferbench` Python library (`from inferbench import benchmark_engine,
5
+ ...`), not pseudocode. Every script talks to whichever engines are
6
+ actually installed on your machine -- none of them fabricate output when
7
+ an engine isn't present; they report `not installed` plainly instead.
8
+
9
+ Install the package first (editable install from this checkout, or `pip
10
+ install inferbench-cli` from PyPI both work identically):
11
+
12
+ ```bash
13
+ cd python
14
+ pip install -e .
15
+ ```
16
+
17
+ Then run any example directly (you need at least one of `omlx` or
18
+ `llama.cpp` installed, plus a model already available to it -- see the
19
+ [project README](../../README.md) for install instructions per engine):
20
+
21
+ ```bash
22
+ python3 examples/01-basic-run/run.py qwen2.5-1.5b-instruct-4bit
23
+ python3 examples/02-ci-gate/gate.py qwen2.5-1.5b-instruct-4bit 20
24
+ python3 examples/03-json-report/report.py qwen2.5-1.5b-instruct-4bit report.json
25
+ ```
26
+
27
+ | Example | What it demonstrates |
28
+ | --- | --- |
29
+ | [01-basic-run](./01-basic-run/) | The core library calls: `detect_hardware()`, `benchmark_engine()` per installed engine, `recommend()`, printing a human-readable summary -- the same functions `inferbench run` itself calls internally. |
30
+ | [02-ci-gate](./02-ci-gate/) | Using the library as a performance-floor gate: fail (non-zero exit) if the best measured throughput falls below a minimum tok/s, suitable for a scheduled job on fixed hardware (see [docs/integrations/ci.md](../../docs/integrations/ci.md) for why this is not recommended as a per-PR gate). |
31
+ | [03-json-report](./03-json-report/) | The agent-native use case: building a full `BenchmarkReport` in-process and serializing it to JSON with the same camelCase field names the npm CLI's `--json` output uses. |