How to Benchmark a Local LLM with lm-eval in 30 Minutes

Why benchmark instead of trusting the model card

Two teams can both report "MMLU accuracy" and still measure different things: different prompts, few-shot examples, scoring rules, and dataset versions. A gap of a few points can come from the setup alone, not the model.

That is why EleutherAI's lm-evaluation-harness (lm-eval) became the default tool for this job. It powers the Hugging Face Open LLM Leaderboard and gives you one fixed way to run hundreds of published tasks. Run the same task version with the same settings, and the numbers are actually comparable.

One boundary: lm-eval measures a model on fixed, gold-labelled datasets. It answers "does this 8B model know more than that 7B model?" It does not judge a whole application.


Source: Differ, LLM Benchmark: An Ultimate Guide for 2025

Prerequisites

  • Python 3.9 or newer, ideally in a virtual environment
  • A GPU for anything above a tiny model; a CPU works for the small first run, but slowly
  • Disk space for weights and datasets, downloaded on first use
  • A Hugging Face login only for gated models or datasets

New to local models? See how to run an open model locally with Ollama and serving a model with vLLM first.

Step 1: Install lm-eval

The simplest install comes from PyPI:

pip install lm-eval

For the latest code plus optional backends, clone the repository and install with extras (vllm for the fast backend, api for hosted models):

git clone https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e ".[vllm,api]"

Confirm the tool is on your path, then list the task identifiers you pass to --tasks. Groups such as mmlu expand into many sub-tasks, one per subject:

lm_eval --help
lm_eval --tasks list

Step 2: Run your first benchmark

Start small. HellaSwag is a commonsense sentence-completion task, and Pythia 160M is tiny enough to run almost anywhere:

lm_eval \
  --model hf \
  --model_args pretrained=EleutherAI/pythia-160m \
  --tasks hellaswag \
  --device cuda:0 \
  --batch_size 16

What each flag does: --model hf selects the Hugging Face Transformers backend. --model_args is a comma-separated list of backend options, and pretrained= is the model ID or a local path. --device is where the model runs, such as cuda:0, cpu, or mps on Apple Silicon. --batch_size auto lets the harness pick the largest batch that fits in memory.

The results table has two columns that matter most for multiple-choice tasks: acc, raw accuracy, and acc_norm, accuracy after normalizing each candidate answer by its length. Short answers get an unfair boost under raw scoring, so acc_norm is usually the headline number. The stderr column is the standard error: a one-point gap with a large standard error is noise, not a win.

Step 3: Run a small suite, not a single task

One task never tells the whole story: a model can be strong at commonsense and weak at math. Pass several tasks at once so the harness loads the model once and runs everything:

lm_eval \
  --model hf \
  --model_args pretrained=meta-llama/Llama-3.1-8B,dtype=bfloat16 \
  --tasks mmlu,gsm8k,arc_challenge,winogrande \
  --device cuda:0 \
  --batch_size auto \
  --output_path results/llama31-8b

Always write results to a file with --output_path. The JSON contains the scores, every task's resolved config and version, and the model arguments, so anyone can reproduce your numbers later. A score printed to the terminal and lost is not a benchmark result.

A sensible starter suite is MMLU for broad knowledge, GSM8K for math, ARC-Challenge for science reasoning, and HellaSwag for commonsense. If you later compare a quantized model against its original, our GGUF quantization guide covers the format side, and this harness gives you the accuracy side.

Step 4: Get few-shot and chat format right

Many leaderboard numbers are few-shot: the prompt includes solved examples before the question. MMLU is conventionally 5-shot, and GSM8K is often 5-shot or 8-shot. Set it explicitly:

lm_eval \
  --model hf \
  --model_args pretrained=meta-llama/Llama-3.1-8B \
  --tasks mmlu \
  --num_fewshot 5 \
  --device cuda:0 \
  --batch_size auto

The few-shot count is part of the benchmark definition: a 0-shot MMLU number and a 5-shot MMLU number are different measurements, so always report the count with the score.

The other classic mistake is prompt format. For instruction-tuned or chat models, add --apply_chat_template so prompts are wrapped in the model's chat format. Without it, scores collapse, which looks like a bad model but is really a bad evaluation.

Step 5: Speed it up with vLLM, or point it at a local server

The Transformers backend is fine for small runs but slow on large suites. The vLLM backend batches aggressively and is much faster on a GPU:

lm_eval \
  --model vllm \
  --model_args pretrained=meta-llama/Llama-3.1-8B,tensor_parallel_size=1,gpu_memory_utilization=0.8 \
  --tasks mmlu,gsm8k \
  --batch_size auto

Here tensor_parallel_size shards the model across GPUs, and gpu_memory_utilization caps how much VRAM vLLM reserves for its key-value cache. Scores should match the hf backend within noise; if they diverge, suspect a tokenizer or chat-template mismatch first.

You can also benchmark a model already serving behind an OpenAI-compatible endpoint, such as a local vLLM server, Ollama, or LM Studio:

lm_eval \
  --model local-completions \
  --model_args model=my-model,base_url=http://localhost:8000/v1/completions \
  --tasks hellaswag

Limitation: endpoints without token log-probabilities cannot run log-likelihood multiple-choice tasks; use generation tasks such as GSM8K instead.



Source: Differ, LLM Benchmark: An Ultimate Guide for 2025

Reading the results

Open the JSON file from --output_path and check three things before quoting any number: the results block with the scores, the configs block with every task's version, and the top-level config block with the model, few-shot count, batch size, and git hash. If the harness bumped a task version between two runs, the benchmark definition changed and the numbers are not directly comparable.

Never report a score without its companions: task name and version, few-shot count, whether the chat template was applied, backend, and dtype. That one line of context turns a number into evidence.

Troubleshooting

  • CUDA out of memory: lower --batch_size or set it to auto, use dtype=bfloat16, or switch to vLLM.
  • Scores far below the model card: usually prompt format. Add --apply_chat_template for chat models, and check few-shot count and task version.
  • Task not found: run lm_eval --tasks list for the exact identifier.
  • API runs return zeros: multiple-choice tasks need token logprobs; use a generation task instead.
  • Results differ between runs: sampling adds variance on generation tasks. Fix the seed with --seed and prefer greedy decoding.

Closing: a comparison you can defend

Benchmark a base model and its instruction-tuned variant on the same suite, with identical task versions and few-shot counts, differing only in the model and the chat-template flag. Save both JSON files, diff them, and you have a comparison you can publish. Model cards will keep quoting bigger numbers. Now you can check them yourself in about thirty minutes.

Comments

Popular posts from this blog

Open-Source AI Weekly: Bonsai, GigaChat 4 Lead

Claude Claims Proof of Riemann Hypothesis After 167 Years

How to Build an AI Agent with LangGraph in 30 Minutes