You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: end-to-end-use-cases/coding/text2sql/README.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,25 @@
1
1
# Improving Llama Text2SQL performance with CoT Fine-tuning
2
2
3
-
This recipe is step by step guide to improve Llama performance on Text2SQL measured with the popular [BIRD](https://bird-bench.github.io) benchmark. We generate synthetic Chain of Thought(CoT) dataset and fine-tune Llama models on it.
3
+
This recipe is step by step guide to improve Llama performance on Text2SQL measured with the popular [BIRD](https://bird-bench.github.io) benchmark. We generate a synthetic Chain of Thought(CoT) dataset and fine-tune Llama models on it.
1. Pre-processing the BIRD TRAIN datset by converting SQL statements into conversation format
14
+
1. Pre-processing the BIRD TRAIN datset by converting SQL statements into the conversation format.
10
15
11
-
2. We use the conversations from step 1, add CoT to these existing conversations using Llama-3.3-70B
16
+
2. We use the conversations from step 1, add CoT to these existing conversations using Llama-3.3-70B.
12
17
13
-
3. Fine-tuning Llama-3.1-8B on the dataset from step 2
18
+
3. Fine-tuning Llama-3.1-8B on the dataset from step 2.
14
19
15
-
4. We provide scripts to simplify running the [BIRD](https://bird-bench.github.io) benchmark on the fine-tuned models and compare it with out of the model.
20
+
4. We provide scripts to simplify running the [BIRD](https://bird-bench.github.io)eval benchmark on the fine-tuned models and compare it with out of the model.
16
21
17
-
## Structure:
22
+
## Folder Structure
18
23
19
24
- quickstart folder: contains a notebook to ask Llama 3.3 to convert natural language queries into SQL queries.
20
25
- data folder: contains scripts to download the BIRD TRAIN and DEV datasets;
Copy file name to clipboardExpand all lines: end-to-end-use-cases/coding/text2sql/eval/README.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,9 @@ Below are the results of the Llama models we have evaluated on the BIRD DEV data
17
17
18
18
## Quick Start with Llama Models via Llama API
19
19
20
-
First, run the commands below to create a new Conda environment and install all the required packages for Text2SQL evaluation and fine-tuning:
20
+
Follow the steps below to evaluate Llama 3 & 4 models on Text2SQL using the BIRD benchmark:
21
+
22
+
1. Run the commands below to create a new Conda environment and install all the required packages for Text2SQL evaluation:
21
23
22
24
```
23
25
conda create -n llama-text2sql python=3.10
@@ -28,18 +30,16 @@ cd llama-cookbook/end-to-end-use-cases/coding/text2sql/eval
28
30
pip install -r requirements.txt
29
31
```
30
32
31
-
Then, follow the steps below to evaluate Llama 3 & 4 models on Text2SQL using the BIRD benchmark:
32
-
33
-
1. Get the DEV dataset:
33
+
2. Get the DEV dataset:
34
34
```
35
35
cd ../data
36
36
sh download_dev_unzip.sh
37
37
cd ../eval
38
38
```
39
39
40
-
2. Open `llama_eval.sh` and set `YOUR_API_KEY` to your [Llama API](https://llama.developer.meta.com/) key then uncomment a line that starts with `model=` to specify the Llama model to use for the text2sql eval.
40
+
3. Open `llama_eval.sh` and set `YOUR_API_KEY` to your [Llama API](https://llama.developer.meta.com/) key then uncomment a line that starts with `model=` to specify the Llama model to use for the text2sql eval.
41
41
42
-
3. Run the evaluation script `sh llama_eval.sh`, which will use the BIRD DEV dataset (1534 examples in total) with external knowledge turned on to run the Llama model on each text question and compare the generated SQL with the gold SQL.
42
+
4. Run the evaluation script `sh llama_eval.sh`, which will use the BIRD DEV dataset (1534 examples in total) with external knowledge turned on to run the Llama model on each text question and compare the generated SQL with the gold SQL.
43
43
44
44
If your API key or model name is incorrect, the script will exit with an authentication or model not supported error.
Copy file name to clipboardExpand all lines: end-to-end-use-cases/coding/text2sql/fine-tuning/README.md
+83-29Lines changed: 83 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ This folder contains scripts to:
4
4
5
5
* generate a dataset from the BIRD TRAIN set (with no CoT info) for supervised fine-tuning (SFT);
6
6
* generate a dataset from the BIRD TRAIN set (with CoT info by Llama 3.3 70B) for SFT;
7
-
* SFT the Llama 3.1 8B model with the generated datasets with different fine-tuning combinations: with or without CoT, using quantization or not, full fine-tuning (FFT) or parameter-efficient fine-tuning (PEFT).
7
+
* SFT the Llama 3.1 8B model with the generated datasets with different fine-tuning combinations: with or without CoT, using quantization or not, full fine-tuning (FFT) or parameter-efficient fine-tuning (PEFT).
8
8
9
9
**Note:** CoT stands for Chain of Thought and we will use "CoT" and "reasoning" interchangeably here, although generally, reasoning encompasses a broader concept than CoT.
10
10
@@ -22,15 +22,92 @@ The eval results of SFT Llama 3.1 8B with different options (epochs is 3, with a
22
22
23
23
Using Quantization+PEFT on CoT dataset only dropped the accuracy from 43.35% to 42.89%.
24
24
25
-
## Creating dataset
25
+
## Quick Start with Fine-tuning Llama 3.1 8B
26
26
27
-
We use the BIRD TRAIN dataset to prepare for supervised fine-tuning with reasoning info in the dataset. The goal is to see if we can improve the accuracy of the fine-tuned model by adding the reasoning info in the dataset.
27
+
1. If you have already run the eval folder's Quick Start Step 1's commands [here](../eval/README.md#quick-start-with-llama-models-via-llama-api) to "create a new Conda environment and install all the required packages for Text2SQL evaluation", just run:
28
+
29
+
```
30
+
cd llama-cookbook/end-to-end-use-cases/coding/text2sql/fine-tuning
31
+
pip install -r requirements.txt
32
+
```
33
+
34
+
Otherwise, run the commands below to create a new Conda environment and install all the required packages for Text2SQL evaluation and fine-tuning:
### Creating a reasoning dataset from the TRAIN dataset
92
+
3. If you haven't downloaded the DEV dataset, download it and unzip it first:
93
+
94
+
```
95
+
cd ../data
96
+
sh download_dev_unzip.sh
97
+
cd ../eval
98
+
```
99
+
100
+
Then run `sh llama_eval.sh`.
101
+
102
+
**Note:** If your fine-tuned model is PEFT based, you may need to run `python merge_peft.py` after modifying its `peft_model_path` and `output_dir` and set the merged folder path after `vllm serve`.
103
+
104
+
## About Creating the CoT Dataset
105
+
106
+
We use the BIRD TRAIN dataset to prepare for supervised fine-tuning with reasoning info in the dataset. The goal is to see if we can improve the accuracy of the fine-tuned model by adding the reasoning info in the dataset.
30
107
31
108
The script `create_reasoning_dataset.py` is used to create a reasoning dataset from the TRAIN dataset by asking Llama 3.3 70B to generate the reasoning for each text question and its corresponding gold SQL. The intent is to use the reasoning dataset to fine-tune the Llama model to improve the accuracy of the generated SQL.
**Note:** If your fine-tuned model is PEFT based, you may need to run `python merge_peft.py` after modifying its `peft_model_path` and `output_dir` and set the merged folder path after `vllm serve`.
0 commit comments