SuperAPI AI Directory

lm-evaluation-harness

A framework for few-shot evaluation of language models.

Open website

About this tool

Purpose

lm-evaluation-harness is a framework for few-shot evaluation of language models, designed to provide a unified testing platform for generative language models, covering a large number of different evaluation tasks. It is designed for standardized, reproducible evaluation of language models in academic research and engineering practice.

Main capabilities

  • Implements more than 60 standard academic benchmarks, including hundreds of subtasks and variants.
  • Supports models loaded via transformers (including quantization via GPTQModel and AutoGPTQ), GPT-NeoX, and Megatron-DeepSpeed, with a flexible, tokenizer-agnostic interface.
  • Supports fast and memory-efficient inference using vLLM.
  • Supports commercial APIs, including OpenAI and TextSynth.
  • Supports evaluation on adapters supported by the HuggingFace PEFT library (such as LoRA).
  • Supports local models and benchmarks.
  • Evaluates using publicly available prompts, ensuring reproducibility and comparability across papers.
  • Easy to support custom prompts and evaluation metrics.
  • Supports Jinja2 prompt design, making it easy to modify prompts and import prompts from Promptsource.
  • Provides more advanced configuration options, including output post-processing, answer extraction, multiple LM generations per document, configurable few-shot settings, and more.
  • Supports acceleration and new modeling libraries, including faster data-parallel HF model usage, vLLM support, HuggingFace's MPS support, and more.
  • New tasks include CoT BIG-Bench-Hard, Belebele, user-defined task groupings, and more.
  • Supports multimodal prototype features: hf-multimodal and vllm-vlm model types and the mmmu task.
  • Supports steering for HF models.
  • Supports SGLang.
  • Supports evaluation of GGUF format models (via the hf backend).
  • Supports evaluation of NVIDIA NeMo models.
  • Supports PyTorch native tensor parallelism (via DTensor).

Usage

Install the lm-eval package from the GitHub repository. The base installation provides the core evaluation framework, and model backends need to be installed separately via optional extras:

  • HuggingFace transformers models:pip install lm_eval[hf]
  • vLLM inference:pip install lm_eval[vllm]
  • API-based models (OpenAI, Anthropic, etc.):pip install lm_eval[api]
  • Multiple backends can be installed at the same time.

Use lm-eval -h to view available options, or lm-eval run -h to view evaluation options. Use lm-eval ls to list available tasks.

To evaluate a model hosted on the HuggingFace Hub (for example GPT-J-6B) on hellaswag, use the corresponding command (assuming a CUDA-compatible GPU is used). Additional parameters can be provided to the model constructor via the --model_args flag, supporting Hub's revisions feature to store partially trained checkpoints, or specifying the data type for running the model.

Supports models loaded via transformers.AutoModelForCausalLM(autoregressive, decoder-only GPT-style models) and transformers.AutoModelForSeq2SeqLM(encoder-decoder models such as T5).

The batch size can be automatically selected by setting the --batch_size flag to auto , automatically detecting the maximum batch size suitable for the device. On tasks where the longest and shortest examples differ greatly, :N can be appended to automatically recompute the maximum batch size N times.

A local path can be provided via --model_args pretrained=/path/to/model .

GGUF model evaluation: pass the directory path containing the model weights via --model_args ,gguf_file, as well as an optional tokenizer path. Important note: if a separate tokenizer is not provided, Hugging Face will attempt to reconstruct the tokenizer from the GGUF file, which may take hours or even hang indefinitely. It is recommended to provide a separate tokenizer path.

Multi-GPU evaluation: three main approaches are supported using Hugging Face's accelerate library. Data-parallel evaluation (each GPU loads a separate full copy of the model) is implemented via the accelerate launcher; when the model is too large to fit on a single GPU, run outside the accelerate launcher and pass parallelize=True; both can also be used together. For models that support PyTorch native tensor parallelism, model weights can be sharded across GPUs via tp_plan=auto .

Steering HF models: specify the model type as steered, and provide a path to a PyTorch file containing predefined steering vectors, or specify a path to a CSV file describing how to derive steering vectors from a pretrained sparsify or sae_lens model.

NVIDIA NeMo models: first install NeMo, then install the lm evaluation harness library. NeMo models can be obtained through the NVIDIA NGC Catalog or NVIDIA's Hugging Face page. Data replication or tensor/pipeline parallelism is supported.

Use cases

  • Standardized evaluation and comparison of language models in academic research.
  • Performance validation and benchmarking during model development.
  • Reproducing evaluation results from papers.
  • Submitting model evaluation results to leaderboards such as the Open LLM Leaderboard.
  • Evaluating quantized models, adapter models, multimodal models, etc.

Limitations

  • Multi-node evaluation using the hf model type is not natively supported.
  • For the GGUF model type,loglikelihood_rolling(such as perplexity tasks like wikitext) is not implemented.
  • The GGUF model type requires a llama.cpp release from December 2024 or newer; deprecated older formats are not supported.
  • When using tp_plan , the number of key-value heads in the model must be divisible by --nproc-per-node(the TP degree), and requires PyTorch >= 2.4 and a transformers version that exposes the TP plan (v4.47+).
  • tp_plan and parallelize=True are mutually exclusive.
  • Multimodal support is still a prototype feature.
  • The base installation no longer includes transformers/torch; the model backend must be installed separately.