lm-evaluation-harness
lm-evaluation-harness 是一个专为大语言模型设计的开源评估框架,旨在通过统一的标准对模型进行少样本(few-shot)能力测试。它主要解决了当前大模型评估中基准分散、环境配置复杂以及结果难以复现的痛点,让研究人员能够在一个平台上轻松对比不同模型在数十种学术任务上的表现。
这款工具非常适合 AI 研究人员、算法工程师以及希望严谨测试模型性能的开发团队使用。无论是验证新训练的模型,还是复现论文中的实验数据,lm-evaluation-harness 都能提供可靠的支持。
其技术亮点十分突出:内置了超过 60 种标准学术基准及数百个子任务;支持多种主流推理后端,包括 Hugging Face Transformers(含量化)、vLLM、SGLang 等,兼顾了灵活性与推理速度;近期更新还引入了基于 YAML 的配置化管理、思维链(CoT)痕迹剥离功能,并初步支持多模态任务评估。此外,它还集成了最新的 Open LLM Leaderboard 任务集,帮助用户紧跟行业评测标准。作为一个社区驱动的项目,lm-evaluation-harness 以模块化设计和丰富的文档,成为了大模型领域不可或缺的“标尺”。
使用场景
某 AI 初创团队在发布自研的 7B 参数大模型前,急需验证其在逻辑推理和常识问答等核心能力上是否达到行业基准,以便向投资人展示性能报告。
没有 lm-evaluation-harness 时
- 评估标准混乱:团队需手动从 Hugging Face 下载 MMLU、GSM8K 等数据集,各自编写脚本处理格式,导致不同成员跑出的分数因预处理差异而无法横向对比。
- 适配成本高昂:每切换一种推理后端(如从 Transformers 切换到 vLLM 以加速测试),都要重写大量数据加载和推理代码,耗时数天且容易引入 Bug。
- 结果不可复现:缺乏统一的少样本(Few-shot)提示词模板和管理机制,实验记录杂乱,难以精确复现某次特定的评测配置供审计或论文发表。
- 多维任务割裂:想要同时评估数学、代码和多语言能力时,需要维护多套独立的测试流水线,无法一次性生成综合性能雷达图。
使用 lm-evaluation-harness 后
- 基准统一规范:直接调用内置的 60+ 学术基准任务(如 Open LLM Leaderboard 系列),一键拉取标准化数据,确保评测结果与社区权威榜单完全可比。
- 后端切换无缝:利用其灵活的接口,仅通过修改命令行参数(如
--model vllm)即可在分钟级内切换推理引擎,无需改动任何业务逻辑代码。 - 配置可追溯:通过 YAML 配置文件统一管理提示词模板、少样本数量及后处理规则,轻松实现实验版本的精确复现和团队间共享。
- 全景效率提升:单条命令即可并行执行多个任务组,自动聚合生成包含准确率、困惑度等多维指标的详细报告,大幅缩短从训练到发布的验证周期。
lm-evaluation-harness 将原本碎片化、高成本的模型验证工作转化为标准化、自动化的流水线,成为大模型迭代中不可或缺的“标尺”。
运行环境要求
- Linux
- macOS
- 非必需(支持 CPU/API),若使用本地模型推荐 NVIDIA GPU(支持 CUDA)
- macOS 支持 MPS
- 显存大小取决于模型规模(支持多卡并行及模型切分)
未说明(取决于模型大小,大模型需大量内存或启用 offload)

快速开始
语言模型评估框架
最新消息 📣
- [2025/12] CLI 重构:新增子命令(
run、ls、validate),并通过--config参数支持 YAML 配置文件。详情请参阅 CLI 参考文档 和 配置指南。 - [2025/12] 安装更轻量:基础包不再包含
transformers和torch。模型后端需单独安装,例如:pip install lm_eval[hf]、lm_eval[vllm]等。 - [2025/07] 为
hf(token/str)、vllm和sglang(str)添加了think_end_token参数,用于去除支持该功能的模型中的思维链推理痕迹。 - [2025/03] 新增对 Hugging Face 模型的引导支持!
- [2025/02] 新增对 SGLang 的支持!
- [2024/09] 我们正在开发允许用户使用 LM Evaluation Harness 处理文本与图像多模态输入、文本输出任务的功能,并已作为原型特性新增了
hf-multimodal和vllm-vlm模型类型以及mmmu任务。欢迎用户试用这一正在进行中的功能并进行压力测试;同时建议大家查看lmms-eval,这是一个从 lm-evaluation-harness 分支出来的优秀项目,提供了更广泛的多模态任务、模型和功能。 - [2024/07] 更新并重构了 API 模型 支持,引入了批量和异步请求的支持,使自定义和按个人需求使用变得更加简便。若要运行 Llama 405B,我们建议使用 VLLM 的 OpenAI 兼容 API 托管模型,并使用
local-completions模型类型进行评估。 - [2024/07] 新增了开放 LLM 排行榜任务!您可以在 leaderboard 任务组中找到它们。
公告
lm-evaluation-harness 新版本 v0.4.0 已发布!
本次更新与新增功能包括:
- 新增开放 LLM 排行榜任务!您可在 leaderboard 任务组中找到它们。
- 内部重构
- 基于配置的任务创建与配置
- 更易导入和共享外部定义的任务配置 YAML 文件
- 支持 Jinja2 提示词设计,可轻松修改提示词,并从 Promptsource 导入提示词
- 更高级的配置选项,包括输出后处理、答案提取、每篇文档生成多个语言模型结果、可配置的少样本设置等
- 性能提升及新增支持的建模库,包括更快的数据并行化 Hugging Face 模型使用、vLLM 支持、Hugging Face 的 MPS 支持等
- 日志记录与可用性改进
- 新增任务,如 CoT BIG-Bench-Hard、Belebele、用户自定义任务分组等
更多详细信息请参阅 docs/ 目录下的更新文档。
开发将继续在 main 分支上进行,我们鼓励您通过 GitHub 上的 Issues 或 PR,或在 EleutherAI Discord 中,向我们反馈所需功能、改进建议或提出疑问!
概述
本项目提供了一个统一的框架,用于在大量不同的评估任务上测试生成式语言模型。
特点:
- 超过 60 个面向 LLM 的标准学术基准测试,包含数百个子任务和变体。
- 支持通过 transformers 加载的模型(包括通过 GPTQModel 和 AutoGPTQ 进行量化)、GPT-NeoX 以及 Megatron-DeepSpeed 加载的模型,并提供灵活的、与分词器无关的接口。
- 支持使用 vLLM 进行快速且内存高效的推理。
- 支持商业 API,包括 OpenAI 和 TextSynth。
- 支持对 Hugging Face 的 PEFT 库 中支持的适配器(如 LoRA)进行评估。
- 支持本地模型和基准测试。
- 使用公开可用的提示词进行评估,确保论文之间的可重复性和可比性。
- 易于支持自定义提示词和评估指标。
Language Model Evaluation Harness 是 🤗 Hugging Face 广受欢迎的 开放 LLM 排行榜 的后端,已被数百篇论文引用(见 Google 学术搜索:链接),并被 NVIDIA、Cohere、BigScience、BigCode、Nous Research 和 Mosaic ML 等数十家机构内部使用。
安装
从 GitHub 仓库安装 lm-eval 包,请执行以下命令:
git clone --depth 1 https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e .
安装模型后端
基础安装仅提供核心评估框架。模型后端需单独安装,可通过可选依赖项实现:
对于 Hugging Face Transformers 模型:
pip install "lm_eval[hf]"
对于 vLLM 推理:
pip install "lm_eval[vllm]"
对于基于 API 的模型(OpenAI、Anthropic 等):
pip install "lm_eval[api]"
也可同时安装多个后端:
pip install "lm_eval[hf,vllm,api]"
本文档末尾提供了所有可选依赖项的详细表格。
基本用法
文档
| 指南 | 描述 |
|---|---|
| CLI 参考文档 | 命令行参数和子命令 |
| 配置指南 | YAML 配置文件格式及示例 |
| Python API 指南 | 使用 simple_evaluate() 进行程序化调用 |
| 任务指南 | 可用任务及任务配置 |
使用 lm-eval -h 查看可用选项,或使用 lm-eval run -h 查看评估选项。
列出可用任务:
lm-eval ls tasks
Hugging Face transformers
[!重要] 要使用 HuggingFace 后端,首先安装:
pip install "lm_eval[hf]"
要在 hellaswag 数据集上评估托管在 HuggingFace Hub 上的模型(例如 GPT-J-6B),可以使用以下命令(假设您正在使用兼容 CUDA 的 GPU):
lm_eval --model hf \
--model_args pretrained=EleutherAI/gpt-j-6B \
--tasks hellaswag \
--device cuda:0 \
--batch_size 8
可以使用 --model_args 标志向模型构造函数传递额外参数。最值得注意的是,这支持在 Hub 上使用 revisions 功能来存储部分训练好的检查点,或者指定运行模型的数据类型:
lm_eval --model hf \
--model_args pretrained=EleutherAI/pythia-160m,revision=step100000,dtype="float" \
--tasks lambada_openai,hellaswag \
--device cuda:0 \
--batch_size 8
HuggingFace 支持通过 transformers.AutoModelForCausalLM(自回归、仅解码器的 GPT 风格模型)和 transformers.AutoModelForSeq2SeqLM(如 T5 等编码器-解码器模型)加载的模型。
可以通过将 --batch_size 标志设置为 auto 来自动选择批次大小。这将自动检测适合您设备的最大批次大小。在最长和最短样本之间差异较大的任务中,定期重新计算最大批次大小有助于进一步提高速度。为此,可以在上述标志后附加 :N,以自动重新计算最大批次大小 N 次。例如,要重新计算批次大小 4 次,命令如下:
lm_eval --model hf \
--model_args pretrained=EleutherAI/pythia-160m,revision=step100000,dtype="float" \
--tasks lambada_openai,hellaswag \
--device cuda:0 \
--batch_size auto:4
[!注释] 就像您可以为
transformers.AutoModel提供本地路径一样,也可以通过--model_args pretrained=/path/to/model为lm_eval提供本地路径。
评估 GGUF 模型
lm-eval 支持使用 Hugging Face (hf) 后端评估 GGUF 格式的模型。这使您可以使用与 transformers、AutoModel 和 llama.cpp 转换兼容的量化模型。
要评估 GGUF 模型,请使用 --model_args 标志传递包含模型权重的目录路径、gguf_file,以及可选的单独 tokenizer 路径。
🚨 重要提示:
如果未提供单独的分词器,HuggingFace 将尝试从 GGUF 文件中重建分词器——这可能需要 数小时,甚至无限期挂起。提供单独的分词器可以避免此问题,并将分词器加载时间从数小时缩短至几秒钟。
✅ 推荐用法:
lm_eval --model hf \
--model_args pretrained=/path/to/gguf_folder,gguf_file=model-name.gguf,tokenizer=/path/to/tokenizer \
--tasks hellaswag \
--device cuda:0 \
--batch_size 8
[!提示] 确保分词器路径指向有效的 HuggingFace 分词器目录(例如包含 tokenizer_config.json、vocab.json 等文件)。
使用 Hugging Face accelerate 进行多 GPU 评估
我们支持三种主要方式来使用 HuggingFace 的 accelerate 🚀 库进行多 GPU 评估。
要执行 数据并行评估(每个 GPU 加载模型的 独立完整副本),我们可以利用 accelerate 启动器,如下所示:
accelerate launch -m lm_eval --model hf \
--tasks lambada_openai,arc_easy \
--batch_size 16
(或通过 accelerate launch --no-python lm_eval)。
对于模型可以容纳在单个 GPU 上的情况,这种方式可以让您在 K 个 GPU 上以比单个 GPU 快 K 倍的速度进行评估。
警告:此设置不适用于 FSDP 模型分片,因此在 accelerate config 中必须禁用 FSDP,或使用 NO_SHARD FSDP 选项。
使用 accelerate 进行多 GPU 评估的第二种方式是当您的模型 太大而无法容纳在单个 GPU 上时。
在这种情况下,应在 accelerate 启动器之外运行该库,但需将 parallelize=True 传递给 --model_args,如下所示:
lm_eval --model hf \
--tasks lambada_openai,arc_easy \
--model_args parallelize=True \
--batch_size 16
这意味着您的模型权重将被拆分到所有可用的 GPU 上。
对于更高级的用户或更大的模型,当 parallelize=True 时,还可以使用以下参数:
device_map_option:如何在可用 GPU 之间拆分模型权重,默认为 “auto”。max_memory_per_gpu:每块 GPU 在加载模型时使用的最大显存。max_cpu_memory:将模型权重卸载到 RAM 时使用的最大 CPU 内存量。offload_folder:如果需要,模型权重将被卸载到磁盘的文件夹。
第三种选择是同时使用前两种方法。这将使您能够同时利用数据并行性和模型分片,尤其适用于太大而无法容纳在单个 GPU 上的模型。
accelerate launch --multi_gpu --num_processes {nb_of_copies_of_your_model} \
-m lm_eval --model hf \
--tasks lambada_openai,arc_easy \
--model_args parallelize=True \
--batch_size 16
要了解有关模型并行性及其如何与 accelerate 库一起使用的更多信息,请参阅 accelerate 文档。
警告:我们目前不原生支持使用 hf 模型类型的多节点评估!请参考 我们的 GPT-NeoX 库集成,其中包含一个自定义多机评估脚本的示例。
注意:我们目前不原生支持多节点评估,建议使用外部托管的服务器来处理推理请求,或根据您的分布式框架创建自定义集成 如同 GPT-NeoX 库所做的那样。
带有引导向量的 Hugging Face transformers 模型
要使用引导向量评估 Hugging Face transformers 模型,需将模型类型指定为 steered,并提供包含预定义引导向量的 PyTorch 文件路径,或指定如何从预训练的 sparsify 或 sae_lens 模型中提取引导向量的 CSV 文件路径(此方法需要安装相应的可选依赖项)。
指定预定义的引导向量:
import torch
steer_config = {
"layers.3": {
"steering_vector": torch.randn(1, 768),
"bias": torch.randn(1, 768),
"steering_coefficient": 1,
"action": "add"
},
}
torch.save(steer_config, "steer_config.pt")
指定派生的引导向量:
import pandas as pd
pd.DataFrame({
"loader": ["sparsify"],
"action": ["add"],
"sparse_model": ["EleutherAI/sae-pythia-70m-32k"],
"hookpoint": ["layers.3"],
"feature_index": [30],
"steering_coefficient": [10.0],
}).to_csv("steer_config.csv", index=False)
运行应用引导向量的评估工具:
lm_eval --model steered \
--model_args pretrained=EleutherAI/pythia-160m,steer_path=steer_config.pt \
--tasks lambada_openai,hellaswag \
--device cuda:0 \
--batch_size 8
NVIDIA nemo 模型
NVIDIA NeMo Framework 是一个生成式 AI 框架,专为从事语言模型研究的科研人员和 PyTorch 开发者设计。
要评估 nemo 模型,首先按照文档安装 NeMo。我们强烈建议使用 NVIDIA 的 PyTorch 或 NeMo 容器,尤其是在安装 Apex 或其他依赖项时遇到问题的情况下(请参阅最新发布的容器)。此外,请按照安装部分中的说明安装 lm 评估工具库。
Nemo 模型可以通过 NVIDIA NGC Catalog 或 NVIDIA 的 Hugging Face 页面获取。在 NVIDIA NeMo Framework 中,提供了用于将流行模型如 llama、falcon、mixtral 或 mpt 的 hf 检查点转换为 nemo 格式的脚本。
在单个 GPU 上运行 nemo 模型:
lm_eval --model nemo_lm \
--model_args path=<nemo_model_path> \
--tasks hellaswag \
--batch_size 32
建议先解压 nemo 模型,以避免在 Docker 容器内进行解压操作导致磁盘空间不足。可以执行以下命令:
mkdir MY_MODEL
tar -xvf MY_MODEL.nemo -c MY_MODEL
使用 NVIDIA nemo 模型进行多 GPU 评估
默认情况下,仅使用一个 GPU。但我们支持在单节点上进行数据复制或张量/流水线并行计算的评估。
- 要启用数据复制,需将
model_args中的devices设置为要运行的数据副本数量。例如,在 8 个 GPU 上运行 8 个数据副本的命令如下:
torchrun --nproc-per-node=8 --no-python lm_eval \
--model nemo_lm \
--model_args path=<nemo_model_path>,devices=8 \
--tasks hellaswag \
--batch_size 32
- 要启用张量和/或流水线并行计算,需设置
model_args中的tensor_model_parallel_size和/或pipeline_model_parallel_size。此外,还需将devices设置为tensor_model_parallel_size和/或pipeline_model_parallel_size的乘积。例如,在 4 个 GPU 的节点上使用张量并行度 2 和流水线并行度 2 的命令如下:
torchrun --nproc-per-node=4 --no-python lm_eval \
--model nemo_lm \
--model_args path=<nemo_model_path>,devices=4,tensor_model_parallel_size=2,pipeline_model_parallel_size=2 \
--tasks hellaswag \
--batch_size 32
请注意,建议用 torchrun --nproc-per-node=<设备数量> --no-python 替代 python 命令,以便更高效地将模型加载到各个 GPU 中。这对于加载到多个 GPU 上的大规模检查点尤为重要。
目前尚不支持:多节点评估以及数据复制与张量或流水线并行计算的组合。
Megatron-LM 模型
Megatron-LM 是 NVIDIA 的大规模 Transformer 训练框架。该后端允许直接评估 Megatron-LM 检查点,无需转换。
要求:
- 必须安装 Megatron-LM,或通过
MEGATRON_PATH环境变量访问 - 支持 CUDA 的 PyTorch
设置:
Simplified Chinese:
# 设置指向 Megatron-LM 安装路径的环境变量
export MEGATRON_PATH=/path/to/Megatron-LM
基本用法(单 GPU):
lm_eval --model megatron_lm \
--model_args load=/path/to/checkpoint,tokenizer_type=HuggingFaceTokenizer,tokenizer_model=/path/to/tokenizer \
--tasks hellaswag \
--batch_size 1
支持的检查点格式:
- 标准 Megatron 检查点 (
model_optim_rng.pt) - 分布式检查点(
.distcp格式,自动检测)
并行模式
Megatron-LM 后端支持以下并行模式:
| 模式 | 配置 | 描述 |
|---|---|---|
| 单 GPU | devices=1(默认) |
标准单 GPU 评估 |
| 数据并行 | devices>1, TP=1 |
每个 GPU 拥有完整的模型副本,数据被分发 |
| 张量并行 | TP == devices |
模型层在 GPU 之间拆分 |
| 专家并行 | EP == devices, TP=1 |
对于 MoE 模型,专家分布在各个 GPU 上 |
[!注]
- 流水线并行(PP > 1)目前不支持。
- 专家并行(EP)不能与张量并行(TP)结合使用。
数据并行(4 个 GPU,每个 GPU 拥有完整模型副本):
torchrun --nproc-per-node=4 -m lm_eval --model megatron_lm \
--model_args load=/path/to/checkpoint,tokenizer_model=/path/to/tokenizer,devices=4 \
--tasks hellaswag
张量并行(TP=2):
torchrun --nproc-per-node=2 -m lm_eval --model megatron_lm \
--model_args load=/path/to/checkpoint,tokenizer_model=/path/to/tokenizer,devices=2,tensor_model_parallel_size=2 \
--tasks hellaswag
MoE 模型的专家并行(EP=4):
torchrun --nproc-per-node=4 -m lm_eval --model megatron_lm \
--model_args load=/path/to/moe_checkpoint,tokenizer_model=/path/to/tokenizer,devices=4,expert_model_parallel_size=4 \
--tasks hellaswag
使用 extra_args 添加额外的 Megatron 选项:
lm_eval --model megatron_lm \
--model_args load=/path/to/checkpoint,tokenizer_model=/path/to/tokenizer,extra_args="--no-rope-fusion --trust-remote-code" \
--tasks hellaswag
[!注] 默认启用
--use-checkpoint-args标志,该标志会从检查点中加载模型架构参数。对于通过 Megatron-Bridge 转换的检查点,这通常包括所有必要的模型配置。
使用 OpenVINO 模型的多 GPU 评估
OpenVINO 模型支持在评估过程中进行流水线并行。
要启用流水线并行,需设置 model_args 中的 pipeline_parallel 参数。此外,还需将 device 设置为 HETERO:<GPU 索引1>,<GPU 索引2> 的形式,例如 HETERO:GPU.1,GPU.0。例如,使用 2 级流水线并行的命令如下:
lm_eval --model openvino \
--tasks wikitext \
--model_args pretrained=<path_to_ov_model>,pipeline_parallel=True \
--device HETERO:GPU.1,GPU.0
使用 vLLM 进行张量 + 数据并行及优化推理
我们还支持 vLLM,以加快对受支持的模型类型的推理速度,尤其是在将模型拆分到多个 GPU 上时更为显著。无论是单 GPU 还是多 GPU——张量并行、数据并行,或两者的组合——都可以进行推理,例如:
lm_eval --model vllm \
--model_args pretrained={model_name},tensor_parallel_size={GPUs_per_model},dtype=auto,gpu_memory_utilization=0.8,data_parallel_size={model_replicas} \
--tasks lambada_openai \
--batch_size auto
要使用 vLLM,请运行 pip install "lm_eval[vllm]"。有关 vLLM 支持的完整配置列表,请参考我们的 vLLM 集成文档以及 vLLM 的官方文档。
vLLM 的输出有时会与 Huggingface 不同。我们将 Huggingface 视为参考实现,并提供了一个脚本,用于对比 vLLM 结果与 Huggingface 的一致性。
[!提示] 为了获得最佳性能,我们建议尽可能对 vLLM 使用
--batch_size auto,以充分利用其连续批处理功能!
[!提示] 通过模型参数向 vLLM 传递
max_model_len=4096或其他合理的默认值,可能会提升速度或避免在尝试使用自动批大小时出现内存不足的问题,例如对于 Mistral-7B-v0.1,默认最大长度为 32k。
使用 SGLang 进行张量 + 数据并行及快速离线批处理推理
我们支持 SGLang,用于高效的离线批处理推理。其 Fast Backend Runtime 通过优化的内存管理和并行处理技术,提供了卓越的性能。关键特性包括张量并行、连续批处理以及对多种量化方法(FP8/INT4/AWQ/GPTQ)的支持。
要将 SGLang 作为评估后端,请务必提前安装,具体步骤请参阅 SGLang 文档这里。
[!提示] 由于
Flashinfer——一个快速注意力核库——的安装方式,我们在 pyproject.toml 中并未包含 SGLang 的依赖项。请注意,Flashinfer对torch版本也有一些要求。
SGLang 的服务器参数与其他后端略有不同,更多信息请参阅这里。以下是使用示例:
lm_eval --model sglang \
--model_args pretrained={model_name},dp_size={data_parallel_size},tp_size={tensor_parallel_size},dtype=auto \
--tasks gsm8k_cot \
--batch_size auto
[!提示] 当遇到内存不足(OOM)错误时(尤其是选择题任务),可以尝试以下解决方案:
- 使用手动
batch_size,而不是auto。- 通过调整
mem_fraction_static来降低 KV 缓存池的内存使用量——例如,在模型参数中添加--model_args pretrained=...,mem_fraction_static=0.7。- 增加张量并行规模
tp_size(如果使用多个 GPU)。
Windows ML
我们支持在 Windows 平台上使用 Windows ML 进行硬件加速推理。这使得模型可以在 CPU、GPU 以及 NPU(神经处理单元) 设备上进行评估。
什么是 Windows ML? https://learn.microsoft.com/en-us/windows/ai/new-windows-ml/overview
要使用 Windows ML,请安装所需的依赖项:
pip install wasdk-Microsoft.Windows.AI.MachineLearning[all] wasdk-Microsoft.Windows.ApplicationModel.DynamicDependency.Bootstrap onnxruntime-windowsml onnxruntime-genai-winml
在 Windows 上使用 NPU/GPU/CPU 评估 ONNX Runtime GenAI LLM:
lm_eval --model winml \
--model_args pretrained=/path/to/onnx/model \
--tasks mmlu \
--batch_size 1
[!注] Windows ML 后端仅适用于 ONNX Runtime GenAI 模型格式。针对
transformers.js的模型将无法运行。您可以通过在模型文件夹中查找genai_config.json文件来验证这一点。
[!注] 要在目标设备上运行 ONNX Runtime GenAI 模型,您必须将原始模型转换为该厂商和设备类型的格式。转换后的模型在其他厂商或设备类型上可能无法正常工作或效果不佳。如需了解更多关于模型转换的信息,请访问 Microsoft AI 工具包。
模型 API 和推理服务器
[!重要] 若要使用基于 API 的模型,首先需要安装:
pip install "lm_eval[api]"
我们的库还支持通过多个商业 API 提供的服务模型的评估,并计划实现对最常用的高性能本地/自托管推理服务器的支持。
要调用托管模型,可以使用以下命令:
export OPENAI_API_KEY=YOUR_KEY_HERE
lm_eval --model openai-completions \
--model_args model=davinci-002 \
--tasks lambada_openai,hellaswag
我们还支持使用您自己的本地推理服务器,这些服务器能够镜像 OpenAI Completions 和 ChatCompletions API。
lm_eval --model local-completions --tasks gsm8k --model_args model=facebook/opt-125m,base_url=http://{yourip}:8000/v1/completions,num_concurrent=1,max_retries=3,tokenized_requests=False,batch_size=16
请注意,对于外部托管的模型,与本地模型位置相关的配置参数(如 --device)不应使用,且不会生效。就像您可以使用 --model_args 向本地模型的构造函数传递任意参数一样,也可以使用它向托管模型的 API 传递任意参数。有关他们支持哪些参数的信息,请参阅托管服务的文档。
| API 或推理服务器 | 已实现? | --model <xxx> 名称 |
支持的模型: | 请求类型: |
|---|---|---|---|---|
| OpenAI Completions | √ | openai-completions, local-completions |
所有 OpenAI Completions API 模型 | generate_until, loglikelihood, loglikelihood_rolling |
| OpenAI ChatCompletions | √ | openai-chat-completions, local-chat-completions |
所有 ChatCompletions API 模型 | generate_until(无 logprobs) |
| Anthropic | √ | anthropic |
支持的 Anthropic 引擎 | generate_until(无 logprobs) |
| Anthropic Chat | √ | anthropic-chat, anthropic-chat-completions |
支持的 Anthropic 引擎 | generate_until(无 logprobs) |
| Textsynth | √ | textsynth |
所有支持的引擎 | generate_until, loglikelihood, loglikelihood_rolling |
| Cohere | :hourglass: - 受 Cohere API 问题阻塞 | 无 | 所有 cohere.generate() 引擎 |
generate_until, loglikelihood, loglikelihood_rolling |
| Llama.cpp(通过 llama-cpp-python) | √ | gguf, ggml |
Llama.cpp 支持的所有模型 | generate_until, loglikelihood,(困惑度评估尚未实现) |
| vLLM | √ | vllm |
大多数 HF 因果语言模型 | generate_until, loglikelihood, loglikelihood_rolling |
| Mamba | √ | mamba_ssm |
通过 mamba_ssm 包支持的 Mamba 架构语言模型 |
generate_until, loglikelihood, loglikelihood_rolling |
| Huggingface Optimum(因果 LM) | √ | openvino |
任何使用 Huggingface Optimum 转换为 OpenVINO™ 中间表示 (IR) 格式的解码器式 AutoModelForCausalLM | generate_until, loglikelihood, loglikelihood_rolling |
| Huggingface Optimum-intel IPEX(因果 LM) | √ | ipex |
任何解码器式 AutoModelForCausalLM | generate_until, loglikelihood, loglikelihood_rolling |
| Huggingface Optimum-habana(因果 LM) | √ | habana |
任何解码器式 AutoModelForCausalLM | generate_until, loglikelihood, loglikelihood_rolling |
| Neuron 通过 AWS Inf2(因果 LM) | √ | neuronx |
任何支持在 huggingface-ami image for inferentia2 上运行的解码器式 AutoModelForCausalLM | generate_until, loglikelihood, loglikelihood_rolling |
| NVIDIA NeMo | √ | nemo_lm |
所有支持的模型 | generate_until, loglikelihood, loglikelihood_rolling |
| NVIDIA Megatron-LM | √ | megatron_lm |
Megatron-LM GPT 模型(标准和分布式检查点) | generate_until, loglikelihood, loglikelihood_rolling |
| Watsonx.ai | √ | watsonx_llm |
支持的 Watsonx.ai 引擎 | generate_until loglikelihood |
| Windows ML | √ | winml |
GenAI 格式的 ONNX 模型 | generate_until, loglikelihood, loglikelihood_rolling |
| 您本地的推理服务器! | √ | local-completions 或 local-chat-completions |
支持与 OpenAI API 兼容的服务器,并可轻松自定义其他 API。 | generate_until, loglikelihood, loglikelihood_rolling |
Models which do not supply logits or logprobs can be used with tasks of type generate_until only, while local models, or APIs that supply logprobs/logits of their prompts, can be run on all task types: generate_until, loglikelihood, loglikelihood_rolling, and multiple_choice.
For more information on the different task output_types and model request types, see our documentation.
[!Note] For best performance with closed chat model APIs such as Anthropic Claude 3 and GPT-4, we recommend carefully looking at a few sample outputs using
--limit 10first to confirm answer extraction and scoring on generative tasks is performing as expected. providingsystem="<some system prompt here>"within--model_argsfor anthropic-chat-completions, to instruct the model what format to respond in, may be useful.
Other Frameworks
A number of other libraries contain scripts for calling the eval harness through their library. These include GPT-NeoX, Megatron-DeepSpeed, and mesh-transformer-jax.
To create your own custom integration you can follow instructions from this tutorial.
Additional Features
[!Note] For tasks unsuitable for direct evaluation — either due risks associated with executing untrusted code or complexities in the evaluation process — the
--predict_onlyflag is available to obtain decoded generations for post-hoc evaluation.
If you have a Metal compatible Mac, you can run the eval harness using the MPS back-end by replacing --device cuda:0 with --device mps (requires PyTorch version 2.1 or higher). Note that the PyTorch MPS backend is still in early stages of development, so correctness issues or unsupported operations may exist. If you observe oddities in model performance on the MPS back-end, we recommend first checking that a forward pass of your model on --device cpu and --device mps match.
[!Note] You can inspect what the LM inputs look like by running the following command:
python write_out.py \ --tasks <task1,task2,...> \ --num_fewshot 5 \ --num_examples 10 \ --output_base_path /path/to/output/folderThis will write out one text file for each task.
To verify the data integrity of the tasks you're performing in addition to running the tasks themselves, you can use the --check_integrity flag:
lm_eval --model openai \
--model_args engine=davinci-002 \
--tasks lambada_openai,hellaswag \
--check_integrity
Advanced Usage Tips
For models loaded with the HuggingFace transformers library, any arguments provided via --model_args get passed to the relevant constructor directly. This means that anything you can do with AutoModel can be done with our library. For example, you can pass a local path via pretrained= or use models finetuned with PEFT by taking the call you would run to evaluate the base model and add ,peft=PATH to the model_args argument:
lm_eval --model hf \
--model_args pretrained=EleutherAI/gpt-j-6b,parallelize=True,load_in_4bit=True,peft=nomic-ai/gpt4all-j-lora \
--tasks openbookqa,arc_easy,winogrande,hellaswag,arc_challenge,piqa,boolq \
--device cuda:0
Models provided as delta weights can be easily loaded using the Hugging Face transformers library. Within --model_args, set the delta argument to specify the delta weights, and use the pretrained argument to designate the relative base model to which they will be applied:
lm_eval --model hf \
--model_args pretrained=Ejafa/llama_7B,delta=lmsys/vicuna-7b-delta-v1.1 \
--tasks hellaswag
GPTQ quantized models can be loaded using GPTQModel (faster) or AutoGPTQ
GPTQModel: add ,gptqmodel=True to model_args
lm_eval --model hf \
--model_args pretrained=model-name-or-path,gptqmodel=True \
--tasks hellaswag
AutoGPTQ: add ,autogptq=True to model_args:
lm_eval --model hf \
--model_args pretrained=model-name-or-path,autogptq=model.safetensors,gptq_use_triton=True \
--tasks hellaswag
We support wildcards in task names, for example you can run all of the machine-translated lambada tasks via --task lambada_openai_mt_*.
Saving & Caching Results
To save evaluation results provide an --output_path. We also support logging model responses with the --log_samples flag for post-hoc analysis.
[!TIP] Use
--use_cache <DIR>to cache evaluation results and skip previously evaluated samples when resuming runs of the same (model, task) pairs. Note that caching is rank-dependent, so restart with the same GPU count if interrupted. You can also use --cache_requests to save dataset preprocessing steps for faster evaluation resumption.
To push results and samples to the Hugging Face Hub, first ensure an access token with write access is set in the HF_TOKEN environment variable. Then, use the --hf_hub_log_args flag to specify the organization, repository name, repository visibility, and whether to push results and samples to the Hub - example dataset on the HF Hub. For instance:
lm_eval --model hf \
--model_args pretrained=model-name-or-path,autogptq=model.safetensors,gptq_use_triton=True \
--tasks hellaswag \
--log_samples \
--output_path results \
--hf_hub_log_args hub_results_org=EleutherAI,hub_repo_name=lm-eval-results,push_results_to_hub=True,push_samples_to_hub=True,public_repo=False \
This allows you to easily download the results and samples from the Hub, using:
from datasets import load_dataset
load_dataset("EleutherAI/lm-eval-results-private", "hellaswag", "latest")
For a full list of supported arguments, check out the interface guide in our documentation!
Visualizing Results
You can seamlessly visualize and analyze the results of your evaluation harness runs using both Weights & Biases (W&B) and Zeno.
Zeno
You can use Zeno to visualize the results of your eval harness runs.
First, head to hub.zenoml.com to create an account and get an API key on your account page. Add this key as an environment variable:
export ZENO_API_KEY=[your api key]
You'll also need to install the lm_eval[zeno] package extra.
To visualize the results, run the eval harness with the log_samples and output_path flags.
We expect output_path to contain multiple folders that represent individual model names.
You can thus run your evaluation on any number of tasks and models and upload all of the results as projects on Zeno.
lm_eval \
--model hf \
--model_args pretrained=EleutherAI/gpt-j-6B \
--tasks hellaswag \
--device cuda:0 \
--batch_size 8 \
--log_samples \
--output_path output/gpt-j-6B
Then, you can upload the resulting data using the zeno_visualize script:
python scripts/zeno_visualize.py \
--data_path output \
--project_name "Eleuther Project"
This will use all subfolders in data_path as different models and upload all tasks within these model folders to Zeno.
If you run the eval harness on multiple tasks, the project_name will be used as a prefix and one project will be created per task.
You can find an example of this workflow in examples/visualize-zeno.ipynb.
Weights and Biases
With the Weights and Biases integration, you can now spend more time extracting deeper insights into your evaluation results. The integration is designed to streamline the process of logging and visualizing experiment results using the Weights & Biases (W&B) platform.
The integration provide functionalities
- to automatically log the evaluation results,
- log the samples as W&B Tables for easy visualization,
- log the
results.jsonfile as an artifact for version control, - log the
<task_name>_eval_samples.jsonfile if the samples are logged, - generate a comprehensive report for analysis and visualization with all the important metric,
- log task and cli specific configs,
- and more out of the box like the command used to run the evaluation, GPU/CPU counts, timestamp, etc.
First you'll need to install the lm_eval[wandb] package extra. Do pip install lm_eval[wandb].
Authenticate your machine with an your unique W&B token. Visit https://wandb.ai/authorize to get one. Do wandb login in your command line terminal.
Run eval harness as usual with a wandb_args flag. Use this flag to provide arguments for initializing a wandb run (wandb.init) as comma separated string arguments.
lm_eval \
--model hf \
--model_args pretrained=microsoft/phi-2,trust_remote_code=True \
--tasks hellaswag,mmlu_abstract_algebra \
--device cuda:0 \
--batch_size 8 \
--output_path output/phi-2 \
--limit 10 \
--wandb_args project=lm-eval-harness-integration \
--log_samples
In the stdout, you will find the link to the W&B run page as well as link to the generated report. You can find an example of this workflow in examples/visualize-wandb.ipynb, and an example of how to integrate it beyond the CLI.
Contributing
Check out our open issues and feel free to submit pull requests!
For more information on the library and how everything fits together, see our documentation pages.
To get started with development, first clone the repository and install the dev dependencies:
git clone https://github.com/EleutherAI/lm-evaluation-harness
cd lm-evaluation-harness
pip install -e ".[dev,hf]"
Implementing new tasks
To implement a new task in the eval harness, see this guide.
In general, we follow this priority list for addressing concerns about prompting and other eval details:
- If there is widespread agreement among people who train LLMs, use the agreed upon procedure.
- If there is a clear and unambiguous official implementation, use that procedure.
- If there is widespread agreement among people who evaluate LLMs, use the agreed upon procedure.
- If there are multiple common implementations but not universal or widespread agreement, use our preferred option among the common implementations. As before, prioritize choosing from among the implementations found in LLM training papers.
These are guidelines and not rules, and can be overruled in special circumstances.
We try to prioritize agreement with the procedures used by other groups to decrease the harm when people inevitably compare runs across different papers despite our discouragement of the practice. Historically, we also prioritized the implementation from Language Models are Few Shot Learners as our original goal was specifically to compare results with that paper.
Support
The best way to get support is to open an issue on this repo or join the EleutherAI Discord server. The #lm-thunderdome channel is dedicated to developing this project and the #release-discussion channel is for receiving support for our releases. If you've used the library and have had a positive (or negative) experience, we'd love to hear from you!
Optional Extras
Extras dependencies can be installed via pip install -e ".[NAME]"
Model Backends
These extras install dependencies required to run specific model backends:
| NAME | Description |
|---|---|
| hf | HuggingFace Transformers (torch, transformers, accelerate, peft) |
| vllm | vLLM fast inference |
| api | API models (OpenAI, Anthropic, local servers) |
| gptq | AutoGPTQ quantized models |
| gptqmodel | GPTQModel quantized models |
| ibm_watsonx_ai | IBM watsonx.ai models |
| ipex | Intel IPEX backend |
| habana | Intel Gaudi backend |
| optimum | Intel OpenVINO models |
| neuronx | AWS Inferentia2 instances |
| winml | Windows ML (ONNX Runtime GenAI) - CPU/GPU/NPU |
| sparsify | Sparsify model steering |
| sae_lens | SAELens model steering |
任务依赖
这些额外包会安装特定评估任务所需的依赖项:
| 名称 | 描述 |
|---|---|
| tasks | 所有任务相关的依赖 |
| acpbench | ACP Bench 任务 |
| audiolm_qwen | Qwen2 音频模型 |
| ifeval | IFEval 任务 |
| japanese_leaderboard | 日语 LLM 任务 |
| longbench | LongBench 任务 |
| math | 数学答案校验 |
| multilingual | 多语言分词器 |
| ruler | RULER 任务 |
开发与工具
| 名称 | 描述 |
|---|---|
| dev | 代码检查与贡献 |
| hf_transfer | 加速 Hugging Face 下载 |
| sentencepiece | SentencePiece 分词器 |
| unitxt | Unitxt 任务 |
| wandb | Weights & Biases 日志记录 |
| zeno | Zeno 结果可视化 |
引用方式
@misc{eval-harness,
author = {Gao, Leo and Tow, Jonathan and Abbasi, Baber and Biderman, Stella and Black, Sid and DiPofi, Anthony and Foster, Charles and Golding, Laurence and Hsu, Jeffrey and Le Noac'h, Alain and Li, Haonan and McDonell, Kyle and Muennighoff, Niklas and Ociepa, Chris and Phang, Jason and Reynolds, Laria and Schoelkopf, Hailey and Skowron, Aviya and Sutawika, Lintang and Tang, Eric and Thite, Anish and Wang, Ben and Wang, Kevin and Zou, Andy},
title = {The Language Model Evaluation Harness},
month = 07,
year = 2024,
publisher = {Zenodo},
version = {v0.4.3},
doi = {10.5281/zenodo.12608602},
url = {https://zenodo.org/records/12608602}
}
版本历史
v0.4.112026/02/13v0.4.102026/01/27v0.4.9.22025/11/26v0.4.9.12025/08/04v0.4.92025/06/19v0.4.82025/03/05v0.4.72024/12/17v0.4.62024/11/25v0.4.52024/10/08v0.4.42024/09/05v0.4.32024/07/01v0.4.22024/03/18v0.4.12024/01/31v0.4.02023/12/04v0.3.02022/12/08v0.2.02022/03/07v0.0.12021/09/02常见问题
相似工具推荐
stable-diffusion-webui
stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面,旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点,将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。 无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师,还是想要深入探索模型潜力的开发者与研究人员,都能从中获益。其核心亮点在于极高的功能丰富度:不仅支持文生图、图生图、局部重绘(Inpainting)和外绘(Outpainting)等基础模式,还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外,它内置了 GFPGAN 和 CodeFormer 等人脸修复工具,支持多种神经网络放大算法,并允许用户通过插件系统无限扩展能力。即使是显存有限的设备,stable-diffusion-webui 也提供了相应的优化选项,让高质量的 AI 艺术创作变得触手可及。
everything-claude-code
everything-claude-code 是一套专为 AI 编程助手(如 Claude Code、Codex、Cursor 等)打造的高性能优化系统。它不仅仅是一组配置文件,而是一个经过长期实战打磨的完整框架,旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。 通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能,everything-claude-code 能显著提升 AI 在复杂任务中的表现,帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略,使得模型响应更快、成本更低,同时有效防御潜在的攻击向量。 这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库,还是需要 AI 协助进行安全审计与自动化测试,everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目,它融合了多语言支持与丰富的实战钩子(hooks),让 AI 真正成长为懂上
ComfyUI
ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎,专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式,采用直观的节点式流程图界面,让用户通过连接不同的功能模块即可构建个性化的生成管线。 这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景,也能自由组合模型、调整参数并实时预览效果,轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性,不仅支持 Windows、macOS 和 Linux 全平台,还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构,并率先支持 SDXL、Flux、SD3 等前沿模型。 无论是希望深入探索算法潜力的研究人员和开发者,还是追求极致创作自由度的设计师与资深 AI 绘画爱好者,ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能,使其成为当前最灵活、生态最丰富的开源扩散模型工具之一,帮助用户将创意高效转化为现实。
NextChat
NextChat 是一款轻量且极速的 AI 助手,旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性,以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发,NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。 这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言,它也提供了便捷的自托管方案,支持一键部署到 Vercel 或 Zeabur 等平台。 NextChat 的核心亮点在于其广泛的模型兼容性,原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型,让用户在一个界面即可自由切换不同 AI 能力。此外,它还率先支持 MCP(Model Context Protocol)协议,增强了上下文处理能力。针对企业用户,NextChat 提供专业版解决方案,具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能,满足公司对数据隐私和个性化管理的高标准要求。
ML-For-Beginners
ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程,旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周,包含 26 节精炼课程和 52 道配套测验,内容涵盖从基础概念到实际应用的完整流程,有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。 无论是希望转型的开发者、需要补充算法背景的研究人员,还是对人工智能充满好奇的普通爱好者,都能从中受益。课程不仅提供了清晰的理论讲解,还强调动手实践,让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持,通过自动化机制提供了包括简体中文在内的 50 多种语言版本,极大地降低了全球不同背景用户的学习门槛。此外,项目采用开源协作模式,社区活跃且内容持续更新,确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路,ML-For-Beginners 将是理想的起点。
ragflow
RAGFlow 是一款领先的开源检索增强生成(RAG)引擎,旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体(Agent)能力相结合,不仅支持从各类文档中高效提取知识,还能让模型基于这些知识进行逻辑推理和任务执行。 在大模型应用中,幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构(如表格、图表及混合排版),显著提升了信息检索的准确度,从而有效减少模型“胡编乱造”的现象,确保回答既有据可依又具备时效性。其内置的智能体机制更进一步,使系统不仅能回答问题,还能自主规划步骤解决复杂问题。 这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统,还是致力于探索大模型在垂直领域落地的创新者,都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口,既降低了非算法背景用户的上手门槛,也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目,它正成为连接通用大模型与行业专有知识之间的重要桥梁。