SKILL.md
SKILL.mdBrowse 5 files
3,561 tokens
12,204 bytes
Token encoding: o200k_base
Snapshot 24fd22b
1---2name: evaluating-llms-harness3description: "lm-eval-harness: benchmark LLMs (MMLU, GSM8K, etc.)."4version: 1.0.15author: Orchestra Research6license: MIT7dependencies: [lm-eval, transformers, vllm]8platforms: [linux, macos]9metadata:10 hermes:11 tags: [Evaluation, LM Evaluation Harness, Benchmarking, MMLU, HumanEval, GSM8K, EleutherAI, Model Quality, Academic Benchmarks, Industry Standard]12 13---14 15# lm-evaluation-harness - LLM Benchmarking16 17## What's inside18 19Evaluates LLMs across 60+ academic benchmarks (MMLU, HumanEval, GSM8K, TruthfulQA, HellaSwag). Use when benchmarking model quality, comparing models, reporting academic results, or tracking training progress. Industry standard used by EleutherAI, HuggingFace, and major labs. Supports HuggingFace, vLLM, APIs.20 21## Quick start22 23lm-evaluation-harness evaluates LLMs across 60+ academic benchmarks using standardized prompts and metrics.24 25**Installation**:26```bash27pip install lm-eval28```29 30**Evaluate any HuggingFace model**:31```bash32lm_eval --model hf \33 --model_args pretrained=meta-llama/Llama-2-7b-hf \34 --tasks mmlu,gsm8k,hellaswag \35 --device cuda:0 \36 --batch_size 837```38 39**View available tasks**:40```bash41lm-eval ls tasks42```43 44## Common workflows45 46### Workflow 1: Standard benchmark evaluation47 48Evaluate model on core benchmarks (MMLU, GSM8K, HumanEval).49 50Copy this checklist:51 52```53Benchmark Evaluation:54- [ ] Step 1: Choose benchmark suite55- [ ] Step 2: Configure model56- [ ] Step 3: Run evaluation57- [ ] Step 4: Analyze results58```59 60**Step 1: Choose benchmark suite**61 62**Core reasoning benchmarks**:63- **MMLU** (Massive Multitask Language Understanding) - 57 subjects, multiple choice64- **GSM8K** - Grade school math word problems65- **HellaSwag** - Common sense reasoning66- **TruthfulQA** - Truthfulness and factuality67- **ARC** (AI2 Reasoning Challenge) - Science questions68 69**Code benchmarks**:70- **HumanEval** - Python code generation (164 problems)71- **MBPP** (Mostly Basic Python Problems) - Python coding72 73**Standard suite** (recommended for model releases):74```bash75--tasks mmlu,gsm8k,hellaswag,truthfulqa,arc_challenge76```77 78**Step 2: Configure model**79 80**HuggingFace model**:81```bash82lm_eval --model hf \83 --model_args pretrained=meta-llama/Llama-2-7b-hf,dtype=bfloat16 \84 --tasks mmlu \85 --device cuda:0 \86 --batch_size auto # Auto-detect optimal batch size87```88 89**Quantized model (4-bit/8-bit)**:90```bash91lm_eval --model hf \92 --model_args pretrained=meta-llama/Llama-2-7b-hf,load_in_4bit=True \93 --tasks mmlu \94 --device cuda:095```96 97**Custom checkpoint**:98```bash99lm_eval --model hf \100 --model_args pretrained=/path/to/my-model,tokenizer=/path/to/tokenizer \101 --tasks mmlu \102 --device cuda:0103```104 105**Step 3: Run evaluation**106 107```bash108# Full MMLU evaluation (57 subjects)109lm_eval --model hf \110 --model_args pretrained=meta-llama/Llama-2-7b-hf \111 --tasks mmlu \112 --num_fewshot 5 \ # 5-shot evaluation (standard)113 --batch_size 8 \114 --output_path results/ \115 --log_samples # Save individual predictions116 117# Multiple benchmarks at once118lm_eval --model hf \119 --model_args pretrained=meta-llama/Llama-2-7b-hf \120 --tasks mmlu,gsm8k,hellaswag,truthfulqa,arc_challenge \121 --num_fewshot 5 \122 --batch_size 8 \123 --output_path results/llama2-7b-eval.json124```125 126**Step 4: Analyze results**127 128Results saved to `results/llama2-7b-eval.json`:129 130```json131{132 "results": {133 "mmlu": {134 "acc": 0.459,135 "acc_stderr": 0.004136 },137 "gsm8k": {138 "exact_match": 0.142,139 "exact_match_stderr": 0.006140 },141 "hellaswag": {142 "acc_norm": 0.765,143 "acc_norm_stderr": 0.004144 }145 },146 "config": {147 "model": "hf",148 "model_args": "pretrained=meta-llama/Llama-2-7b-hf",149 "num_fewshot": 5150 }151}152```153 154### Workflow 2: Track training progress155 156Evaluate checkpoints during training.157 158```159Training Progress Tracking:160- [ ] Step 1: Set up periodic evaluation161- [ ] Step 2: Choose quick benchmarks162- [ ] Step 3: Automate evaluation163- [ ] Step 4: Plot learning curves164```165 166**Step 1: Set up periodic evaluation**167 168Evaluate every N training steps:169 170```bash171#!/bin/bash172# eval_checkpoint.sh173 174CHECKPOINT_DIR=$1175STEP=$2176 177lm_eval --model hf \178 --model_args pretrained=$CHECKPOINT_DIR/checkpoint-$STEP \179 --tasks gsm8k,hellaswag \180 --num_fewshot 0 \ # 0-shot for speed181 --batch_size 16 \182 --output_path results/step-$STEP.json183```184 185**Step 2: Choose quick benchmarks**186 187Fast benchmarks for frequent evaluation:188- **HellaSwag**: ~10 minutes on 1 GPU189- **GSM8K**: ~5 minutes190- **PIQA**: ~2 minutes191 192Avoid for frequent eval (too slow):193- **MMLU**: ~2 hours (57 subjects)194- **HumanEval**: Requires code execution195 196**Step 3: Automate evaluation**197 198Integrate with training script:199 200```python201# In training loop202if step % eval_interval == 0:203 model.save_pretrained(f"checkpoints/step-{step}")204 205 # Run evaluation206 os.system(f"./eval_checkpoint.sh checkpoints step-{step}")207```208 209Or use PyTorch Lightning callbacks:210 211```python212from pytorch_lightning import Callback213 214class EvalHarnessCallback(Callback):215 def on_validation_epoch_end(self, trainer, pl_module):216 step = trainer.global_step217 checkpoint_path = f"checkpoints/step-{step}"218 219 # Save checkpoint220 trainer.save_checkpoint(checkpoint_path)221 222 # Run lm-eval223 os.system(f"lm_eval --model hf --model_args pretrained={checkpoint_path} ...")224```225 226**Step 4: Plot learning curves**227 228```python229import json230import matplotlib.pyplot as plt231 232# Load all results233steps = []234mmlu_scores = []235 236for file in sorted(glob.glob("results/step-*.json")):237 with open(file) as f:238 data = json.load(f)239 step = int(file.split("-")[1].split(".")[0])240 steps.append(step)241 mmlu_scores.append(data["results"]["mmlu"]["acc"])242 243# Plot244plt.plot(steps, mmlu_scores)245plt.xlabel("Training Step")246plt.ylabel("MMLU Accuracy")247plt.title("Training Progress")248plt.savefig("training_curve.png")249```250 251### Workflow 3: Compare multiple models252 253Benchmark suite for model comparison.254 255```256Model Comparison:257- [ ] Step 1: Define model list258- [ ] Step 2: Run evaluations259- [ ] Step 3: Generate comparison table260```261 262**Step 1: Define model list**263 264```bash265# models.txt266meta-llama/Llama-2-7b-hf267meta-llama/Llama-2-13b-hf268mistralai/Mistral-7B-v0.1269microsoft/phi-2270```271 272**Step 2: Run evaluations**273 274```bash275#!/bin/bash276# eval_all_models.sh277 278TASKS="mmlu,gsm8k,hellaswag,truthfulqa"279 280while read model; do281 echo "Evaluating $model"282 283 # Extract model name for output file284 model_name=$(echo $model | sed 's/\//-/g')285 286 lm_eval --model hf \287 --model_args pretrained=$model,dtype=bfloat16 \288 --tasks $TASKS \289 --num_fewshot 5 \290 --batch_size auto \291 --output_path results/$model_name.json292 293done < models.txt294```295 296**Step 3: Generate comparison table**297 298```python299import json300import pandas as pd301 302models = [303 "meta-llama-Llama-2-7b-hf",304 "meta-llama-Llama-2-13b-hf",305 "mistralai-Mistral-7B-v0.1",306 "microsoft-phi-2"307]308 309tasks = ["mmlu", "gsm8k", "hellaswag", "truthfulqa"]310 311results = []312for model in models:313 with open(f"results/{model}.json") as f:314 data = json.load(f)315 row = {"Model": model.replace("-", "/")}316 for task in tasks:317 # Get primary metric for each task318 metrics = data["results"][task]319 if "acc" in metrics:320 row[task.upper()] = f"{metrics['acc']:.3f}"321 elif "exact_match" in metrics:322 row[task.upper()] = f"{metrics['exact_match']:.3f}"323 results.append(row)324 325df = pd.DataFrame(results)326print(df.to_markdown(index=False))327```328 329Output:330```331| Model | MMLU | GSM8K | HELLASWAG | TRUTHFULQA |332|------------------------|-------|-------|-----------|------------|333| meta-llama/Llama-2-7b | 0.459 | 0.142 | 0.765 | 0.391 |334| meta-llama/Llama-2-13b | 0.549 | 0.287 | 0.801 | 0.430 |335| mistralai/Mistral-7B | 0.626 | 0.395 | 0.812 | 0.428 |336| microsoft/phi-2 | 0.560 | 0.613 | 0.682 | 0.447 |337```338 339### Workflow 4: Evaluate with vLLM (faster inference)340 341Use vLLM backend for 5-10x faster evaluation.342 343```344vLLM Evaluation:345- [ ] Step 1: Install vLLM346- [ ] Step 2: Configure vLLM backend347- [ ] Step 3: Run evaluation348```349 350**Step 1: Install vLLM**351 352```bash353pip install vllm354```355 356**Step 2: Configure vLLM backend**357 358```bash359lm_eval --model vllm \360 --model_args pretrained=meta-llama/Llama-2-7b-hf,tensor_parallel_size=1,dtype=auto,gpu_memory_utilization=0.8 \361 --tasks mmlu \362 --batch_size auto363```364 365**Step 3: Run evaluation**366 367vLLM is 5-10× faster than standard HuggingFace:368 369```bash370# Standard HF: ~2 hours for MMLU on 7B model371lm_eval --model hf \372 --model_args pretrained=meta-llama/Llama-2-7b-hf \373 --tasks mmlu \374 --batch_size 8375 376# vLLM: ~15-20 minutes for MMLU on 7B model377lm_eval --model vllm \378 --model_args pretrained=meta-llama/Llama-2-7b-hf,tensor_parallel_size=2 \379 --tasks mmlu \380 --batch_size auto381```382 383## When to use vs alternatives384 385**Use lm-evaluation-harness when:**386- Benchmarking models for academic papers387- Comparing model quality across standard tasks388- Tracking training progress389- Reporting standardized metrics (everyone uses same prompts)390- Need reproducible evaluation391 392**Use alternatives instead:**393- **HELM** (Stanford): Broader evaluation (fairness, efficiency, calibration)394- **AlpacaEval**: Instruction-following evaluation with LLM judges395- **MT-Bench**: Conversational multi-turn evaluation396- **Custom scripts**: Domain-specific evaluation397 398## Common issues399 400**Issue: Evaluation too slow**401 402Use vLLM backend:403```bash404lm_eval --model vllm \405 --model_args pretrained=model-name,tensor_parallel_size=2406```407 408Or reduce fewshot examples:409```bash410--num_fewshot 0 # Instead of 5411```412 413Or evaluate subset of MMLU:414```bash415--tasks mmlu_stem # Only STEM subjects416```417 418**Issue: Out of memory**419 420Reduce batch size:421```bash422--batch_size 1 # Or --batch_size auto423```424 425Use quantization:426```bash427--model_args pretrained=model-name,load_in_8bit=True428```429 430Enable CPU offloading:431```bash432--model_args pretrained=model-name,device_map=auto,offload_folder=offload433```434 435**Issue: Different results than reported**436 437Check fewshot count:438```bash439--num_fewshot 5 # Most papers use 5-shot440```441 442Check exact task name:443```bash444--tasks mmlu # Not mmlu_direct or mmlu_fewshot445```446 447Verify model and tokenizer match:448```bash449--model_args pretrained=model-name,tokenizer=same-model-name450```451 452**Issue: HumanEval not executing code**453 454Code-executing tasks (HumanEval, MBPP, etc.) are gated behind an explicit455confirmation flag — you must pass `--confirm_run_unsafe_code` to run them:456 457```bash458lm_eval --model hf \459 --model_args pretrained=model-name \460 --tasks humaneval \461 --confirm_run_unsafe_code # Required to run tasks that execute generated code462```463 464Without this flag lm-eval refuses to run the task rather than silently skipping465code execution.466 467## Advanced topics468 469**Benchmark descriptions**: See [references/benchmark-guide.md](references/benchmark-guide.md) for detailed description of all 60+ tasks, what they measure, and interpretation.470 471**Custom tasks**: See [references/custom-tasks.md](references/custom-tasks.md) for creating domain-specific evaluation tasks.472 473**API evaluation**: See [references/api-evaluation.md](references/api-evaluation.md) for evaluating OpenAI, Anthropic, and other API models.474 475**Multi-GPU strategies**: See [references/distributed-eval.md](references/distributed-eval.md) for data parallel and tensor parallel evaluation.476 477## Hardware requirements478 479- **GPU**: NVIDIA (CUDA 11.8+), works on CPU (very slow)480- **VRAM**:481 - 7B model: 16GB (bf16) or 8GB (8-bit)482 - 13B model: 28GB (bf16) or 14GB (8-bit)483 - 70B model: Requires multi-GPU or quantization484- **Time** (7B model, single A100):485 - HellaSwag: 10 minutes486 - GSM8K: 5 minutes487 - MMLU (full): 2 hours488 - HumanEval: 20 minutes489 490## Resources491 492- GitHub: https://github.com/EleutherAI/lm-evaluation-harness493- Docs: https://github.com/EleutherAI/lm-evaluation-harness/tree/main/docs494- Task library: 60+ tasks including MMLU, GSM8K, HumanEval, TruthfulQA, HellaSwag, ARC, WinoGrande, etc.495- Leaderboard: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard (uses this harness)496 497 498 499 Discovery context
Discovered by repository scan. No exact path reference found in the snapshot’s root AGENTS.md.