更多评测技巧欢迎查看 opencompass.readthedocs.io/zh-cn/lates… 文档~我们下节课再见!
闯关任务
使用 OpenCompass 评测 InternLM(C-Eval和math_gen 选做一道即可) 和 InternVL(MME数据集) 并在飞书文档中详细记录到飞书文档
进阶 完成3.4 自建数据集的评测
提交地址:aicarrier.feishu.cn/share/base/…
conda环境安装
conda create -n opencompass python=3.10conda activate opencompass# 注意:一定要先 cd /rootcd /rootgit clone https://github.moeyy.xyz/https://github.com/open-compass/opencompass opencompasscd opencompasspip install -e .pip install sentencepiece#升级datasets 避免不识别新的功能pip install datasets==3.2.0pip install modelscope
评测不同类型的题目
3.0 数据集的下载
OpenCompass 支持的数据集主要包括三个部分:
- Huggingface 数据集: Huggingface Dataset 提供了大量的数据集,这部分数据集运行时会自动下载。ModelScope 数据集:ModelScope OpenCompass Dataset 支持从 ModelScope 自动下载数据集。
要启用此功能,请设置环境变量:export DATASET_SOURCE=ModelScope
,可用的数据集包括(来源于 OpenCompassData-core.zip):
humaneval, triviaqa, commonsenseqa, tydiqa, strategyqa, cmmlu, lambada, piqa, ceval, math, LCSTS, Xsum, winogrande, openbookqa, AGIEval, gsm8k, nq, race, siqa, mbpp, mmlu, hellaswag, ARC, BBH, xstory_cloze, summedits, GAOKAO-BENCH, OCNLI, cmnli
3. 自建以及第三方数据集:OpenCompass 还提供了一些第三方数据集及自建中文数据集。运行以下命令手动下载解压。
为了方便评测,我们首先将数据集下载到本地:
cd /root/opencompasswget https://ghfast.top/https://github.com/open-compass/opencompass/releases/download/0.2.2.rc1/OpenCompassData-core-20240207.zipunzip OpenCompassData-core-20240207.zip
将会在 OpenCompass 下看到data文件夹,里面包含的数据集如下图所示:
评测C-Eval 选择题
有两种方式运行,推荐命令行运行简单。但如果要更高定制化需求,需要些配置脚本运行更合适。
3.1.1 命令行运行
修改评测模型地址为本地,不用下载更节省时间。
opencompass/opencompass/configs/models/hf_internlm/hf_internlm3_8b_instruct.py
,贴入以下代码:
from opencompass.models import HuggingFacewithChatTemplatemodels = [ dict( type=HuggingFacewithChatTemplate, abbr='internlm3-8b-instruct-hf', path='/root/share/new_models/internlm3/internlm3-8b-instruct', max_out_len=8192, batch_size=8, run_cfg=dict(num_gpus=1), )]
可以通过以下命令评测 internlm3_8b_instruct 模型在 C-Eval 数据集上的性能:
python run.py --datasets ceval_gen --models hf_internlm3_8b_instruct --debug
Notice: 由于 OpenCompass 默认并行启动评估过程,我们可以在第一次运行时以 --debug 模式启动评估,并检查是否存在问题。在 --debug 模式下,任务将按顺序执行,并实时打印输出。
输出结果
3.1.2 写配置脚本运行
除了通过命令行配置实验外,OpenCompass 还允许用户在配置文件中编写实验的完整配置脚本,并通过 run.py 直接运行它。配置文件是以 Python 格式组织的,并且必须包括 datasets 和 models 字段。本次测试配置在 configs
文件夹 中。此配置通过 继承机制 引入所需的数据集和模型配置,并以所需格式组合 datasets 和 models 字段。
运行以下代码,在configs文件夹下创建eval_tutorial_demo.py
cd /root/opencompass/opencompass/configstouch eval_tutorial_demo.py
打开eval_tutorial_demo.py
贴入以下代码
from mmengine.config import read_basewith read_base(): from .datasets.ceval.ceval_gen import ceval_datasets from .models.hf_internlm.hf_internlm3_8b_instruct import models as hf_internlm3_8b_instructdatasets = ceval_datasetsmodels = hf_internlm3_8b_instruct
因此,运行任务时,我们只需将配置文件的路径参数传递给 run.py:
cd /root/opencompasspython run.py opencompass/configs/eval_tutorial_demo.py --debug
输出结果
3.2评测math_gen计算题
运行以下代码
python run.py --datasets math_gen --models hf_internlm3_8b_instruct --debug
conda activate opencompass # 注意:一定要先 cd /root cd /root
3.3评测MME多模态题——InternVL3-2B评测实践
环境准备用以下命令安装依赖:
# 基于conda环境conda create -n VLMEvalKit python=3.10conda activate VLMEvalKitpip install idna requestspip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118git clone https://ghfast.top/https://github.com/open-compass/VLMEvalKit.gitcd VLMEvalKitpip install -e .pip install einops timm validators sty decord httpx xlsxwriter pandas matplotlib tabulate rich portalocker imageio
注意:
某些 VLM 可能无法在某些特定的 transformers 版本下运行,参考以下设置来评估对应的VLM:
- 请用
transformers==4.33.0
来运行: Qwen series
, Monkey series
, InternLM-XComposer Series
, mPLUG-Owl2
, OpenFlamingo v2
, IDEFICS series
, VisualGLM
, MMAlaya
, ShareCaptioner
, MiniGPT-4 series
, InstructBLIP series
, PandaGPT
, VXVERSE
.请用 transformers==4.37.0
来运行: LLaVA series
, ShareGPT4V series
, TransCore-M
, LLaVA (XTuner)
, CogVLM Series
, EMU2 Series
, Yi-VL Series
, MiniCPM-[V1/V2]
, OmniLMM-12B
, DeepSeek-VL series
, InternVL series
, Cambrian Series
, VILA Series
, Llama-3-MixSenseV1_1
, Parrot-7B
, PLLaVA Series
.请用 transformers==4.40.0
来运行: IDEFICS2
, Bunny-Llama3
, MiniCPM-Llama3-V2.5
, 360VL-70B
, Phi-3-Vision
, WeMM
.请用 transformers==latest
来运行: LLaVA-Next series
, PaliGemma-3B
, Chame3leon series
, Video-LLaVA-7B-HF
, Ovis series
, Mantis series
, MiniCPM-V2.6
, OmChat-v2.0-13B-sinlge-beta
, Idefics-3
, GLM-4v-9B
, VideoChat2-HD
.3.3.2修改文件
在$VLMEvalKit/vlmeval/config.py
文件中设置在 VLMEvalKit 中支持的 VLM 名称,以及模型路径。
如果你的电脑上面没有该模型的模型文件,则需要自己下载,然后更改模型路径,也可以不修改,在运行模型评测命令的时候会自动下载模型文件。
注:默认下载使用的是Huggingface,需要进行科学上网,也可以使用modelscope将模型下载到本地,然后更改路径。
修改VLMEvalKit/vlmeval/config.py下第852行为2. ### 修改文件
在$VLMEvalKit/vlmeval/config.py
文件中设置在 VLMEvalKit 中支持的 VLM 名称,以及模型路径。
如果你的电脑上面没有该模型的模型文件,则需要自己下载,然后更改模型路径,也可以不修改,在运行模型评测命令的时候会自动下载模型文件。
注:默认下载使用的是Huggingface,需要进行科学上网,也可以使用modelscope将模型下载到本地,然后更改路径。
修改VLMEvalKit/vlmeval/config.py下第852行为
InternVLChat, model_path="/root/share/new_models/InternVL3/InternVL3-2B", version="V2.0"
/VLMEvalKit目录下执行使用以下命令开始推理和评估:
python run.py --data MME --model InternVL3-2B --verbose
torchrun --nproc-per-node=1 run.py --data MME --model InternVL3-2B --verbose
3.4自建数据集进行评测
运行以下代码,在configs文件夹下创建eval_tutorial_demo3.py
cd /root/opencompass/opencompass/configstouch eval_tutorial_demo3.py
from mmengine.config import read_basefrom opencompass.models import OpenAISDK# 配置模型models = [ dict( type=OpenAISDK, path='internlm3-latest', # 请求服务时的 model name key='eyJ0_your_key', # 缩进修正(与path、openai_api_base等对齐) openai_api_base='https://internlm-chat.intern-ai.org.cn/puyu/api/v1/', # API 地址 rpm_verbose=True, query_per_second=0.16, max_out_len=1024, max_seq_len=4096, temperature=0.01, batch_size=1, retry=3, )]# 配置数据集datasets = [ dict( path='/root/opencompass/newformat_sft_test_data.csv', data_type='mcq', infer_method='gen' )]
运行
#在opencompass目录下python run.py opencompass/configs/eval_tutorial_demo3.py --debug