Skip to content

Latest commit

 

History

History
 
 

xfinder_training

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

xFinder Scripts

This directory contains various scripts used in the xFinder project for robust and pinpoint answer extraction from LLMs.

Machine Environment

  • Operating System: Ubuntu
  • Package Manager: Anaconda
  • GPU: NVIDIA A100, 80GB

XTuner Installation

  • Prepare the Conda Environment
conda create --name xtuner-env python=3.10 -y
conda activate xtuner-env
  • Install XTuner via pip
pip install -U 'xtuner[deepspeed]'

Fine-tuning Dataset

The fine-tuning dataset for xFinder was derived by converting the training set of the KAF dataset into a format supported by xtuner. The final fine-tuning data is structured as follows:

{
    "system": "You are a help assistant tasked with extracting the precise key answer from given output sentences. You must only provide the extracted key answer without including any additional text.",
    "input": "I will provide you with a question, output sentences along with an answer range. The output sentences are the response of the question provided. The answer range could either describe the type of answer expected or list all possible valid answers. Using the information provided, you must accurately and precisely determine and extract the intended key answer from the output sentences. Please don't have your subjective thoughts about the question.\nFirst, you need to determine whether the content of the output sentences is relevant to the given question. If the entire output sentences are unrelated to the question (meaning the output sentences are not addressing the question), then output [No valid answer].\nOtherwise, ignore the parts of the output sentences that have no relevance to the question and then extract the key answer that matches the answer range.\nBelow are some special cases you need to be aware of: \n    (1) If the output sentences present multiple different answers, carefully determine if the later provided answer is a correction or modification of a previous one. If so, extract this corrected or modified answer as the final response. Conversely, if the output sentences fluctuate between multiple answers without a clear final answer, you should output [No valid answer].\n    (2) If the answer range is a list and the key answer in the output sentences is not explicitly listed among the candidate options in the answer range, also output [No valid answer].\n\nQuestion: \"\"\"Which statement correctly describes a physical characteristic of the Moon?  Answer Choices:  (A) The Moon is made of hot gases.  (B) The Moon is covered with many craters. (C) The Moon has many bodies of liquid water. (D) The Moon has the ability to give off its own light.\"\"\"\n\nOutput sentences: \"\"\"\n\nStep 1: Analyze the question and the given options.\nThe question is asking for a physical characteristic of the Moon.\n\nStep 2: Evaluate each option.\nOption (A) states that the Moon is made of hot gases, which is not a physical characteristic.\nOption (B) states that the Moon is covered with many craters, which is a physical characteristic.\nOption (C) states that the Moon has many bodies of liquid water, which is not a physical characteristic.\nOption (D) states that the Moon has the ability to give off its own light, which is not a physical characteristic.\n\nStep 3: Choose the correct option based on the evaluation.\nThe correct option is (B) The Moon is covered with many craters.\n\nFinal Answer: B. The Moon is covered with many craters.\"\"\"\n\nAnswer range: [['D', 'The Moon has the ability to give off its own light.'], ['C', 'The Moon has many bodies of liquid water.'], ['B', 'The Moon is covered with many craters.'], ['A', 'The Moon is made of hot gases.']]\n\nKey extracted answer: ",
    "output": "B"
}

XTuner Fine-tuning Config

The configuration files used to fine-tune different models to obtain xFinder are shown in the table below:

xFinder foundation model configuration file
xFinder-qwen1505 Qwen1.5-0.5B xFinder-qwen1505_qlora.py
xFinder-qwen1505chat Qwen1.5-0.5B-Chat xFinder-qwen1505chat_qlora.py
xFinder-qwen1518 Qwen1.5-1.8B xFinder-qwen1518_qlora.py
xFinder-qwen1518chat Qwen1.5-1.8B-Chat xFinder-qwen1518chat_qlora.py
xFinder-internlm218 InternLM2-1.8B xFinder-internlm218_qlora.py
xFinder-gemma2 Gemma-2B xFinder-gemma2_qlora.py
xFinder-gemma2it Gemma-2B-it xFinder-gemma2it_qlora.py
xFinder-qwen154 Qwen1.5-4B xFinder-qwen154_qlora.py
xFinder-qwen154chat Qwen1.5-4B-Chat xFinder-qwen154chat_qlora.py
xFinder-chatglm36base ChatGLM3-6B-base xFinder-chatglm36base_qlora.py
xFinder-chatglm36 ChatGLM3-6B xFinder-chatglm36_qlora.py
xFinder-qwen157 Qwen1.5-7B xFinder-qwen157_qlora.py
xFinder-qwen157chat Qwen1.5-7B-Chat xFinder-qwen157chat_qlora.py
xFinder-internlm27 InternLM2-7B xFinder-internlm27_qlora.py
xFinder-baichuan27chat Baichuan2-7B-Chat xFinder-baichuan27chat_qlora.py
xFinder-gemma7 Gemma-7B xFinder-gemma7_qlora.py
xFinder-gemma7it Gemma-7B-it xFinder-gemma7it_qlora.py
xFinder-llama38 Llama-3-8B xFinder-llama38_qlora.py
xFinder-llama38it Llama3-8B-Instruct xFinder-llama38it_qlora.py

Fine-tuning

Use the xtuner train command to start training.

CUDA_VISIBLE_DEVICES=0 xtuner train path/to/scripts/xtuner_config/xFinder-qwen1518_qlora.py --deepspeed deepspeed_zero2

Parameter conversion and merging after fine-tuning.

./xtuner_merge.sh -l /path/to/llm -a /path/to/adapter -m /path/to/merge/save