一、OpenCompass介绍
1.评测对象
本算法库的主要评测对象为语言大模型与多模态大模型。我们以语言大模型为例介绍评测的具体模型类型。
-
基座模型:一般是经过海量的文本数据以自监督学习的方式进行训练获得的模型(如OpenAI的GPT-3,Meta的LLaMA),往往具有强大的文字续写能力。
-
对话模型:一般是在的基座模型的基础上,经过指令微调或人类偏好对齐获得的模型(如OpenAI的ChatGPT、上海人工智能实验室的书生·浦语),能理解人类指令,具有较强的对话能力。
2.工具架构
OpenCompass是一个开源评测平台,旨在为企业提供全面的软件质量评估服务。该平台采用了独特的架构设计,将工具层、方法层和能力层三个层面紧密结合,实现了高效、准确的评测功能。
在工具层方面,OpenCompass提供了分布式评测、工程评测、数据库上报评测、榜单发布和评测报告生成等工具。这些工具覆盖了从软件开发生命周期的各个阶段到最终的测试和评估过程,确保了全方位的质量控制。
在方法层方面,OpenCompass采用了自动化客观评测、基于模型辅助的主观评测和基于人类反馈的主观评测等多种方法。这些方法相互补充,不仅提高了评测的准确性,还能适应不同类型和规模的软件项目。
在能力层方面,OpenCompass注重学科语言知识、知识增强模型和通用能力特色能力等方面的建设。通过这些能力的整合,OpenCompass能够更好地理解和评估软件的性能、安全性和其他关键指标。
3.评测步骤
二、实操
1.面向GPU的环境安装
conda create --name opencompass --clone=/root/share/conda_envs/internlm-base
source activate opencompass
git clone https://github.com/open-compass/opencompass
cd opencompass
pip install -e .
2.数据准备
# 解压评测数据集到 data/ 处
cp /share/temp/datasets/OpenCompassData-core-20231110.zip /root/opencompass/
unzip OpenCompassData-core-20231110.zip# 将会在opencompass下看到data文件夹
3.启动评测
确保按照上述步骤正确安装 OpenCompass 并准备好数据集后,可以通过以下命令评测 InternLM-Chat-7B 模型在 C-Eval 数据集上的性能。由于 OpenCompass 默认并行启动评估过程,我们可以在第一次运行时以 --debug
模式启动评估,并检查是否存在问题。在 --debug
模式下,任务将按顺序执行,并实时打印输出。
python run.py --datasets ceval_gen --hf-path /share/temp/model_repos/internlm-chat-7b/ --tokenizer-path /share/temp/model_repos/internlm-chat-7b/ --tokenizer-kwargs padding_side='left' truncation='left' trust_remote_code=True --model-kwargs trust_remote_code=True device_map='auto' --max-seq-len 2048 --max-out-len 16 --batch-size 4 --num-gpus 1 --debug
命令解析
--datasets ceval_gen \
--hf-path /share/temp/model_repos/internlm-chat-7b/ \ # HuggingFace 模型路径
--tokenizer-path /share/temp/model_repos/internlm-chat-7b/ \ # HuggingFace tokenizer 路径(如果与模型路径相同,可以省略)
--tokenizer-kwargs padding_side='left' truncation='left' trust_remote_code=True \ # 构建 tokenizer 的参数
--model-kwargs device_map='auto' trust_remote_code=True \ # 构建模型的参数
--max-seq-len 2048 \ # 模型可以接受的最大序列长度
--max-out-len 16 \ # 生成的最大 token 数
--batch-size 2 \ # 批量大小
--num-gpus 1 # 运行模型所需的 GPU 数量
--debug
如果一切正常,您应该看到屏幕上显示 “Starting inference process”:
[2024-01-12 18:23:55,076] [opencompass.openicl.icl_inferencer.icl_gen_inferencer] [INFO] Starting inference process...
三、基础作业
四、进阶作业
使用 OpenCompass 评测 InternLM2-Chat-7B 模型使用 LMDeploy 0.2.0 部署后在 C-Eval 数据集上的性能
1.下载internLM2-Chat-7B 模型,并进行挂载
ln -s /share/model_repos/internlm2-7b/ ./
2. 编译安装LMdeploy0.2.0
pip install 'lmdeploy[all]==v0.2.0'
3. 使用LMdeploy 将模型internLM2-Chat-7B 进行转换
lmdeploy convert internlm2-chat-7b /root/model/Shanghai_AI_Laboratory/internlm2-chat-7b
4. 模型结果测评
cd /root/opencompass
cd configs
#新建deploy.py
python run.py configs/deploy.py --debug
from mmengine.config import read_base
from opencompass.models.turbomind import TurboMindModel
with read_base():
# choose a list of datasets
from .datasets.ceval.ceval_gen_5f30c7 import ceval_datasets
# and output the results in a choosen format
from .summarizers.medium import summarizer
datasets = sum((v for k, v in locals().items() if k.endswith('_datasets')), [])
internlm_meta_template = dict(round=[
dict(role='HUMAN', begin='<|User|>:', end='\n'),
dict(role='BOT', begin='<|Bot|>:', end='<eoa>\n', generate=True),
],
eos_token_id=103028)
# config for internlm-chat-7b
internlm2_chat_7b = dict(
type=TurboMindModel,
abbr='internlm2-chat-7b-turbomind',
path='/root/deploy2/workspace/',
engine_config=dict(session_len=512,
max_batch_size=2,
rope_scaling_factor=1.0),
gen_config=dict(top_k=1,
top_p=0.8,
temperature=1.0,
max_new_tokens=100),
max_out_len=100,
max_seq_len=512,
batch_size=2,
concurrency=1,
meta_template=internlm_meta_template,
run_cfg=dict(num_gpus=1, num_procs=1),
)
models = [internlm2_chat_7b]
Model: internlm2-chat-7b-turbomind
ceval-computer_network: {'accuracy': 36.368421052631554}
ceval-operating_system: {'accuracy': 26.3278947368251}
ceval-computer_architecture: {'accuracy': 32.095238095238095}
ceval-college_programming: {'accuracy': 24.324324324324326}
ceval-college_physics: {'accuracy': 10.526315789473683}
ceval-college_chemistry: {'accuracy': 0.0}
ceval-advanced_mathematics: {'accuracy': 15.789473684210526}
ceval-probability_and_statistics: {'accuracy': 11.11111111111111}
ceval-discrete_mathematics: {'accuracy': 18.75}
ceval-electrical_engineer: {'accuracy': 21.62162162162162}
ceval-metrology_engineer: {'accuracy': 41.66666666666667}
ceval-high_school_mathematics: {'accuracy': 0.0}
ceval-high_school_physics: {'accuracy': 31.57894736842105}
ceval-high_school_chemistry: {'accuracy': 31.57894736842105}
ceval-high_school_biology: {'accuracy': 31.57894736842105}
ceval-middle_school_mathematics: {'accuracy': 31.57894736842105}
ceval-middle_school_biology: {'accuracy': 71.42857142857143}
ceval-middle_school_physics: {'accuracy': 52.63157894736842}
ceval-middle_school_chemistry: {'accuracy': 80.0}
ceval-veterinary_medicine: {'accuracy': 43.47826086956522}
ceval-college_economics: {'accuracy': 23.636363636363637}
ceval-business_administration: {'accuracy': 33.33333333333333}
ceval-marxism: {'accuracy': 84.21052631578947}
ceval-mao_zedong_thought: {'accuracy': 70.83333333333334}
ceval-education_science: {'accuracy': 62.06896551724138}
ceval-teacher_qualification: {'accuracy': 77.27272727272727}
ceval-high_school_politics: {'accuracy': 26.31578947368421}
ceval-high_school_geography: {'accuracy': 57.89473684210527}
ceval-middle_school_politics: {'accuracy': 57.14285714285714}
ceval-middle_school_geography: {'accuracy': 50.0}
ceval-modern_chinese_history: {'accuracy': 65.21739130434783}
ceval-ideological_and_moral_cultivation: {'accuracy': 89.47368421052632}
ceval-logic: {'accuracy': 13.234363536763634}