Text Generation
Transformers
Safetensors
mistral
conversational
text-generation-inference
4-bit precision
awq
TheBloke commited on
Commit
22b49e8
1 Parent(s): 0da5aae

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +706 -0
README.md ADDED
@@ -0,0 +1,706 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: jondurbin/bagel-dpo-7b-v0.1
3
+ datasets:
4
+ - ai2_arc
5
+ - unalignment/spicy-3.1
6
+ - codeparrot/apps
7
+ - facebook/belebele
8
+ - boolq
9
+ - jondurbin/cinematika-v0.1
10
+ - drop
11
+ - lmsys/lmsys-chat-1m
12
+ - TIGER-Lab/MathInstruct
13
+ - cais/mmlu
14
+ - Muennighoff/natural-instructions
15
+ - openbookqa
16
+ - piqa
17
+ - Vezora/Tested-22k-Python-Alpaca
18
+ - cakiki/rosetta-code
19
+ - Open-Orca/SlimOrca
20
+ - spider
21
+ - squad_v2
22
+ - migtissera/Synthia-v1.3
23
+ - datasets/winogrande
24
+ - nvidia/HelpSteer
25
+ - Intel/orca_dpo_pairs
26
+ - unalignment/toxic-dpo-v0.1
27
+ - jondurbin/truthy-dpo-v0.1
28
+ - allenai/ultrafeedback_binarized_cleaned
29
+ inference: false
30
+ license: apache-2.0
31
+ model_creator: Jon Durbin
32
+ model_name: Bagel DPO 7B v0.1
33
+ model_type: mistral
34
+ prompt_template: 'Below is an instruction that describes a task. Write a response
35
+ that appropriately completes the request.
36
+
37
+
38
+ ### Instruction:
39
+
40
+ {prompt}
41
+
42
+
43
+ ### Response:
44
+
45
+ '
46
+ quantized_by: TheBloke
47
+ ---
48
+ <!-- markdownlint-disable MD041 -->
49
+
50
+ <!-- header start -->
51
+ <!-- 200823 -->
52
+ <div style="width: auto; margin-left: auto; margin-right: auto">
53
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
54
+ </div>
55
+ <div style="display: flex; justify-content: space-between; width: 100%;">
56
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
57
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
58
+ </div>
59
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
60
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
61
+ </div>
62
+ </div>
63
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
64
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
65
+ <!-- header end -->
66
+
67
+ # Bagel DPO 7B v0.1 - AWQ
68
+ - Model creator: [Jon Durbin](https://huggingface.co/jondurbin)
69
+ - Original model: [Bagel DPO 7B v0.1](https://huggingface.co/jondurbin/bagel-dpo-7b-v0.1)
70
+
71
+ <!-- description start -->
72
+ ## Description
73
+
74
+ This repo contains AWQ model files for [Jon Durbin's Bagel DPO 7B v0.1](https://huggingface.co/jondurbin/bagel-dpo-7b-v0.1).
75
+
76
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
77
+
78
+
79
+ ### About AWQ
80
+
81
+ AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference with equivalent or better quality compared to the most commonly used GPTQ settings.
82
+
83
+ AWQ models are currently supported on Linux and Windows, with NVidia GPUs only. macOS users: please use GGUF models instead.
84
+
85
+ It is supported by:
86
+
87
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
88
+ - [vLLM](https://github.com/vllm-project/vllm) - version 0.2.2 or later for support for all model types.
89
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
90
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later, from any code or client that supports Transformers
91
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
92
+
93
+ <!-- description end -->
94
+ <!-- repositories-available start -->
95
+ ## Repositories available
96
+
97
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-AWQ)
98
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ)
99
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GGUF)
100
+ * [Jon Durbin's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/jondurbin/bagel-dpo-7b-v0.1)
101
+ <!-- repositories-available end -->
102
+
103
+ <!-- prompt-template start -->
104
+ ## Prompt template: Alpaca
105
+
106
+ ```
107
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
108
+
109
+ ### Instruction:
110
+ {prompt}
111
+
112
+ ### Response:
113
+
114
+ ```
115
+
116
+ <!-- prompt-template end -->
117
+
118
+
119
+ <!-- README_AWQ.md-provided-files start -->
120
+ ## Provided files, and AWQ parameters
121
+
122
+ I currently release 128g GEMM models only. The addition of group_size 32 models, and GEMV kernel models, is being actively considered.
123
+
124
+ Models are released as sharded safetensors files.
125
+
126
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
127
+ | ------ | ---- | -- | ----------- | ------- | ---- |
128
+ | [main](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-AWQ/tree/main) | 4 | 128 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 4.15 GB
129
+
130
+ <!-- README_AWQ.md-provided-files end -->
131
+
132
+ <!-- README_AWQ.md-text-generation-webui start -->
133
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
134
+
135
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
136
+
137
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
138
+
139
+ 1. Click the **Model tab**.
140
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/bagel-dpo-7B-v0.1-AWQ`.
141
+ 3. Click **Download**.
142
+ 4. The model will start downloading. Once it's finished it will say "Done".
143
+ 5. In the top left, click the refresh icon next to **Model**.
144
+ 6. In the **Model** dropdown, choose the model you just downloaded: `bagel-dpo-7B-v0.1-AWQ`
145
+ 7. Select **Loader: AutoAWQ**.
146
+ 8. Click Load, and the model will load and is now ready for use.
147
+ 9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
148
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
149
+ <!-- README_AWQ.md-text-generation-webui end -->
150
+
151
+ <!-- README_AWQ.md-use-from-vllm start -->
152
+ ## Multi-user inference server: vLLM
153
+
154
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
155
+
156
+ - Please ensure you are using vLLM version 0.2 or later.
157
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
158
+
159
+ For example:
160
+
161
+ ```shell
162
+ python3 -m vllm.entrypoints.api_server --model TheBloke/bagel-dpo-7B-v0.1-AWQ --quantization awq --dtype auto
163
+ ```
164
+
165
+ - When using vLLM from Python code, again set `quantization=awq`.
166
+
167
+ For example:
168
+
169
+ ```python
170
+ from vllm import LLM, SamplingParams
171
+
172
+ prompts = [
173
+ "Tell me about AI",
174
+ "Write a story about llamas",
175
+ "What is 291 - 150?",
176
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
177
+ ]
178
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
179
+
180
+ ### Instruction:
181
+ {prompt}
182
+
183
+ ### Response:
184
+ '''
185
+
186
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
187
+
188
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
189
+
190
+ llm = LLM(model="TheBloke/bagel-dpo-7B-v0.1-AWQ", quantization="awq", dtype="auto")
191
+
192
+ outputs = llm.generate(prompts, sampling_params)
193
+
194
+ # Print the outputs.
195
+ for output in outputs:
196
+ prompt = output.prompt
197
+ generated_text = output.outputs[0].text
198
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
199
+ ```
200
+ <!-- README_AWQ.md-use-from-vllm start -->
201
+
202
+ <!-- README_AWQ.md-use-from-tgi start -->
203
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
204
+
205
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
206
+
207
+ Example Docker parameters:
208
+
209
+ ```shell
210
+ --model-id TheBloke/bagel-dpo-7B-v0.1-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
211
+ ```
212
+
213
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
214
+
215
+ ```shell
216
+ pip3 install huggingface-hub
217
+ ```
218
+
219
+ ```python
220
+ from huggingface_hub import InferenceClient
221
+
222
+ endpoint_url = "https://your-endpoint-url-here"
223
+
224
+ prompt = "Tell me about AI"
225
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
226
+
227
+ ### Instruction:
228
+ {prompt}
229
+
230
+ ### Response:
231
+ '''
232
+
233
+ client = InferenceClient(endpoint_url)
234
+ response = client.text_generation(prompt,
235
+ max_new_tokens=128,
236
+ do_sample=True,
237
+ temperature=0.7,
238
+ top_p=0.95,
239
+ top_k=40,
240
+ repetition_penalty=1.1)
241
+
242
+ print(f"Model output: ", response)
243
+ ```
244
+ <!-- README_AWQ.md-use-from-tgi end -->
245
+
246
+ <!-- README_AWQ.md-use-from-python start -->
247
+ ## Inference from Python code using Transformers
248
+
249
+ ### Install the necessary packages
250
+
251
+ - Requires: [Transformers](https://huggingface.co/docs/transformers) 4.35.0 or later.
252
+ - Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.6 or later.
253
+
254
+ ```shell
255
+ pip3 install --upgrade "autoawq>=0.1.6" "transformers>=4.35.0"
256
+ ```
257
+
258
+ Note that if you are using PyTorch 2.0.1, the above AutoAWQ command will automatically upgrade you to PyTorch 2.1.0.
259
+
260
+ If you are using CUDA 11.8 and wish to continue using PyTorch 2.0.1, instead run this command:
261
+
262
+ ```shell
263
+ pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl
264
+ ```
265
+
266
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
267
+
268
+ ```shell
269
+ pip3 uninstall -y autoawq
270
+ git clone https://github.com/casper-hansen/AutoAWQ
271
+ cd AutoAWQ
272
+ pip3 install .
273
+ ```
274
+
275
+ ### Transformers example code (requires Transformers 4.35.0 and later)
276
+
277
+ ```python
278
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
279
+
280
+ model_name_or_path = "TheBloke/bagel-dpo-7B-v0.1-AWQ"
281
+
282
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
283
+ model = AutoModelForCausalLM.from_pretrained(
284
+ model_name_or_path,
285
+ low_cpu_mem_usage=True,
286
+ device_map="cuda:0"
287
+ )
288
+
289
+ # Using the text streamer to stream output one token at a time
290
+ streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
291
+
292
+ prompt = "Tell me about AI"
293
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
294
+
295
+ ### Instruction:
296
+ {prompt}
297
+
298
+ ### Response:
299
+ '''
300
+
301
+ # Convert prompt to tokens
302
+ tokens = tokenizer(
303
+ prompt_template,
304
+ return_tensors='pt'
305
+ ).input_ids.cuda()
306
+
307
+ generation_params = {
308
+ "do_sample": True,
309
+ "temperature": 0.7,
310
+ "top_p": 0.95,
311
+ "top_k": 40,
312
+ "max_new_tokens": 512,
313
+ "repetition_penalty": 1.1
314
+ }
315
+
316
+ # Generate streamed output, visible one token at a time
317
+ generation_output = model.generate(
318
+ tokens,
319
+ streamer=streamer,
320
+ **generation_params
321
+ )
322
+
323
+ # Generation without a streamer, which will include the prompt in the output
324
+ generation_output = model.generate(
325
+ tokens,
326
+ **generation_params
327
+ )
328
+
329
+ # Get the tokens from the output, decode them, print them
330
+ token_output = generation_output[0]
331
+ text_output = tokenizer.decode(token_output)
332
+ print("model.generate output: ", text_output)
333
+
334
+ # Inference is also possible via Transformers' pipeline
335
+ from transformers import pipeline
336
+
337
+ pipe = pipeline(
338
+ "text-generation",
339
+ model=model,
340
+ tokenizer=tokenizer,
341
+ **generation_params
342
+ )
343
+
344
+ pipe_output = pipe(prompt_template)[0]['generated_text']
345
+ print("pipeline output: ", pipe_output)
346
+
347
+ ```
348
+ <!-- README_AWQ.md-use-from-python end -->
349
+
350
+ <!-- README_AWQ.md-compatibility start -->
351
+ ## Compatibility
352
+
353
+ The files provided are tested to work with:
354
+
355
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
356
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
357
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
358
+ - [Transformers](https://huggingface.co/docs/transformers) version 4.35.0 and later.
359
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
360
+
361
+ <!-- README_AWQ.md-compatibility end -->
362
+
363
+ <!-- footer start -->
364
+ <!-- 200823 -->
365
+ ## Discord
366
+
367
+ For further support, and discussions on these models and AI in general, join us at:
368
+
369
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
370
+
371
+ ## Thanks, and how to contribute
372
+
373
+ Thanks to the [chirper.ai](https://chirper.ai) team!
374
+
375
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
376
+
377
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
378
+
379
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
380
+
381
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
382
+
383
+ * Patreon: https://patreon.com/TheBlokeAI
384
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
385
+
386
+ **Special thanks to**: Aemon Algiz.
387
+
388
+ **Patreon special mentions**: Michael Levine, 阿明, Trailburnt, Nikolai Manek, John Detwiler, Randy H, Will Dee, Sebastain Graf, NimbleBox.ai, Eugene Pentland, Emad Mostaque, Ai Maven, Jim Angel, Jeff Scroggin, Michael Davis, Manuel Alberto Morcote, Stephen Murray, Robert, Justin Joy, Luke @flexchar, Brandon Frisco, Elijah Stavena, S_X, Dan Guido, Undi ., Komninos Chatzipapas, Shadi, theTransient, Lone Striker, Raven Klaugh, jjj, Cap'n Zoog, Michel-Marie MAUDET (LINAGORA), Matthew Berman, David, Fen Risland, Omer Bin Jawed, Luke Pendergrass, Kalila, OG, Erik Bjäreholt, Rooh Singh, Joseph William Delisle, Dan Lewis, TL, John Villwock, AzureBlack, Brad, Pedro Madruga, Caitlyn Gatomon, K, jinyuan sun, Mano Prime, Alex, Jeffrey Morgan, Alicia Loh, Illia Dulskyi, Chadd, transmissions 11, fincy, Rainer Wilmers, ReadyPlayerEmma, knownsqashed, Mandus, biorpg, Deo Leter, Brandon Phillips, SuperWojo, Sean Connelly, Iucharbius, Jack West, Harry Royden McLaughlin, Nicholas, terasurfer, Vitor Caleffi, Duane Dunston, Johann-Peter Hartmann, David Ziegler, Olakabola, Ken Nordquist, Trenton Dambrowitz, Tom X Nguyen, Vadim, Ajan Kanaga, Leonard Tan, Clay Pascal, Alexandros Triantafyllidis, JM33133, Xule, vamX, ya boyyy, subjectnull, Talal Aujan, Alps Aficionado, wassieverse, Ari Malik, James Bentley, Woland, Spencer Kim, Michael Dempsey, Fred von Graf, Elle, zynix, William Richards, Stanislav Ovsiannikov, Edmond Seymore, Jonathan Leane, Martin Kemka, usrbinkat, Enrico Ros
389
+
390
+
391
+ Thank you to all my generous patrons and donaters!
392
+
393
+ And thank you again to a16z for their generous grant.
394
+
395
+ <!-- footer end -->
396
+
397
+ # Original model card: Jon Durbin's Bagel DPO 7B v0.1
398
+
399
+
400
+ # A bagel, with everything
401
+
402
+ ![bagel](bagel.png)
403
+
404
+ ## Overview
405
+
406
+ This is the DPO'd version of https://huggingface.co/jondurbin/bagel-7b-v0.1
407
+
408
+ If you are getting too many AALLM or other refusals, even with explicitly human system prompts, you may want to try the non-DPO version.
409
+
410
+ ## Benchmarks
411
+
412
+ I ran these against the latest main branch of lm-evaluation-harness (and opencompass/FastChat for agieval and mt-bench), since batch size/etc effects score for some benchmarks.
413
+
414
+ | model | arc_challenge | boolq | gsm8k | hellaswag | mmlu | openbookqa | piqa | truthful_qa | winogrande |
415
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
416
+ | bagel | __0.6715__ | 0.8813 | __0.5618__ | 0.8397 | __0.6408__ | __0.51__ | __0.8406__ | __0.6275__ | __0.7561__ |
417
+ | openhermes-2.5 | 0.6476 | __0.8835__ | 0.4852 | __0.8414__ | 0.6347 | 0.498 | 0.8400 | 0.5295 | 0.7443 |
418
+
419
+
420
+ MT-Bench:
421
+ ```
422
+ ########## First turn ##########
423
+ score
424
+ model turn
425
+ bagel-7b-v0.1 1 7.60625
426
+
427
+ ########## Second turn ##########
428
+ score
429
+ model turn
430
+ bagel-7b-v0.1 2 7.00625
431
+
432
+ ########## Average ##########
433
+ score
434
+ model
435
+ bagel-7b-v0.1 7.30625
436
+ ```
437
+
438
+ ## Data selection.
439
+
440
+ The first step in the process is creating a dataset.
441
+ In this case, we're actually creating a composite dataset, consisting of both supervised fine-tuning data (SFT) and direct preference optimization (DPO) data.
442
+
443
+ All instruction data, that is, data that is not plain text (like project Gutenberg and items from Cinematika) or DPO, is converted into ShareGPT format so it's easier to work with.
444
+
445
+ See the corresponding code in `bagel/data_sources/*.py` for full implementation for each data source.
446
+
447
+ Deduplication is done by creating a uuid v5 of the instruction/text, then only adding items not previously seen (where datasets are loaded in order of the confidence score I assign them).
448
+ This means that if an instruction is in data source "Foo" with confidence 4 as well as in data source "Bar" with confidence score 2, only the entry from "Foo" will be taken.
449
+
450
+ ### SFT data sources
451
+
452
+ *Yes, you will see benchmark names in the list, but this only uses the train splits, and a decontamination by cosine similarity is performed at the end as a sanity check*
453
+
454
+ - [ai2_arc](https://huggingface.co/datasets/ai2_arc)
455
+ - Abstraction and reasoning dataset, useful in measuring "intelligence" to a certain extent.
456
+ - [airoboros](https://huggingface.co/datasets/unalignment/spicy-3.1)
457
+ - Variety of categories of synthetic instructions generated by gpt-4.
458
+ - [apps](https://huggingface.co/datasets/codeparrot/apps)
459
+ - Python coding dataset with 10k problems.
460
+ - [belebele](https://huggingface.co/datasets/facebook/belebele)
461
+ - Multi-lingual reading comprehension dataset.
462
+ - [boolq](https://huggingface.co/datasets/boolq)
463
+ - Corpus of yes/no questions (which can be surprisingly difficult for AI to answer apparently?)
464
+ - [cinematika](https://huggingface.co/datasets/jondurbin/cinematika-v0.1) (instruction and plain text)
465
+ - RP-style data synthesized from movie scripts so the model isn't quite as boring as it otherwise would be.
466
+ - [drop](https://huggingface.co/datasets/drop)
467
+ - More reading comprehension.
468
+ - [gutenberg](https://www.gutenberg.org/) (plain text)
469
+ - Books/plain text, again to make the model less boring, only a handful of examples supported by [chapterize](https://github.com/JonathanReeve/chapterize)
470
+ - [lmsys_chat_1m](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) (only gpt-4 items, also used for DPO)
471
+ - Chats collected by the lmsys chat arena, containing a wide variety of chats with various models.
472
+ - [mathinstruct](https://huggingface.co/datasets/TIGER-Lab/MathInstruct)
473
+ - Composite dataset with a variety of math-related tasks and problem/question formats.
474
+ - [mmlu](https://huggingface.co/datasets/cais/mmlu)
475
+ - Massive Multitask Language Understanding - a wide variety of questions about various subject matters.
476
+ - [natural_instructions](https://huggingface.co/datasets/Muennighoff/natural-instructions)
477
+ - Millions of instructions from 1600+ task categories (sampled down substantially, stratified by task type)
478
+ - [openbookqa](https://huggingface.co/datasets/openbookqa)
479
+ - Question answering dataset.
480
+ - [piqa](https://huggingface.co/datasets/piqa)
481
+ - Phyiscal interaction question answering.
482
+ - [python_alpaca](https://huggingface.co/datasets/Vezora/Tested-22k-Python-Alpaca)
483
+ - Python instruction response pairs, validated as functional.
484
+ - [rosetta_code](https://huggingface.co/datasets/cakiki/rosetta-code)
485
+ - Code problems and solutions in a variety of programming languages taken from rosettacode.org.
486
+ - [slimorca](https://huggingface.co/datasets/Open-Orca/SlimOrca)
487
+ - Collection of ~500k gpt-4 verified chats from OpenOrca.
488
+ - [spider](https://huggingface.co/datasets/spider)
489
+ - SQL-targeted dataset.
490
+ - [squad_v2](https://huggingface.co/datasets/squad_v2)
491
+ - Contextual question answering (RAG).
492
+ - [synthia](https://huggingface.co/datasets/migtissera/Synthia-v1.3)
493
+ - GPT-4 generated data using advanced prompting from Migel Tissera.
494
+ - [winogrande](https://huggingface.co/datasets/winogrande)
495
+ - Fill in the blank style prompts.
496
+
497
+ ### DPO data sources
498
+ - [airoboros 3.1](https://huggingface.co/datasets/unalignment/spicy-3.1) vs [airoboros 2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-gpt4-1.4.1)
499
+ - The creative/writing tasks from airoboros-2.2.1 were re-generated using gpt4-0314 and a custom prompt to get longer, more creative, less clichè responses for airoboros 3.1, so we can use the shorter/boring version as the "rejected" value and the rerolled response as "chosen"
500
+ - [helpsteer](https://huggingface.co/datasets/nvidia/HelpSteer)
501
+ - Really neat dataset provided by the folks at NVidia with human annotation across a variety of metrics. Only items with the highest "correctness" value were used for DPO here, with the highest scoring output as "chosen" and random lower scoring value as "rejected"
502
+ - [orca_dpo_pairs](https://huggingface.co/datasets/Intel/orca_dpo_pairs)
503
+ - Another interesting dataset by Intel, which provides various DPO pairs generated from prompts included in the SlimOrca dataset.
504
+ - [toxic-dpo](https://huggingface.co/datasets/unalignment/toxic-dpo-v0.1)
505
+ - __*highly toxic and potentially illegal content!*__ De-censorship, for academic and lawful purposes only, of course. Generated by llama-2-70b via prompt engineering.
506
+ - [truthy](https://huggingface.co/datasets/jondurbin/truthy-dpo-v0.1)
507
+ - DPO pairs meant to increase truthfulness of the model, e.g. common misconceptions, differentiate between AI assistants and roleplayed human in terms of corporeal awareness/locality/etc.
508
+ - [ultrafeedback](https://huggingface.co/datasets/allenai/ultrafeedback_binarized_cleaned)
509
+ - One of the bits of magic behind the Zephyr model. Only the items with a chosen score of 8 or higher were included.
510
+
511
+ Only the train splits were used (if a split was provided), and an additional pass of decontamination is performed using approximate nearest neighbor search (via faiss).
512
+
513
+ ### Total dataset size
514
+
515
+ The deduplicated and decontamined list of instructions contains 1,671,822 items:
516
+
517
+ - 1,602,217 SFT/instructions
518
+ - 59,247 DPO pairs
519
+ - 1606 with both SFT and DPO data
520
+
521
+ Keep in mind, this number becomes 4x larger when applying the various prompt formats.
522
+
523
+ ## Prompt formatting
524
+
525
+ In sticking with the theme of the bagel, I didn't want to use a single prompt format, so I used 4 - vicuna, llama-2, alpaca, and chat-ml (sorta).
526
+ I also didn't want to randomly select a single prompt format for each item (hoping each instruction would generalize more when used in a variety of prompt formats), so each instruction is actually converted into every prompt format.
527
+
528
+ This means each epoch of our fine-tune is really basically 4 epochs. So, for the fine-tunes, I would recommend only doing 1 epoch (or 0.75 epochs). I am testing with a single epoch using a relatively low learning rate.
529
+
530
+ ### Alpaca (sort of)
531
+
532
+ ```
533
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
534
+
535
+ ### Instruction:
536
+ {system prompt, if provided}
537
+ {instruction}
538
+
539
+ ### Response:
540
+ ```
541
+
542
+ The main difference here is that because of the dataset formatting and variety of data sources, it would have been much to tedious to add an `### Input:` block, so the inputs are just in the instruction section.
543
+
544
+ ### Vicuna
545
+
546
+ ```
547
+ {system prompt, if provided, randomly defaulting to "A chat between a user and an unbiased, uncensored assistant."}
548
+ USER: {instruction}
549
+ ASSISTANT:
550
+ ```
551
+
552
+ ### ChatML (sort of)
553
+
554
+ I don't really understand the point of having special tokens for `<|im_start|>` and `<|im_end|>`, because in practice they just act as BOS and EOS tokens (but, please correct me if I'm wrong).
555
+
556
+ So, instead of:
557
+ ```text
558
+ {bos}<|im_start|>{role}
559
+ {text}
560
+ <|im_end|>{eos}
561
+ ```
562
+
563
+ I just changed it to:
564
+ ```text
565
+ {bos}{role}
566
+ {text}
567
+ {eos}
568
+ ```
569
+
570
+ In practice, this would mean tokenization code like such:
571
+ ```python
572
+ tokenizer = AutoTokenizer.from_pretrained('mistralai/mistral-7b-v0.1')
573
+
574
+ input_str = f"""system
575
+ You are a goat.
576
+ {tokenizer.eos_token}
577
+ {tokenizer.bos_token}user
578
+ Tell me how to fry an egg.
579
+ {tokenizer.eos_token}
580
+ {tokenizer.bos_token}assistant
581
+ """
582
+
583
+ inputs = tokenizer(input_str, return_tensors="pt")
584
+ ```
585
+
586
+ If you *really* want to use `<|im_start|>` and `<|im_end|>`, just update your `tokenizer_config.json` to use `<|im_start|>` instead of `<s>` and `<|im_end|>` instead of `</s>` and when tokenizing. And if you still don't like what I've done to this chat-ml-ish format, feel free to cry into your pillow or fork the code and do a new fine-tune.
587
+
588
+ ### Llama-2 chat
589
+
590
+ ```
591
+ [INST] <<SYS>>
592
+ {system}
593
+ <</SYS>>
594
+
595
+ {instruction} [/INST]
596
+ ```
597
+
598
+ ## Fine tuning
599
+
600
+ ### SFT phase
601
+
602
+ An example for mistral-7b:
603
+
604
+ *Note: I actually used my fork of [qlora](https://github.com/jondurbin/qlora)'s `train.py` for this, but I'm porting it to a minified version here, not tested yet!*
605
+
606
+ *More notes: I stopped the SFT phase around 50% because of budget constraints.*
607
+
608
+ ```bash
609
+ export BASE_DIR=/workspace
610
+ export WANDB_API_KEY=[redacted]
611
+ export WANDB_PROJECT=bagel-7b-v0.1
612
+
613
+ # Run the pretraining.
614
+ accelerate launch bagel/tune/sft.py \
615
+ --model_name_or_path $BASE_DIR/mistral-7b \
616
+ --final_output_dir $BASE_DIR/$WANDB_PROJECT \
617
+ --output_dir $BASE_DIR/$WANDB_PROJECT-workdir \
618
+ --num_train_epochs 1 \
619
+ --logging_steps 1 \
620
+ --save_strategy steps \
621
+ --save_steps 200 \
622
+ --save_total_limit 5 \
623
+ --data_seed 42 \
624
+ --evaluation_strategy steps \
625
+ --eval_dataset_size 0.0006 \
626
+ --eval_steps 200 \
627
+ --max_new_tokens 4096 \
628
+ --dataloader_num_workers 3 \
629
+ --logging_strategy steps \
630
+ --remove_unused_columns False \
631
+ --do_train \
632
+ --full_finetune \
633
+ --bf16 \
634
+ --bits 16 \
635
+ --optim adamw_torch \
636
+ --lr_scheduler_type linear \
637
+ --dataset $BASE_DIR/bagel/bagel-input-output-v0.1.parquet \
638
+ --dataset_format input-output \
639
+ --model_max_len 4096 \
640
+ --per_device_train_batch_size 8 \
641
+ --learning_rate 3.5e-7 \
642
+ --warmup_ratio 0.005 \
643
+ --adam_beta2 0.999 \
644
+ --max_grad_norm 0.3 \
645
+ --weight_decay 0.001 \
646
+ --seed 42 \
647
+ --report_to wandb \
648
+ --gradient_checkpointing True \
649
+ --gradient_accumulation_steps 4 \
650
+ --skip_excess_length False \
651
+ --ddp_find_unused_parameters False \
652
+ --use_flash_attention_2 \
653
+ --deepspeed deepspeed.json
654
+ ```
655
+
656
+ Deepspeed configuration:
657
+ ```json
658
+ {
659
+ "gradient_accumulation_steps": "auto",
660
+ "gradient_clipping": "auto",
661
+ "train_batch_size": "auto",
662
+ "train_micro_batch_size_per_gpu": "auto",
663
+ "bf16": {
664
+ "enabled": true
665
+ },
666
+ "zero_optimization": {
667
+ "stage": 2,
668
+ "contiguous_gradients": true,
669
+ "overlap_comm": true,
670
+ "reduce_scatter": true,
671
+ "reduce_bucket_size": 5e8,
672
+ "allgather_bucket_size": 5e8
673
+ }
674
+ }
675
+ ```
676
+
677
+ ### DPO phase
678
+
679
+ An example of the DPO phase for mistral-7b (requires first running the SFT):
680
+
681
+ ```bash
682
+ export BASE_DIR=/mnt/data
683
+ export WANDB_API_KEY=[redacted]
684
+ export WANDB_PROJECT=bagel-dpo-7b-v0.1
685
+
686
+ accelerate launch bagel/tune/dpo.py \
687
+ --model_name_or_path bagel-7b-v0.1 \
688
+ --learning_rate 3e-7 \
689
+ --per_device_train_batch_size 2 \
690
+ --gradient_accumulation_steps 4 \
691
+ --max_length 4096 \
692
+ --max_prompt_length 1024 \
693
+ --max_target_length 3092 \
694
+ --num_train_epochs 3 \
695
+ --report_to wandb \
696
+ --gradient_checkpointing true \
697
+ --use_flash_attention_2 true \
698
+ --dataset $BASE_DIR/bagel/bagel-dpo-v0.1.parquet \
699
+ --eval_steps 5 \
700
+ --eval_dataset_size 0.03 \
701
+ --workdir $BASE_DIR/$WANDB_PROJECT-workdir \
702
+ --output_dir $BASE_DIR/$WANDB_PROJECT \
703
+ --deepspeed deepspeed.json \
704
+ --save_steps 25 \
705
+ --save_total_limit 5
706
+ ```