{"id":"lm-evaluation-harness","name":"evaluating-llms-harness","summary":"60+の学術ベンチマーク(MMLU、HumanEval、GSM8K、TruthfulQA、HellaSwag)でLLMを評価します。","body":"# lm-evaluation-harness - LLM Benchmarking\n\n## Quick start\n\nlm-evaluation-harness evaluates LLMs across 60+ academic benchmarks using standardized prompts and metrics.\n\n**Installation**:\n```bash\npip install lm-eval\n```\n\n**Evaluate any HuggingFace model**:\n```bash\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf \\\n  --tasks mmlu,gsm8k,hellaswag \\\n  --device cuda:0 \\\n  --batch_size 8\n```\n\n**View available tasks**:\n```bash\nlm_eval --tasks list\n```\n\n## Common workflows\n\n### Workflow 1: Standard benchmark evaluation\n\nEvaluate model on core benchmarks (MMLU, GSM8K, HumanEval).\n\nCopy this checklist:\n\n```\nBenchmark Evaluation:\n- [ ] Step 1: Choose benchmark suite\n- [ ] Step 2: Configure model\n- [ ] Step 3: Run evaluation\n- [ ] Step 4: Analyze results\n```\n\n**Step 1: Choose benchmark suite**\n\n**Core reasoning benchmarks**:\n- **MMLU** (Massive Multitask Language Understanding) - 57 subjects, multiple choice\n- **GSM8K** - Grade school math word problems\n- **HellaSwag** - Common sense reasoning\n- **TruthfulQA** - Truthfulness and factuality\n- **ARC** (AI2 Reasoning Challenge) - Science questions\n\n**Code benchmarks**:\n- **HumanEval** - Python code generation (164 problems)\n- **MBPP** (Mostly Basic Python Problems) - Python coding\n\n**Standard suite** (recommended for model releases):\n```bash\n--tasks mmlu,gsm8k,hellaswag,truthfulqa,arc_challenge\n```\n\n**Step 2: Configure model**\n\n**HuggingFace model**:\n```bash\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf,dtype=bfloat16 \\\n  --tasks mmlu \\\n  --device cuda:0 \\\n  --batch_size auto  # Auto-detect optimal batch size\n```\n\n**Quantized model (4-bit/8-bit)**:\n```bash\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf,load_in_4bit=True \\\n  --tasks mmlu \\\n  --device cuda:0\n```\n\n**Custom checkpoint**:\n```bash\nlm_eval --model hf \\\n  --model_args pretrained=/path/to/my-model,tokenizer=/path/to/tokenizer \\\n  --tasks mmlu \\\n  --device cuda:0\n```\n\n**Step 3: Run evaluation**\n\n```bash\n# Full MMLU evaluation (57 subjects)\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf \\\n  --tasks mmlu \\\n  --num_fewshot 5 \\  # 5-shot evaluation (standard)\n  --batch_size 8 \\\n  --output_path results/ \\\n  --log_samples  # Save individual predictions\n\n# Multiple benchmarks at once\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf \\\n  --tasks mmlu,gsm8k,hellaswag,truthfulqa,arc_challenge \\\n  --num_fewshot 5 \\\n  --batch_size 8 \\\n  --output_path results/llama2-7b-eval.json\n```\n\n**Step 4: Analyze results**\n\nResults saved to `results/llama2-7b-eval.json`:\n\n```json\n{\n  \"results\": {\n    \"mmlu\": {\n      \"acc\": 0.459,\n      \"acc_stderr\": 0.004\n    },\n    \"gsm8k\": {\n      \"exact_match\": 0.142,\n      \"exact_match_stderr\": 0.006\n    },\n    \"hellaswag\": {\n      \"acc_norm\": 0.765,\n      \"acc_norm_stderr\": 0.004\n    }\n  },\n  \"config\": {\n    \"model\": \"hf\",\n    \"model_args\": \"pretrained=meta-llama/Llama-2-7b-hf\",\n    \"num_fewshot\": 5\n  }\n}\n```\n\n### Workflow 2: Track training progress\n\nEvaluate checkpoints during training.\n\n```\nTraining Progress Tracking:\n- [ ] Step 1: Set up periodic evaluation\n- [ ] Step 2: Choose quick benchmarks\n- [ ] Step 3: Automate evaluation\n- [ ] Step 4: Plot learning curves\n```\n\n**Step 1: Set up periodic evaluation**\n\nEvaluate every N training steps:\n\n```bash\n#!/bin/bash\n# eval_checkpoint.sh\n\nCHECKPOINT_DIR=$1\nSTEP=$2\n\nlm_eval --model hf \\\n  --model_args pretrained=$CHECKPOINT_DIR/checkpoint-$STEP \\\n  --tasks gsm8k,hellaswag \\\n  --num_fewshot 0 \\  # 0-shot for speed\n  --batch_size 16 \\\n  --output_path results/step-$STEP.json\n```\n\n**Step 2: Choose quick benchmarks**\n\nFast benchmarks for frequent evaluation:\n- **HellaSwag**: ~10 minutes on 1 GPU\n- **GSM8K**: ~5 minutes\n- **PIQA**: ~2 minutes\n\nAvoid for frequent eval (too slow):\n- **MMLU**: ~2 hours (57 subjects)\n- **HumanEval**: Requires code execution\n\n**Step 3: Automate evaluation**\n\nIntegrate with training script:\n\n```python\n# In training loop\nif step % eval_interval == 0:\n    model.save_pretrained(f\"checkpoints/step-{step}\")\n\n    # Run evaluation\n    os.system(f\"./eval_checkpoint.sh checkpoints step-{step}\")\n```\n\nOr use PyTorch Lightning callbacks:\n\n```python\nfrom pytorch_lightning import Callback\n\nclass EvalHarnessCallback(Callback):\n    def on_validation_epoch_end(self, trainer, pl_module):\n        step = trainer.global_step\n        checkpoint_path = f\"checkpoints/step-{step}\"\n\n        # Save checkpoint\n        trainer.save_checkpoint(checkpoint_path)\n\n        # Run lm-eval\n        os.system(f\"lm_eval --model hf --model_args pretrained={checkpoint_path} ...\")\n```\n\n**Step 4: Plot learning curves**\n\n```python\nimport json\nimport matplotlib.pyplot as plt\n\n# Load all results\nsteps = []\nmmlu_scores = []\n\nfor file in sorted(glob.glob(\"results/step-*.json\")):\n    with open(file) as f:\n        data = json.load(f)\n        step = int(file.split(\"-\")[1].split(\".\")[0])\n        steps.append(step)\n        mmlu_scores.append(data[\"results\"][\"mmlu\"][\"acc\"])\n\n# Plot\nplt.plot(steps, mmlu_scores)\nplt.xlabel(\"Training Step\")\nplt.ylabel(\"MMLU Accuracy\")\nplt.title(\"Training Progress\")\nplt.savefig(\"training_curve.png\")\n```\n\n### Workflow 3: Compare multiple models\n\nBenchmark suite for model comparison.\n\n```\nModel Comparison:\n- [ ] Step 1: Define model list\n- [ ] Step 2: Run evaluations\n- [ ] Step 3: Generate comparison table\n```\n\n**Step 1: Define model list**\n\n```bash\n# models.txt\nmeta-llama/Llama-2-7b-hf\nmeta-llama/Llama-2-13b-hf\nmistralai/Mistral-7B-v0.1\nmicrosoft/phi-2\n```\n\n**Step 2: Run evaluations**\n\n```bash\n#!/bin/bash\n# eval_all_models.sh\n\nTASKS=\"mmlu,gsm8k,hellaswag,truthfulqa\"\n\nwhile read model; do\n    echo \"Evaluating $model\"\n\n    # Extract model name for output file\n    model_name=$(echo $model | sed 's/\\//-/g')\n\n    lm_eval --model hf \\\n      --model_args pretrained=$model,dtype=bfloat16 \\\n      --tasks $TASKS \\\n      --num_fewshot 5 \\\n      --batch_size auto \\\n      --output_path results/$model_name.json\n\ndone < models.txt\n```\n\n**Step 3: Generate comparison table**\n\n```python\nimport json\nimport pandas as pd\n\nmodels = [\n    \"meta-llama-Llama-2-7b-hf\",\n    \"meta-llama-Llama-2-13b-hf\",\n    \"mistralai-Mistral-7B-v0.1\",\n    \"microsoft-phi-2\"\n]\n\ntasks = [\"mmlu\", \"gsm8k\", \"hellaswag\", \"truthfulqa\"]\n\nresults = []\nfor model in models:\n    with open(f\"results/{model}.json\") as f:\n        data = json.load(f)\n        row = {\"Model\": model.replace(\"-\", \"/\")}\n        for task in tasks:\n            # Get primary metric for each task\n            metrics = data[\"results\"][task]\n            if \"acc\" in metrics:\n                row[task.upper()] = f\"{metrics['acc']:.3f}\"\n            elif \"exact_match\" in metrics:\n                row[task.upper()] = f\"{metrics['exact_match']:.3f}\"\n        results.append(row)\n\ndf = pd.DataFrame(results)\nprint(df.to_markdown(index=False))\n```\n\nOutput:\n```\n| Model                  | MMLU  | GSM8K | HELLASWAG | TRUTHFULQA |\n|------------------------|-------|-------|-----------|------------|\n| meta-llama/Llama-2-7b  | 0.459 | 0.142 | 0.765     | 0.391      |\n| meta-llama/Llama-2-13b | 0.549 | 0.287 | 0.801     | 0.430      |\n| mistralai/Mistral-7B   | 0.626 | 0.395 | 0.812     | 0.428      |\n| microsoft/phi-2        | 0.560 | 0.613 | 0.682     | 0.447      |\n```\n\n### Workflow 4: Evaluate with vLLM (faster inference)\n\nUse vLLM backend for 5-10x faster evaluation.\n\n```\nvLLM Evaluation:\n- [ ] Step 1: Install vLLM\n- [ ] Step 2: Configure vLLM backend\n- [ ] Step 3: Run evaluation\n```\n\n**Step 1: Install vLLM**\n\n```bash\npip install vllm\n```\n\n**Step 2: Configure vLLM backend**\n\n```bash\nlm_eval --model vllm \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf,tensor_parallel_size=1,dtype=auto,gpu_memory_utilization=0.8 \\\n  --tasks mmlu \\\n  --batch_size auto\n```\n\n**Step 3: Run evaluation**\n\nvLLM is 5-10× faster than standard HuggingFace:\n\n```bash\n# Standard HF: ~2 hours for MMLU on 7B model\nlm_eval --model hf \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf \\\n  --tasks mmlu \\\n  --batch_size 8\n\n# vLLM: ~15-20 minutes for MMLU on 7B model\nlm_eval --model vllm \\\n  --model_args pretrained=meta-llama/Llama-2-7b-hf,tensor_parallel_size=2 \\\n  --tasks mmlu \\\n  --batch_size auto\n```\n\n## When to use vs alternatives\n\n**Use lm-evaluation-harness when:**\n- Benchmarking models for academic papers\n- Comparing model quality across standard tasks\n- Tracking training progress\n- Reporting standardized metrics (everyone uses same prompts)\n- Need reproducible evaluation\n\n**Use alternatives instead:**\n- **HELM** (Stanford): Broader evaluation (fairness, efficiency, calibration)\n- **AlpacaEval**: Instruction-following evaluation with LLM judges\n- **MT-Bench**: Conversational multi-turn evaluation\n- **Custom scripts**: Domain-specific evaluation\n\n## Common issues\n\n**Issue: Evaluation too slow**\n\nUse vLLM backend:\n```bash\nlm_eval --model vllm \\\n  --model_args pretrained=model-name,tensor_parallel_size=2\n```\n\nOr reduce fewshot examples:\n```bash\n--num_fewshot 0  # Instead of 5\n```\n\nOr evaluate subset of MMLU:\n```bash\n--tasks mmlu_stem  # Only STEM subjects\n```\n\n**Issue: Out of memory**\n\nReduce batch size:\n```bash\n--batch_size 1  # Or --batch_size auto\n```\n\nUse quantization:\n```bash\n--model_args pretrained=model-name,load_in_8bit=True\n```\n\nEnable CPU offloading:\n```bash\n--model_args pretrained=model-name,device_map=auto,offload_folder=offload\n```\n\n**Issue: Different results than reported**\n\nCheck fewshot count:\n```bash\n--num_fewshot 5  # Most papers use 5-shot\n```\n\nCheck exact task name:\n```bash\n--tasks mmlu  # Not mmlu_direct or mmlu_fewshot\n```\n\nVerify model and tokenizer match:\n```bash\n--model_args pretrained=model-name,tokenizer=same-model-name\n```\n\n**Issue: HumanEval not executing code**\n\nInstall execution dependencies:\n```bash\npip install human-eval\n```\n\nEnable code execution:\n```bash\nlm_eval --model hf \\\n  --model_args pretrained=model-name \\\n  --tasks humaneval \\\n  --allow_code_execution  # Required for HumanEval\n```\n\n## Advanced topics\n\n**Benchmark descriptions**: See [references/benchmark-guide.md](references/benchmark-guide.md) for detailed description of all 60+ tasks, what they measure, and interpretation.\n\n**Custom tasks**: See [references/custom-tasks.md](references/custom-tasks.md) for creating domain-specific evaluation tasks.\n\n**API evaluation**: See [references/api-evaluation.md](references/api-evaluation.md) for evaluating OpenAI, Anthropic, and other API models.\n\n**Multi-GPU strategies**: See [references/distributed-eval.md](references/distributed-eval.md) for data parallel and tensor parallel evaluation.\n\n## Hardware requirements\n\n- **GPU**: NVIDIA (CUDA 11.8+), works on CPU (very slow)\n- **VRAM**:\n  - 7B model: 16GB (bf16) or 8GB (8-bit)\n  - 13B model: 28GB (bf16) or 14GB (8-bit)\n  - 70B model: Requires multi-GPU or quantization\n- **Time** (7B model, single A100):\n  - HellaSwag: 10 minutes\n  - GSM8K: 5 minutes\n  - MMLU (full): 2 hours\n  - HumanEval: 20 minutes\n\n## Resources\n\n- GitHub: https://github.com/EleutherAI/lm-evaluation-harness\n- Docs: https://github.com/EleutherAI/lm-evaluation-harness/tree/main/docs\n- Task library: 60+ tasks including MMLU, GSM8K, HumanEval, TruthfulQA, HellaSwag, ARC, WinoGrande, etc.\n- Leaderboard: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard (uses this harness)","author":"@Orchestra-Research","ownerProfile":null,"authorContacts":null,"sourceUrl":"https://github.com/Orchestra-Research/AI-Research-SKILLs/tree/main/11-evaluation/lm-evaluation-harness","license":"MIT","category":"writing","lang":"en","tokens":3316,"stars":0,"calls30d":1,"claimed":false,"visibility":"public","origin":"crawler","version":"0.1.0","createdAt":"2026-08-22","updatedAt":"2026-08-22","files":[{"path":"references/api-evaluation.md","size":11114,"sha256":"433372d84b8bbd6c28e5b971c1aae7c5d2d032aae9ff23dd7d7a47a51277dc78"},{"path":"references/benchmark-guide.md","size":10769,"sha256":"6f3e6daf78cee21453cebc1c4688ee126fbf0d4566782496dd5841dd669ae295"},{"path":"references/custom-tasks.md","size":13125,"sha256":"c6b5591c77c16570b43fa5f497405a65f35ef73d1702a3871cc0c8a257c76aeb"},{"path":"references/distributed-eval.md","size":11426,"sha256":"3ddc4551f25ce0d3cb09f971f27191331fb65b5b4c882efd4a9bde7bdfb82353"}],"requires":{"mcp":[],"tools":[]},"safety":{"flags":[{"code":"code.eval","kind":"dangerous-code","where":"SKILL.md:174","excerpt":"eval (","message":"evaluates code at runtime","severity":"warn"}],"scannedAt":"2026-08-22","hasScripts":false,"networkEndpoints":["api.anthropic.com","api.example.com","api.openai.com","docs.nvidia.com","docs.vllm.ai","huggingface.co","platform.openai.com"]}}