Metadata-Version: 2.4
Name: lmbench-llm
Version: 0.1.0
Summary: Benchmark the LLMs installed in Ollama on your own machine: speed, memory, context scaling and task quality, then pick the best one.
Keywords: llm,benchmark,ollama,local-llm,inference,cli,gpu,vram
Author: Pravir Nihar Maity
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Benchmark
Requires-Dist: httpx>=0.27
Requires-Dist: nvidia-ml-py>=12.0
Requires-Dist: psutil>=5.9
Requires-Dist: rich>=13.7
Requires-Dist: typer>=0.15
Requires-Python: >=3.11
Project-URL: Homepage, https://github.com/Pravir-005/lmbench
Project-URL: Repository, https://github.com/Pravir-005/lmbench
Project-URL: Issues, https://github.com/Pravir-005/lmbench/issues
Project-URL: Changelog, https://github.com/Pravir-005/lmbench/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# lmbench

[![CI](https://github.com/Pravir-005/lmbench/actions/workflows/ci.yml/badge.svg)](https://github.com/Pravir-005/lmbench/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/lmbench-llm)](https://pypi.org/project/lmbench-llm/)
[![Python](https://img.shields.io/pypi/pyversions/lmbench-llm)](https://pypi.org/project/lmbench-llm/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

**Measure which of your local LLMs works best on *your* machine.**
lmbench benchmarks the models installed in [Ollama](https://ollama.com): speed, memory, CPU offload, how performance
changes as the context window grows, and answer quality on small tasks graded by code. Then it ranks them and
recommends one for what you need ("best coding model that fits in 4 GB of VRAM").

![lmbench demo](docs/demo.gif)

## Why

Leaderboard scores come from datacenter GPUs. On a laptop GPU with 4 to 8 GB of VRAM, the interesting questions are
different: does this 7B model fit, how much of it spills onto the CPU, what happens to speed at 8k context, and is it
actually good enough at *my* tasks? lmbench answers those with measurements from your own hardware.

- **Fully local and free.** No cloud APIs. Quality is graded by deterministic code, not by another model.
- **Small-VRAM aware.** Reports peak RAM and VRAM, how much of each model is offloaded to the CPU, and a context-size
  sweep that shows where speed falls off a cliff.
- **One decision.** Combines speed, memory and quality into a score with profiles (`coding`, `interactive`, ...) and
  hard limits (`--max-vram`, `--min-tps`, ...).

## Install

```bash
uv tool install lmbench-llm        # recommended
# or: pipx install lmbench-llm
# or: pip install lmbench-llm
```

The package is called `lmbench-llm` on PyPI; the command it installs is `lmbench`. Requires Python 3.11+ and a
running Ollama (`ollama serve`) with at least one model pulled.

From source:

```bash
git clone https://github.com/Pravir-005/lmbench && cd lmbench
uv sync && uv run lmbench --help
```

## Quick start

```bash
lmbench hardware                         # what lmbench detects: CPU, RAM, NVIDIA GPU + VRAM
lmbench run --quick                      # fast trial of every installed model (a few minutes each)
lmbench run -o results.json              # full benchmark, saved
lmbench recommend results.json -p coding --max-vram 4
```

Example result (format only; run it to get your own numbers):

```text
Recommended (coding): <model> scores NN/100 (quality NN%, NN.N tok/s, N.N GB loaded, NN% offloaded to the CPU).
Ruled out:
  <model>: needs N.N GB to fit entirely in VRAM (limit 4 GB)
```

Results measured on the author's machine are in [RESULTS.md](RESULTS.md).

## Commands

| Command | What it does |
|---|---|
| `lmbench hardware` | Show detected CPU, RAM and NVIDIA GPU |
| `lmbench models` | List models installed in Ollama |
| `lmbench speed` | Tokens/sec, time to first token, peak RAM/VRAM, CPU offload |
| `lmbench context` | Speed and memory at different context-window sizes |
| `lmbench quality` | 25 tasks in 5 suites (coding, json, reasoning, instruct, summarize) |
| `lmbench run` | All of the above for every model, then a ranking |
| `lmbench report` | Rank models from saved result files (terminal, Markdown, HTML) |
| `lmbench recommend` | Pick the best model for your needs, with the reasons |

Every option, column and term is explained in the [command reference](docs/command-reference.pdf).
Result files from separate commands can be combined: `lmbench report speed.json quality.json context.json`.

## How it measures

- **Speed** comes from Ollama's own timing data: tokens/sec = output tokens / generation time (median of several runs
  after a discarded warm-up). Time to first token is measured on the streamed response.
- **Memory.** Peak RAM is the resident memory of the Ollama processes; peak VRAM is the extra GPU memory used during
  the run (NVML). Offload comes from Ollama's `/api/ps`: the share of the loaded model that is not in VRAM.
- **Context scaling.** The model is reloaded at each size and given a prompt that fills about 60% of the window. Each
  prompt is slightly different so Ollama's prompt cache cannot flatter the result.
- **Quality.** Temperature 0, fixed seed. Coding answers run against hidden unit tests; JSON is validated; reasoning
  needs a final `Answer:` line; instruction and summary tasks are rule-checked. Scores have partial credit.

## Scoring

`score = weighted mean of quality, speed and memory`, where speed is tok/s relative to a target (`--target-tps`,
default 30) and memory compares the loaded size to your VRAM. Models below 60% quality are scaled down so a fast model
that gets most tasks wrong cannot win. Profiles change the weights:

| Profile | Quality | Speed | Memory |
|---|---|---|---|
| `balanced` (default) | 0.50 | 0.30 | 0.20 |
| `coding` | 0.65 | 0.25 | 0.10 |
| `interactive` | 0.35 | 0.50 | 0.15 |
| `tight-memory` | 0.40 | 0.20 | 0.40 |

The weights are defaults, not truths. Adjust `--target-tps` and the profile until the ranking matches your judgement.

## Limitations

- **Ollama only** for now, and **VRAM sampling is NVIDIA only** (AMD and Apple Silicon report RAM only).
- **The quality suites are small** (25 tasks). One task moves a suite score by 20 points, so use them to compare
  models, not as an absolute grade. They are also fairly easy: strong models may all score near 100%.
- **Reasoning models** (deepseek-r1, qwen3) can use many tokens thinking. Answers that hit the token limit are flagged
  and scores marked as lower bounds; raise `--num-predict` if you see the warning.
- **Results are only comparable on the same machine.** `report` warns if files come from different hardware.
- **The coding suite executes model-written code on your machine.** It runs in a separate process with a 10-second
  time limit and a memory limit where the OS allows, but it is not network-isolated. Run it on a machine you control.

## Related tools

lmbench measures models you have installed. If you want to know which models *could* run on your hardware before you
download them, see [whichllm](https://github.com/Andyyyy64/whichllm), which estimates this from your specs and
published benchmark results. Other Ollama benchmarking tools exist on PyPI, for example `local-inferbench` and
`ollama-spark`; lmbench's focus is the context-scaling and offload view, deterministic task grading and a
recommendation with explicit memory and speed limits.

## Contributing

Bug reports, new quality tasks, new backends (llama.cpp, LM Studio) and AMD/Apple memory sampling are all welcome.
See [CONTRIBUTING.md](CONTRIBUTING.md). Sharing a results file from your hardware is a useful contribution too.

## License

MIT. See [LICENSE](LICENSE).
