Lazy loaded image
LlamaFactory
Words 2109Read Time 6 min
2025-6-2
2025-6-2
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为cevalcmmlummlu三种。

eval过程

Load dataset

对task参数,task参数拆分为task_split,例如mmlu_testcmmlu_train,前者对应benchmark后者对应切分的集合。
task存储方式如下:
notion image
读取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中的一个。
notion image
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。
最后匹配答案即可:
notion image

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:
notion image
Query -> answer ends up with a number
上一篇
ACL2025
下一篇
Research Proposal for MATRL