type
status
date
slug
summary
tags
category
icon
password
org
参数
LlamaFactory
的参数在src/llamafactory/hparams
中定义:data_args
evaluation_args
finetuning_args
generating_args
model_args
training_args
Evaluate
自带的benchmark为
ceval
、cmmlu
和mmlu
三种。eval过程
Load dataset
对task参数,task参数拆分为
task_split
,例如mmlu_test
、cmmlu_train
,前者对应benchmark后者对应切分的集合。task存储方式如下:
读取mapping.json文件,按照文件中subject的顺序进行处理,逐一测试。
对于
load_dataset
函数,若path参数为一个文件夹,则会找到文件夹中同名python文件进行处理读取数据集。Formatting benchmark
Raw data(mmlu)
对每一个subject的原始数据进行formatting,例如
input: a dict with keys {"question", "A", "B", "C", "D", "answer"}output: a tuple of (prompt, response)
可以自定义eval_template。
Predict and test
每个batch进行inference,测试每个数据的回答,preds为choices中的一个。
How to batch_inference?
batch_size个input,经过model生成,logits为[batch_size, len, vocab_size]的tensor,每个input对应一个[len, vocab_size]的tensor,取每个input对应的logit的最后一个词认为是答案->word_probs,得到的是最后一个位置的所有词表中的token的概率,取其中为choice的token的概率->choice_probs,
word_probs[:, self.choice_inputs]
中choice_inputs为choices(如ABCD)对应在词表中的位置(如果choice不只是一个token怎么办?)。最后取选项中最大概率的一个作为输出pred。最后匹配答案即可:
How to use it to evaluate models on other benchmarks?
无论是mmlu task 还是cval task,此框架的eval针对是answer是choice的benchmark。
How about gsm8k?
https://huggingface.co/datasets/openai/gsm8k
Raw data is like this:
Query -> answer ends up with a number
- Author:Wenxuan Wang
- URL:http://preview.tangly1024.com/article/206d0968-b245-8062-a443-cf2161a6e201
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!