使用lm-evaluation-harness评估LoRA量化模型缺失config.json的解决方法
解决模型缺失config.json的LLM评估方案
核心思路
该模型基于Gemma架构微调,直接复用Gemma基础模型的config.json,再正确加载LoRA权重即可解决问题。
方法1:命令行指定基础模型+LoRA权重
修改执行命令,在model_args中同时指定基础模型(提供config)和LoRA微调权重路径:
!python -m lm_eval --model hf --model_args pretrained=google/gemma-7b-it,peft=theoracle/gemma_italian_camoscio --tasks xcopa_it,hellaswag_it,lambada_openai_mt_it,belebele_ita_Latn,arc_it --device cuda:0 --batch_size 8
如果是4bit量化版本,可补充量化参数(需安装bitsandbytes库):
!python -m lm_eval --model hf --model_args pretrained=google/gemma-7b-it,peft=theoracle/gemma_italian_camoscio,load_in_4bit=True --tasks xcopa_it,hellaswag_it,lambada_openai_mt_it,belebele_ita_Latn,arc_it --device cuda:0 --batch_size 8
方法2:手动补充config.json到模型目录
- 下载
google/gemma-7b-it的config.json文件(对应你微调时用的基础模型版本)。 - 将该文件复制到本地的
theoracle/gemma_italian_camoscio模型目录下。 - 保持原命令不变,重新运行评估脚本。
方法3:Python脚本手动加载模型后评估
如果命令行参数配置受限,可直接编写脚本加载模型并调用评估API:
import torch from lm_eval import evaluator from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig from peft import PeftModel # 配置4bit量化(按需启用) bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16 ) # 加载基础模型和tokenizer base_model = AutoModelForCausalLM.from_pretrained( "google/gemma-7b-it", quantization_config=bnb_config, device_map="auto" ) tokenizer = AutoTokenizer.from_pretrained("google/gemma-7b-it") # 加载LoRA微调权重 model = PeftModel.from_pretrained(base_model, "theoracle/gemma_italian_camoscio") model.eval() # 执行评估 results = evaluator.simple_evaluate( model=model, tokenizer=tokenizer, tasks=["xcopa_it", "hellaswag_it", "lambada_openai_mt_it", "belebele_ita_Latn", "arc_it"], batch_size=8, device="cuda:0" ) # 打印评估结果表 print(evaluator.make_table(results))
内容的提问来源于stack exchange,提问作者Gabriele Monti
相关产品推荐
相关产品推荐

