目录
③评测 InternLM2-Chat-7B 模型在 C-Eval 数据集上的性能
一、为什么要对大模型进行评测
- 理解模型能力:通过评测,可以更好地理解大模型的长处和短处,以及其在不同任务上的表现。
- 指导模型优化:评测结果可以作为优化模型的依据,帮助研究者找到模型改进的方向。
- 量化模型性能:通过评测,可以对大模型的性能进行量化评估,从而在不同模型之间进行比较。
- 确保模型可信:随着大模型在各个领域的广泛应用,确保模型的可信度变得越来越重要。评测可以帮助验证模型的预测结果是否可靠。
- 推动研究进展:通过对大模型的评测,可以推动相关研究的进展,促进学术交流和合作。
- 满足实际需求:在实际应用中,对大模型的评测可以帮助用户更好地了解和使用模型,满足实际需求。
二、大模型评测什么
- 自然语言处理:包括自然语言理解、推理、自然语言生成和多语言任务
- 鲁棒性、伦理、偏见和真实性
- 医学应用:包括医学问答、医学考试、医学教育和医学助手
- 社会科学
- 自然科学与工程:包括数学、通用科学和工程
- 代理应用:将 LLMs 作为代理使用
- 其他应用
三、opencompass
1、介绍
OpenCompass采取客观评测与主观评测相结合的方法。针对具有确定性答案的能力维度和场景,通过构造丰富完善的评测集,对模型能力进行综合评价。针对体现模型能力的开放式或半开放式的问题、模型安全问题等,采用主客观相结合的评测方式。
框架结构:
2、实操
①环境准备
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 .
②开始评测
通过以下命令评测 InternLM-Chat-7B 模型在 C-Eval 数据集上的性能。
第一次运行时以 --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 4 \ # 批量大小
--num-gpus 1 # 运行模型所需的 GPU 数量
--debug
③评测 InternLM2-Chat-7B 模型在 C-Eval 数据集上的性能
我首先使用了命令行测试了ceval_gen_2daf24数据集命令如下:
python run.py --datasets ceval_gen_2daf24 --hf-path /share/temp/model_repos/internlm-chat-7b/ --toke
nizer-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和models列表里面
from mmengine.config import read_base
with read_base():
from .models.qwen.hf_qwen_7b_chat import models as hf_qwen_7b_chat
from .models.qwen.hf_qwen_14b_chat import models as hf_qwen_14b_chat
from .models.chatglm.hf_chatglm3_6b import models as hf_chatglm3_6b
from .models.baichuan.hf_baichuan2_7b_chat import models as hf_baichuan2_7b
from .models.hf_internlm.hf_internlm_chat_20b import models as hf_internlm_chat_20b
from .models.judge_llm.auto_j.hf_autoj_eng_13b import models as hf_autoj
from .models.judge_llm.judgelm.hf_judgelm_33b_v1 import models as hf_judgelm
from .models.judge_llm.pandalm.hf_pandalm_7b_v1 import models as hf_pandalm
from .datasets.subjective.alignbench.alignbench_judgeby_critiquellm import subjective_datasets
from .datasets.ceval.ceval_gen_2daf24 import ceval_datasets # 我的数据集添加
from .models.hf_internlm.hf_internlm_chat_7b import models as internlm_7b # 我的模型添加
datasets = [*ceval_datasets] # 需要修改相应的数据集
from opencompass.models import HuggingFaceCausalLM, HuggingFace, HuggingFaceChatGLM3
from opencompass.models.openai_api import OpenAIAllesAPIN
from opencompass.partitioners import NaivePartitioner, SizePartitioner
from opencompass.partitioners.sub_naive import SubjectiveNaivePartitioner
from opencompass.partitioners.sub_size import SubjectiveSizePartitioner
from opencompass.runners import LocalRunner
from opencompass.runners import SlurmSequentialRunner
from opencompass.tasks import OpenICLInferTask
from opencompass.tasks.subjective_eval import SubjectiveEvalTask
from opencompass.summarizers import AlignmentBenchSummarizer
# -------------Inferen Stage ----------------------------------------
models = [*internlm_7b]#, *hf_chatglm3_6b, *hf_internlm_chat_20b, *hf_qwen_7b_chat, *hf_qwen_14b_chat]
infer = dict(
partitioner=dict(type=NaivePartitioner),
runner=dict(
type=LocalRunner, # 也需要修改为本地的GPU
# partition='llmeval',
# quotatype='auto',
max_num_workers=256,
task=dict(type=OpenICLInferTask)),
)
# -------------Evalation Stage ----------------------------------------
## ------------- JudgeLLM Configuration
api_meta_template = dict(
round=[
dict(role='HUMAN', api_role='HUMAN'),
dict(role='BOT', api_role='BOT', generate=True),
]
)
judge_model = dict(
abbr='GPT4-Turbo',
type=OpenAIAllesAPIN, path='gpt-4-1106-preview',
key='xxxx', # The key will be obtained from $OPENAI_API_KEY, but you can write down your key here as well
url='xxxx',
meta_template=api_meta_template,
query_per_second=16,
max_out_len=2048,
max_seq_len=2048,
batch_size=8,
temperature = 0
)
## ------------- Evaluation Configuration
eval = dict(
partitioner=dict(
type=SubjectiveNaivePartitioner,
mode='singlescore',
models = models
),
runner=dict(
type=LocalRunner,
max_num_workers=2,
task=dict(
type=SubjectiveEvalTask,
judge_cfg=judge_model
)),
)
summarizer = dict(
type=AlignmentBenchSummarizer, judge_type = 'general'
)
work_dir = '/root/opencompass/my_output'
模型的配置文件
路径修改
from opencompass.models import HuggingFaceCausalLM
_meta_template = dict(
round=[
dict(role='HUMAN', begin='<|User|>:', end='\n'),
dict(role='BOT', begin='<|Bot|>:', end='<eoa>\n', generate=True),
],
)
models = [
dict(
type=HuggingFaceCausalLM,
abbr='internlm-chat-7b-hf',
path="/share/temp/model_repos/internlm-chat-7b/", # 路径修改
tokenizer_path='/share/temp/model_repos/internlm-chat-7b/', # 路径修改
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,
max_seq_len=2048,
batch_size=8,
meta_template=_meta_template,
run_cfg=dict(num_gpus=1, num_procs=1),
end_str='<eoa>',
)
]
运行bash脚本
cd ~/opencompass
conda activate opencompass
python run.py configs/eval_subjective_alignbench.py --debug
结果报错如下:
不知道怎么解决,如果哪位大佬知道,请指点一下。
参考文章:
1. (36 条消息) 目前大语言模型的评测基准有哪些? - 知乎 (zhihu.com)https://www.zhihu.com/question/601328258