1. 环境安装
conda create -n opencompass python=3.10
conda activate opencompass
conda install pytorch==2.1.2 torchvision==0.16.2 torchaudio==2.1.2 pytorch-cuda=12.1 -c pytorch -c nvidia -y
# 注意:一定要先 cd /root
cd /root
git clone -b 0.2.4 https://github.com/open-compass/opencompass
cd opencompass
pip install -e .
apt-get update
apt-get install cmake
pip install -r requirements.txt
pip install protobuf
安装成功后,结果如图:
2.数据准备
评测数据集
拷贝数据集到当前文件夹下,并解压
cp /share/temp/datasets/OpenCompassData-core-20231110.zip /root/opencompass/
unzip OpenCompassData-core-20231110.zip
解压后
InternLM和ceval 相关的配置文件
在终端输入
python tools/list_configs.py internlm ceval
可以得到如下输出
启动评测
使用命令行配置参数法进行评测
打开 opencompass文件夹下configs/models/hf_internlm/的hf_internlm2_chat_1_8b.py
,贴入以下代码
from opencompass.models import HuggingFaceCausalLM
models = [
dict(
type=HuggingFaceCausalLM,
abbr='internlm2-1.8b-hf',
path="/share/new_models/Shanghai_AI_Laboratory/internlm2-chat-1_8b",
tokenizer_path='/share/new_models/Shanghai_AI_Laboratory/internlm2-chat-1_8b',
model_kwargs=dict(
trust_remote_code=True,
device_map='auto',
),
tokenizer_kwargs=dict(
padding_side='left',
truncation_side='left',
use_fast=False,
trust_remote_code=True,
),
max_out_len=100,
min_out_len=1,
max_seq_len=2048,
batch_size=8,
run_cfg=dict(num_gpus=1, num_procs=1),
)
]
确保按照上述步骤正确安装 OpenCompass 并准备好数据集后,可以通过以下命令评测 InternLM2-Chat-1.8B 模型在 C-Eval 数据集上的性能。由于 OpenCompass 默认并行启动评估过程,我们可以在第一次运行时以 --debug 模式启动评估,并检查是否存在问题。在 --debug 模式下,任务将按顺序执行,并实时打印输出。
配置环境变量
export MKL_SERVICE_FORCE_INTEL=1
运行代码:
python run.py --datasets ceval_gen --models hf_internlm2_chat_1_8b --debug
得到
使用配置文件修改参数法进行评测
除了通过命令行配置实验外,OpenCompass 还允许用户在配置文件中编写实验的完整配置,并通过 run.py 直接运行它。配置文件是以 Python 格式组织的,并且必须包括 datasets 和 models 字段。本次测试配置在 configs
文件夹 中。此配置通过 继承机制 引入所需的数据集和模型配置,并以所需格式组合 datasets 和 models 字段。 运行以下代码,在configs文件夹下创建eval_tutorial_demo.py
cd /root/opencompass/configs
touch eval_tutorial_demo.py
贴入代码:
from mmengine.config import read_base
with read_base():
from .datasets.ceval.ceval_gen import ceval_datasets
from .models.hf_internlm.hf_internlm2_chat_1_8b import models as hf_internlm2_chat_1_8b_models
datasets = ceval_datasets
models = hf_internlm2_chat_1_8b_models
因此,运行任务时,我们只需将配置文件的路径传递给 run.py:
cd /root/opencompass
python run.py configs/eval_tutorial_demo.py --debug
得到:
使用 OpenCompass 进行调用API评测
官方已经给出了api的demo,在文件opencompass/configs/api_examples中,这里有一些常见的大模型,我选的是qwen,因此,我们找到eval_api_qwen.py,把api-key添加进去即可。然后运行代码:
python run.py configs/api_examples/eval_api_qwen.py --debug
得到:
dataset version metric mode qwen-max
-------------------------------------- --------- ------------- ------ ----------
--------- 考试 Exam --------- - - - -
ceval - naive_average gen 84.91
agieval - - - -
mmlu - - - -
GaokaoBench - - - -
ARC-c - - - -
--------- 语言 Language --------- - - - -
WiC - - - -
summedits - - - -
chid-dev - - - -
afqmc-dev - - - -
bustm-dev - - - -
cluewsc-dev - - - -
WSC - - - -
winogrande - - - -
flores_100 - - - -
--------- 知识 Knowledge --------- - - - -
BoolQ - - - -
commonsense_qa - - - -
nq - - - -
triviaqa - - - -
--------- 推理 Reasoning --------- - - - -
cmnli - - - -
ocnli - - - -
ocnli_fc-dev - - - -
AX_b - - - -
AX_g - - - -
CB - - - -
RTE - - - -
story_cloze - - - -
COPA - - - -
ReCoRD - - - -
hellaswag - - - -
piqa - - - -
siqa - - - -
strategyqa - - - -
math - - - -
gsm8k - - - -
TheoremQA - - - -
openai_humaneval - - - -
mbpp - - - -
bbh - - - -
--------- 理解 Understanding --------- - - - -
C3 - - - -
CMRC_dev - - - -
DRCD_dev - - - -
MultiRC - - - -
race-middle - - - -
race-high - - - -
openbookqa_fact - - - -
csl_dev - - - -
lcsts - - - -
Xsum - - - -
eprstmt-dev - - - -
lambada - - - -
tnews-dev - - - -
08/23 12:17:07 - OpenCompass - INFO - write summary to /root/opencompass/outputs/api_qwen/20240823_111223/summary/summary_20240823_111223.txt
08/23 12:17:07 - OpenCompass - INFO - write csv to /root/opencompass/outputs/api_qwen/20240823_111223/summary/summary_20240823_111223.csv