notebooks/ceval_example_for_chinese_alpaca.ipynb
教程分为三部分:
机器选择:此处使用A100进行预测(实际7B模型用V100应该也是可以的)。
!nvidia-smi
这里不再一一介绍流程,感兴趣的可以去看另一个Colab Notebook:https://colab.research.google.com/drive/1FnFkyKhrnS7s-2lDDeous-AutdI_SkAd?usp=sharing
!pip install torch==1.13.1
!pip install transformers==4.30.2
!pip install peft==0.3.0
!pip install sentencepiece
!git clone https://github.com/ymcui/Chinese-LLaMA-Alpaca
!python ./Chinese-LLaMA-Alpaca/scripts/merge_llama_with_chinese_lora_low_mem.py \
--base_model elinas/llama-7b-hf-transformers-4.29 \
--lora_model ziqingyang/chinese-llama-plus-lora-7b,ziqingyang/chinese-alpaca-plus-lora-7b \
--output_type huggingface \
--output_dir alpaca-combined-hf
相关教程:
!cd ./Chinese-LLaMA-Alpaca/scripts/ceval && wget https://huggingface.co/datasets/ceval/ceval-exam/resolve/main/ceval-exam.zip && mkdir data && unzip ceval-exam.zip -d data
!ls ./Chinese-LLaMA-Alpaca/scripts/ceval/data
!cd ./Chinese-LLaMA-Alpaca/scripts/ceval && CUDA_VISIBLE_DEVICES=0 python eval.py \
--model_path /content/alpaca-combined-hf \
--cot False \
--few_shot False \
--with_prompt True \
--constrained_decoding True \
--temperature 0.2 \
--n_times 1 \
--ntrain 5 \
--do_save_csv False \
--do_test False \
--output_dir /content/ceval-output
运行以下命令查看最终结果,json最后的ALL里会显示,这一次运行结果是:
"All": {
"score": 0.36701337295690933,
"num": 1346,
"correct": 494.0
}
上述结果与我们论文中汇报的zero-shot 36.7(%)一致。需要注意的是解码存在随机性,如果希望多次运行可将n_times改为需要运行的次数。
!cat ./ceval-output/take0/summary.json