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
@@ -26,8 +24,8 @@ LLM Finetuning toolkit is a config-based CLI tool for launching a series of LLM
26
24
### [Option 1] Docker (recommended)
27
25
28
26
```shell
29
-
docker build -t llm-toolkit
30
-
```
27
+
docker build -t llm-toolkit
28
+
```
31
29
32
30
#### CPU Only
33
31
@@ -63,29 +61,25 @@ See poetry documentation page for poetry [installation instructions](https://pyt
63
61
pip install -r requirements.txt
64
62
```
65
63
66
-
67
64
## Quick Start
68
65
69
66
This guide contains 3 stages that will enable you to get the most out of this toolkit!
70
67
71
-
*__Basic__: Run your first LLM fine-tuning experiment
72
-
*__Intermediate__: Run a custom experiment by changing the componenets of the YAML configuration file
73
-
*__Advanced__: Launch series of fine-tuning experiments across different prompt templates, LLMs, optimization techniques -- all through **one** YAML configuration file
74
-
68
+
-**Basic**: Run your first LLM fine-tuning experiment
69
+
-**Intermediate**: Run a custom experiment by changing the componenets of the YAML configuration file
70
+
-**Advanced**: Launch series of fine-tuning experiments across different prompt templates, LLMs, optimization techniques -- all through **one** YAML configuration file
75
71
76
-
77
-
### Basic
72
+
### Basic
78
73
79
74
```python
80
75
python toolkit.py --config ./config.yml
81
76
```
82
77
83
78
This command initiates the fine-tuning process using the settings specified in the default YAML configuration file `config.yaml`.
84
79
85
-
86
80
### Intermediate
87
81
88
-
The configuration file is the central piece that defines the behavior of the toolkit. It is written in YAML format and consists of several sections that control different aspects of the process, such as data ingestion, model definition, training, inference, and quality assurance. We highlight some of the critical sections.
82
+
The configuration file is the central piece that defines the behavior of the toolkit. It is written in YAML format and consists of several sections that control different aspects of the process, such as data ingestion, model definition, training, inference, and quality assurance. We highlight some of the critical sections.
89
83
90
84
#### Data Ingestion
91
85
@@ -99,14 +93,13 @@ data:
99
93
### Instruction: {instruction}
100
94
### Input: {input}
101
95
### Output:
102
-
prompt_stub:
103
-
{output}
96
+
prompt_stub: { output }
104
97
test_size: 0.1# Proportion of test as % of total; if integer then # of samples
105
98
train_size: 0.9# Proportion of train as % of total; if integer then # of samples
106
99
train_test_split_seed: 42
107
100
```
108
101
109
-
* While the above example illustrates using a public dataset from Hugging Face, the config file can also ingest your own data.
102
+
- While the above example illustrates using a public dataset from Hugging Face, the config file can also ingest your own data.
110
103
111
104
```yaml
112
105
file_type: "json"
@@ -118,13 +111,12 @@ data:
118
111
path: "<path to your data file>
119
112
```
120
113
121
-
* The prompt fields help create instructions to fine-tune the LLM on. It reads data from specific columns, mentioned in {} brackets, that are present in your dataset. In the example provided, it is expected for the data file to have column names: `instruction`, `input` and `output`.
122
-
123
-
* The prompt fields use both `prompt` and `prompt_stub` during fine-tuning. However, during testing, **only** the `prompt` section is used as input to the fine-tuned LLM.
114
+
- The prompt fields help create instructions to fine-tune the LLM on. It reads data from specific columns, mentioned in {} brackets, that are present in your dataset. In the example provided, it is expected for the data file to have column names: `instruction`, `input` and `output`.
124
115
116
+
- The prompt fields use both `prompt` and `prompt_stub` during fine-tuning. However, during testing, **only** the `prompt` section is used as input to the fine-tuned LLM.
125
117
126
118
#### LLM Definition
127
-
119
+
128
120
```yaml
129
121
model:
130
122
hf_model_ckpt: "NousResearch/Llama-2-7b-hf"
@@ -149,60 +141,59 @@ lora:
149
141
- gate_proj
150
142
```
151
143
152
-
* While the above example showcases using Llama2 7B, in theory, any open-source LLM supported by Hugging Face can be used in this toolkit.
144
+
- While the above example showcases using Llama2 7B, in theory, any open-source LLM supported by Hugging Face can be used in this toolkit.
153
145
154
146
```yaml
155
-
hf_model_ckpt: "mistralai/Mistral-7B-v0.1"
147
+
hf_model_ckpt: "mistralai/Mistral-7B-v0.1"
156
148
```
157
149
158
150
```yaml
159
-
hf_model_ckpt: "tiiuae/falcon-7b"
151
+
hf_model_ckpt: "tiiuae/falcon-7b"
160
152
```
161
153
162
-
* The parameters for LoRA, such as the rank `r` and dropout, can be altered.
154
+
- The parameters for LoRA, such as the rank `r` and dropout, can be altered.
163
155
164
156
```yaml
165
-
lora:
166
-
r: 64
167
-
lora_dropout: 0.25
157
+
lora:
158
+
r: 64
159
+
lora_dropout: 0.25
168
160
```
169
-
161
+
170
162
#### Quality Assurance
171
163
172
164
```yaml
173
165
qa:
174
166
llm_tests:
175
-
- length_test
167
+
- length_test
176
168
- word_overlap_test
177
169
```
178
170
179
-
* To ensure that the fine-tuned LLM behaves as expected, you can add tests that check if the desired behaviour is being attained. Example: for an LLM fine-tuned for a summarization task, we may want to check if the generated summary is indeed smaller in length than the input text. We would also like to learn the overlap between words in the original text and generated summary.
180
-
171
+
- To ensure that the fine-tuned LLM behaves as expected, you can add tests that check if the desired behaviour is being attained. Example: for an LLM fine-tuned for a summarization task, we may want to check if the generated summary is indeed smaller in length than the input text. We would also like to learn the overlap between words in the original text and generated summary.
181
172
182
173
#### Artifact Outputs
183
174
184
175
This config will run finetuning and save the results under directory `./experiment/[unique_hash]`. Each unique configuration will generate a unique hash, so that our tool can automatically pick up where it left off. For example, if you need to exit in the middle of the training, by relaunching the script, the program will automatically load the existing dataset that has been generated under the directory, instead of doing it all over again.
185
176
186
177
After the script finishes running you will see these distinct artifacts:
178
+
187
179
```shell
188
180
/dataset # generated pkl file in hf datasets format
189
181
/model # peft model weights in hf format
190
182
/results # csv of prompt, ground truth, and predicted values
191
183
/qa # csv of test results: e.g. vector similarity between ground truth and prediction
192
184
```
193
185
194
-
Once all the changes have been incorporated in the YAML file, you can simply use it to run a custom fine-tuning experiment!
186
+
Once all the changes have been incorporated in the YAML file, you can simply use it to run a custom fine-tuning experiment!
195
187
196
188
```python
197
-
python toolkit.py --config <path to custom YAML file>
189
+
python toolkit.py --config-path <path to custom YAML file>
198
190
```
199
191
200
-
### Advanced
201
-
192
+
### Advanced
202
193
203
194
Fine-tuning workflows typically involve running ablation studies across various LLMs, prompt designs and optimization techniques. The configuration file can be altered to support running ablation studies.
204
195
205
-
* Specify different prompt templates to experiment with while fine-tuning.
196
+
-Specify different prompt templates to experiment with while fine-tuning.
206
197
207
198
```yaml
208
199
data:
@@ -212,55 +203,55 @@ data:
212
203
- >-
213
204
This is the first prompt template to iterate over
214
205
### Input: {input}
215
-
### Output:
206
+
### Output:
216
207
- >-
217
208
This is the second prompt template
218
209
### Instruction: {instruction}
219
210
### Input: {input}
220
211
### Output:
221
-
prompt_stub:
222
-
{output}
212
+
prompt_stub: { output }
223
213
test_size: 0.1 # Proportion of test as % of total; if integer then # of samples
224
214
train_size: 0.9 # Proportion of train as % of total; if integer then # of samples
225
215
train_test_split_seed: 42
226
216
```
227
217
228
-
229
-
* Specify various LLMs that you would like to experiment with.
218
+
- Specify various LLMs that you would like to experiment with.
* Specify different configurations of LoRA that you would like to ablate over.
235
+
-Specify different configurations of LoRA that you would like to ablate over.
242
236
243
237
```yaml
244
-
lora:
245
-
r: [16, 32, 64]
246
-
lora_dropout: [0.25, 0.50]
238
+
lora:
239
+
r: [16, 32, 64]
240
+
lora_dropout: [0.25, 0.50]
247
241
```
248
242
249
243
## Extending
250
244
251
245
The toolkit provides a modular and extensible architecture that allows developers to customize and enhance its functionality to suit their specific needs. Each component of the toolkit, such as data ingestion, finetuning, inference, and quality assurance testing, is designed to be easily extendable.
252
246
253
-
254
247
## Contributing
255
248
256
249
If you would like to contribute to this project, we recommend following the "fork-and-pull" Git workflow.
257
250
258
-
1. **Fork** the repo on GitHub
259
-
2. **Clone** the project to your own machine
260
-
3. **Commit** changes to your own branch
261
-
4. **Push** your work back up to your fork
262
-
5. Submit a **Pull request** so that we can review your changes
251
+
1. **Fork** the repo on GitHub
252
+
2. **Clone** the project to your own machine
253
+
3. **Commit** changes to your own branch
254
+
4. **Push** your work back up to your fork
255
+
5. Submit a **Pull request** so that we can review your changes
263
256
264
257
NOTE: Be sure to merge the latest from "upstream" before making a pull request!
0 commit comments