L1G2-OpenCompass 评测书生大模型实践

更多评测技巧欢迎查看 opencompass.readthedocs.io/zh-cn/lates... 文档~我们下节课再见!

闯关任务

  • 使用 OpenCompass 评测 InternLM(C-Eval和math_gen 选做一道即可) 和 InternVL(MME数据集) 并在飞书文档中详细记录到飞书文档

  • 进阶 完成3.4 自建数据集的评测

提交地址:aicarrier.feishu.cn/share/base/...

conda环境安装

bash 复制代码
conda create -n opencompass python=3.10
conda activate opencompass

# 注意:一定要先 cd /root
cd /root
git clone https://github.moeyy.xyz/https://github.com/open-compass/opencompass opencompass
cd opencompass
pip install -e .

pip install sentencepiece
#升级datasets 避免不识别新的功能
pip install datasets==3.2.0
pip install modelscope

评测不同类型的题目

3.0 数据集的下载

OpenCompass 支持的数据集主要包括三个部分:

  1. Huggingface 数据集: Huggingface Dataset 提供了大量的数据集,这部分数据集运行时会自动下载
  2. ModelScope 数据集:ModelScope OpenCompass Dataset 支持从 ModelScope 自动下载数据集。

要启用此功能,请设置环境变量:export DATASET_SOURCE=ModelScope,可用的数据集包括(来源于 OpenCompassData-core.zip):

lua 复制代码
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
  1. 自建以及第三方数据集:OpenCompass 还提供了一些第三方数据集及自建中文 数据集。运行以下命令手动下载解压

为了方便评测,我们首先将数据集下载到本地:

bash 复制代码
cd /root/opencompass
wget https://ghfast.top/https://github.com/open-compass/opencompass/releases/download/0.2.2.rc1/OpenCompassData-core-20240207.zip
unzip OpenCompassData-core-20240207.zip

将会在 OpenCompass 下看到data文件夹,里面包含的数据集如下图所示:

评测C-Eval 选择题

有两种方式运行,推荐命令行运行简单。但如果要更高定制化需求,需要些配置脚本运行更合适。

3.1.1 命令行运行

修改评测模型地址为本地,不用下载更节省时间

opencompass/opencompass/configs/models/hf_internlm/hf_internlm3_8b_instruct.py,贴入以下代码:

python 复制代码
from opencompass.models import HuggingFacewithChatTemplate

models = [
    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 数据集上的性能:

css 复制代码
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

bash 复制代码
cd /root/opencompass/opencompass/configs
touch eval_tutorial_demo.py

打开eval_tutorial_demo.py 贴入以下代码

javascript 复制代码
from mmengine.config import read_base

with read_base():
    from .datasets.ceval.ceval_gen import ceval_datasets
    from .models.hf_internlm.hf_internlm3_8b_instruct import models as hf_internlm3_8b_instruct

datasets = ceval_datasets
models = hf_internlm3_8b_instruct

因此,运行任务时,我们只需将配置文件的路径参数传递给 run.py

bash 复制代码
cd /root/opencompass
python run.py opencompass/configs/eval_tutorial_demo.py --debug

输出结果

3.2评测math_gen计算题

运行以下代码

css 复制代码
python run.py --datasets math_gen --models hf_internlm3_8b_instruct --debug
js 复制代码
conda activate opencompass # 注意:一定要先 cd /root cd /root

3.3评测MME多模态题------InternVL3-2B评测实践

环境准备用以下命令安装依赖:

ruby 复制代码
# 基于conda环境
conda create -n VLMEvalKit python=3.10
conda activate VLMEvalKit
pip install idna requests
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

git clone https://ghfast.top/https://github.com/open-compass/VLMEvalKit.git
cd VLMEvalKit
pip 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行为

ini 复制代码
InternVLChat, model_path="/root/share/new_models/InternVL3/InternVL3-2B", version="V2.0"

/VLMEvalKit目录下执行 使用以下命令开始推理和评估:

css 复制代码
python run.py --data MME --model InternVL3-2B --verbose
css 复制代码
torchrun --nproc-per-node=1 run.py --data MME --model InternVL3-2B --verbose

3.4自建数据集进行评测

运行以下代码,在configs文件夹下创建eval_tutorial_demo3.py

bash 复制代码
cd /root/opencompass/opencompass/configs
touch eval_tutorial_demo3.py
python 复制代码
from mmengine.config import read_base
from 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'
    )
]

运行

bash 复制代码
#在opencompass目录下
python run.py opencompass/configs/eval_tutorial_demo3.py --debug
相关推荐
sunny-ll1 小时前
【C++】详解vector二维数组的全部操作(超细图例解析!!!)
c语言·开发语言·c++·算法·面试
嵌入式@秋刀鱼2 小时前
《第四章-筋骨淬炼》 C++修炼生涯笔记(基础篇)数组与函数
开发语言·数据结构·c++·笔记·算法·链表·visual studio code
嵌入式@秋刀鱼2 小时前
《第五章-心法进阶》 C++修炼生涯笔记(基础篇)指针与结构体⭐⭐⭐⭐⭐
c语言·开发语言·数据结构·c++·笔记·算法·visual studio code
简简单单做算法2 小时前
基于PSO粒子群优化的VMD-LSTM时间序列预测算法matlab仿真
算法·matlab·lstm·时间序列预测·pso·vmd-lstm·pso-vmd-lstm
无聊的小坏坏2 小时前
高精度算法详解:从原理到加减乘除的完整实现
算法
愚润求学2 小时前
【递归、搜索与回溯】FloodFill算法(二)
c++·算法·leetcode
泽02022 小时前
C++之list的自我实现
开发语言·数据结构·c++·算法·list
南枝异客3 小时前
四数之和-力扣
java·算法·leetcode
凌肖战3 小时前
C语言中提供的第三方库之哈希表实现
算法·哈希算法
lingling0094 小时前
迁移科技:破解纸箱拆垛场景的自动化升级密码
算法