Text Generation
Transformers
Safetensors
mistral
conversational
text-generation-inference
4-bit precision
gptq
TheBloke commited on
Commit
40d161e
1 Parent(s): ffa87ec

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +718 -0
README.md ADDED
@@ -0,0 +1,718 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 - GPTQ
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 GPTQ model files for [Jon Durbin's Bagel DPO 7B v0.1](https://huggingface.co/jondurbin/bagel-dpo-7b-v0.1).
75
+
76
+ Multiple GPTQ parameter permutations are provided; see Provided Files below for details of the options provided, their parameters, and the software used to create them.
77
+
78
+ These files were quantised using hardware kindly provided by [Massed Compute](https://massedcompute.com/).
79
+
80
+ <!-- description end -->
81
+ <!-- repositories-available start -->
82
+ ## Repositories available
83
+
84
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-AWQ)
85
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ)
86
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GGUF)
87
+ * [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)
88
+ <!-- repositories-available end -->
89
+
90
+ <!-- prompt-template start -->
91
+ ## Prompt template: Alpaca
92
+
93
+ ```
94
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
95
+
96
+ ### Instruction:
97
+ {prompt}
98
+
99
+ ### Response:
100
+
101
+ ```
102
+
103
+ <!-- prompt-template end -->
104
+
105
+
106
+
107
+ <!-- README_GPTQ.md-compatible clients start -->
108
+ ## Known compatible clients / servers
109
+
110
+ GPTQ models are currently supported on Linux (NVidia/AMD) and Windows (NVidia only). macOS users: please use GGUF models.
111
+
112
+ These GPTQ models are known to work in the following inference servers/webuis.
113
+
114
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
115
+ - [KoboldAI United](https://github.com/henk717/koboldai)
116
+ - [LoLLMS Web UI](https://github.com/ParisNeo/lollms-webui)
117
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
118
+
119
+ This may not be a complete list; if you know of others, please let me know!
120
+ <!-- README_GPTQ.md-compatible clients end -->
121
+
122
+ <!-- README_GPTQ.md-provided-files start -->
123
+ ## Provided files, and GPTQ parameters
124
+
125
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
126
+
127
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
128
+
129
+ Most GPTQ files are made with AutoGPTQ. Mistral models are currently made with Transformers.
130
+
131
+ <details>
132
+ <summary>Explanation of GPTQ parameters</summary>
133
+
134
+ - Bits: The bit size of the quantised model.
135
+ - GS: GPTQ group size. Higher numbers use less VRAM, but have lower quantisation accuracy. "None" is the lowest possible value.
136
+ - Act Order: True or False. Also known as `desc_act`. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.
137
+ - Damp %: A GPTQ parameter that affects how samples are processed for quantisation. 0.01 is default, but 0.1 results in slightly better accuracy.
138
+ - GPTQ dataset: The calibration dataset used during quantisation. Using a dataset more appropriate to the model's training can improve quantisation accuracy. Note that the GPTQ calibration dataset is not the same as the dataset used to train the model - please refer to the original model repo for details of the training dataset(s).
139
+ - Sequence Length: The length of the dataset sequences used for quantisation. Ideally this is the same as the model sequence length. For some very long sequence models (16+K), a lower sequence length may have to be used. Note that a lower sequence length does not limit the sequence length of the quantised model. It only impacts the quantisation accuracy on longer inference sequences.
140
+ - ExLlama Compatibility: Whether this file can be loaded with ExLlama, which currently only supports Llama and Mistral models in 4-bit.
141
+
142
+ </details>
143
+
144
+ | Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
145
+ | ------ | ---- | -- | --------- | ------ | ------------ | ------- | ---- | ------- | ---- |
146
+ | [main](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/main) | 4 | 128 | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 4.16 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
147
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 4.57 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
148
+ | [gptq-8bit--1g-actorder_True](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/gptq-8bit--1g-actorder_True) | 8 | None | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 7.52 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
149
+ | [gptq-8bit-128g-actorder_True](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/gptq-8bit-128g-actorder_True) | 8 | 128 | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 7.68 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
150
+ | [gptq-8bit-32g-actorder_True](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/gptq-8bit-32g-actorder_True) | 8 | 32 | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 8.17 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
151
+ | [gptq-4bit-64g-actorder_True](https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ/tree/gptq-4bit-64g-actorder_True) | 4 | 64 | Yes | 0.1 | [VMware Open Instruct](https://huggingface.co/datasets/VMware/open-instruct/viewer/) | 4096 | 4.29 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
152
+
153
+ <!-- README_GPTQ.md-provided-files end -->
154
+
155
+ <!-- README_GPTQ.md-download-from-branches start -->
156
+ ## How to download, including from branches
157
+
158
+ ### In text-generation-webui
159
+
160
+ To download from the `main` branch, enter `TheBloke/bagel-dpo-7B-v0.1-GPTQ` in the "Download model" box.
161
+
162
+ To download from another branch, add `:branchname` to the end of the download name, eg `TheBloke/bagel-dpo-7B-v0.1-GPTQ:gptq-4bit-32g-actorder_True`
163
+
164
+ ### From the command line
165
+
166
+ I recommend using the `huggingface-hub` Python library:
167
+
168
+ ```shell
169
+ pip3 install huggingface-hub
170
+ ```
171
+
172
+ To download the `main` branch to a folder called `bagel-dpo-7B-v0.1-GPTQ`:
173
+
174
+ ```shell
175
+ mkdir bagel-dpo-7B-v0.1-GPTQ
176
+ huggingface-cli download TheBloke/bagel-dpo-7B-v0.1-GPTQ --local-dir bagel-dpo-7B-v0.1-GPTQ --local-dir-use-symlinks False
177
+ ```
178
+
179
+ To download from a different branch, add the `--revision` parameter:
180
+
181
+ ```shell
182
+ mkdir bagel-dpo-7B-v0.1-GPTQ
183
+ huggingface-cli download TheBloke/bagel-dpo-7B-v0.1-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir bagel-dpo-7B-v0.1-GPTQ --local-dir-use-symlinks False
184
+ ```
185
+
186
+ <details>
187
+ <summary>More advanced huggingface-cli download usage</summary>
188
+
189
+ If you remove the `--local-dir-use-symlinks False` parameter, the files will instead be stored in the central Hugging Face cache directory (default location on Linux is: `~/.cache/huggingface`), and symlinks will be added to the specified `--local-dir`, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.
190
+
191
+ The cache location can be changed with the `HF_HOME` environment variable, and/or the `--cache-dir` parameter to `huggingface-cli`.
192
+
193
+ For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).
194
+
195
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
196
+
197
+ ```shell
198
+ pip3 install hf_transfer
199
+ ```
200
+
201
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
202
+
203
+ ```shell
204
+ mkdir bagel-dpo-7B-v0.1-GPTQ
205
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/bagel-dpo-7B-v0.1-GPTQ --local-dir bagel-dpo-7B-v0.1-GPTQ --local-dir-use-symlinks False
206
+ ```
207
+
208
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
209
+ </details>
210
+
211
+ ### With `git` (**not** recommended)
212
+
213
+ To clone a specific branch with `git`, use a command like this:
214
+
215
+ ```shell
216
+ git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/bagel-dpo-7B-v0.1-GPTQ
217
+ ```
218
+
219
+ Note that using Git with HF repos is strongly discouraged. It will be much slower than using `huggingface-hub`, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the `.git` folder as a blob.)
220
+
221
+ <!-- README_GPTQ.md-download-from-branches end -->
222
+ <!-- README_GPTQ.md-text-generation-webui start -->
223
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
224
+
225
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
226
+
227
+ 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.
228
+
229
+ 1. Click the **Model tab**.
230
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/bagel-dpo-7B-v0.1-GPTQ`.
231
+
232
+ - To download from a specific branch, enter for example `TheBloke/bagel-dpo-7B-v0.1-GPTQ:gptq-4bit-32g-actorder_True`
233
+ - see Provided Files above for the list of branches for each option.
234
+
235
+ 3. Click **Download**.
236
+ 4. The model will start downloading. Once it's finished it will say "Done".
237
+ 5. In the top left, click the refresh icon next to **Model**.
238
+ 6. In the **Model** dropdown, choose the model you just downloaded: `bagel-dpo-7B-v0.1-GPTQ`
239
+ 7. The model will automatically load, and is now ready for use!
240
+ 8. 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.
241
+
242
+ - Note that you do not need to and should not set manual GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
243
+
244
+ 9. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
245
+
246
+ <!-- README_GPTQ.md-text-generation-webui end -->
247
+
248
+ <!-- README_GPTQ.md-use-from-tgi start -->
249
+ ## Serving this model from Text Generation Inference (TGI)
250
+
251
+ It's recommended to use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
252
+
253
+ Example Docker parameters:
254
+
255
+ ```shell
256
+ --model-id TheBloke/bagel-dpo-7B-v0.1-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
257
+ ```
258
+
259
+ Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
260
+
261
+ ```shell
262
+ pip3 install huggingface-hub
263
+ ```
264
+
265
+ ```python
266
+ from huggingface_hub import InferenceClient
267
+
268
+ endpoint_url = "https://your-endpoint-url-here"
269
+
270
+ prompt = "Tell me about AI"
271
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
272
+
273
+ ### Instruction:
274
+ {prompt}
275
+
276
+ ### Response:
277
+ '''
278
+
279
+ client = InferenceClient(endpoint_url)
280
+ response = client.text_generation(prompt,
281
+ max_new_tokens=128,
282
+ do_sample=True,
283
+ temperature=0.7,
284
+ top_p=0.95,
285
+ top_k=40,
286
+ repetition_penalty=1.1)
287
+
288
+ print(f"Model output: {response}")
289
+ ```
290
+ <!-- README_GPTQ.md-use-from-tgi end -->
291
+ <!-- README_GPTQ.md-use-from-python start -->
292
+ ## Python code example: inference from this GPTQ model
293
+
294
+ ### Install the necessary packages
295
+
296
+ Requires: Transformers 4.33.0 or later, Optimum 1.12.0 or later, and AutoGPTQ 0.4.2 or later.
297
+
298
+ ```shell
299
+ pip3 install --upgrade transformers optimum
300
+ # If using PyTorch 2.1 + CUDA 12.x:
301
+ pip3 install --upgrade auto-gptq
302
+ # or, if using PyTorch 2.1 + CUDA 11.x:
303
+ pip3 install --upgrade auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/
304
+ ```
305
+
306
+ If you are using PyTorch 2.0, you will need to install AutoGPTQ from source. Likewise if you have problems with the pre-built wheels, you should try building from source:
307
+
308
+ ```shell
309
+ pip3 uninstall -y auto-gptq
310
+ git clone https://github.com/PanQiWei/AutoGPTQ
311
+ cd AutoGPTQ
312
+ git checkout v0.5.1
313
+ pip3 install .
314
+ ```
315
+
316
+ ### Example Python code
317
+
318
+ ```python
319
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
320
+
321
+ model_name_or_path = "TheBloke/bagel-dpo-7B-v0.1-GPTQ"
322
+ # To use a different branch, change revision
323
+ # For example: revision="gptq-4bit-32g-actorder_True"
324
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
325
+ device_map="auto",
326
+ trust_remote_code=False,
327
+ revision="main")
328
+
329
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
330
+
331
+ prompt = "Tell me about AI"
332
+ prompt_template=f'''Below is an instruction that describes a task. Write a response that appropriately completes the request.
333
+
334
+ ### Instruction:
335
+ {prompt}
336
+
337
+ ### Response:
338
+ '''
339
+
340
+ print("\n\n*** Generate:")
341
+
342
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
343
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
344
+ print(tokenizer.decode(output[0]))
345
+
346
+ # Inference can also be done using transformers' pipeline
347
+
348
+ print("*** Pipeline:")
349
+ pipe = pipeline(
350
+ "text-generation",
351
+ model=model,
352
+ tokenizer=tokenizer,
353
+ max_new_tokens=512,
354
+ do_sample=True,
355
+ temperature=0.7,
356
+ top_p=0.95,
357
+ top_k=40,
358
+ repetition_penalty=1.1
359
+ )
360
+
361
+ print(pipe(prompt_template)[0]['generated_text'])
362
+ ```
363
+ <!-- README_GPTQ.md-use-from-python end -->
364
+
365
+ <!-- README_GPTQ.md-compatibility start -->
366
+ ## Compatibility
367
+
368
+ The files provided are tested to work with Transformers. For non-Mistral models, AutoGPTQ can also be used directly.
369
+
370
+ [ExLlama](https://github.com/turboderp/exllama) is compatible with Llama and Mistral models in 4-bit. Please see the Provided Files table above for per-file compatibility.
371
+
372
+ For a list of clients/servers, please see "Known compatible clients / servers", above.
373
+ <!-- README_GPTQ.md-compatibility end -->
374
+
375
+ <!-- footer start -->
376
+ <!-- 200823 -->
377
+ ## Discord
378
+
379
+ For further support, and discussions on these models and AI in general, join us at:
380
+
381
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
382
+
383
+ ## Thanks, and how to contribute
384
+
385
+ Thanks to the [chirper.ai](https://chirper.ai) team!
386
+
387
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
388
+
389
+ 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.
390
+
391
+ 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.
392
+
393
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
394
+
395
+ * Patreon: https://patreon.com/TheBlokeAI
396
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
397
+
398
+ **Special thanks to**: Aemon Algiz.
399
+
400
+ **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
401
+
402
+
403
+ Thank you to all my generous patrons and donaters!
404
+
405
+ And thank you again to a16z for their generous grant.
406
+
407
+ <!-- footer end -->
408
+
409
+ # Original model card: Jon Durbin's Bagel DPO 7B v0.1
410
+
411
+
412
+ # A bagel, with everything
413
+
414
+ ![bagel](bagel.png)
415
+
416
+ ## Overview
417
+
418
+ This is the DPO'd version of https://huggingface.co/jondurbin/bagel-7b-v0.1
419
+
420
+ 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.
421
+
422
+ ## Benchmarks
423
+
424
+ 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.
425
+
426
+ | model | arc_challenge | boolq | gsm8k | hellaswag | mmlu | openbookqa | piqa | truthful_qa | winogrande |
427
+ | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
428
+ | bagel | __0.6715__ | 0.8813 | __0.5618__ | 0.8397 | __0.6408__ | __0.51__ | __0.8406__ | __0.6275__ | __0.7561__ |
429
+ | openhermes-2.5 | 0.6476 | __0.8835__ | 0.4852 | __0.8414__ | 0.6347 | 0.498 | 0.8400 | 0.5295 | 0.7443 |
430
+
431
+
432
+ MT-Bench:
433
+ ```
434
+ ########## First turn ##########
435
+ score
436
+ model turn
437
+ bagel-7b-v0.1 1 7.60625
438
+
439
+ ########## Second turn ##########
440
+ score
441
+ model turn
442
+ bagel-7b-v0.1 2 7.00625
443
+
444
+ ########## Average ##########
445
+ score
446
+ model
447
+ bagel-7b-v0.1 7.30625
448
+ ```
449
+
450
+ ## Data selection.
451
+
452
+ The first step in the process is creating a dataset.
453
+ In this case, we're actually creating a composite dataset, consisting of both supervised fine-tuning data (SFT) and direct preference optimization (DPO) data.
454
+
455
+ 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.
456
+
457
+ See the corresponding code in `bagel/data_sources/*.py` for full implementation for each data source.
458
+
459
+ 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).
460
+ 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.
461
+
462
+ ### SFT data sources
463
+
464
+ *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*
465
+
466
+ - [ai2_arc](https://huggingface.co/datasets/ai2_arc)
467
+ - Abstraction and reasoning dataset, useful in measuring "intelligence" to a certain extent.
468
+ - [airoboros](https://huggingface.co/datasets/unalignment/spicy-3.1)
469
+ - Variety of categories of synthetic instructions generated by gpt-4.
470
+ - [apps](https://huggingface.co/datasets/codeparrot/apps)
471
+ - Python coding dataset with 10k problems.
472
+ - [belebele](https://huggingface.co/datasets/facebook/belebele)
473
+ - Multi-lingual reading comprehension dataset.
474
+ - [boolq](https://huggingface.co/datasets/boolq)
475
+ - Corpus of yes/no questions (which can be surprisingly difficult for AI to answer apparently?)
476
+ - [cinematika](https://huggingface.co/datasets/jondurbin/cinematika-v0.1) (instruction and plain text)
477
+ - RP-style data synthesized from movie scripts so the model isn't quite as boring as it otherwise would be.
478
+ - [drop](https://huggingface.co/datasets/drop)
479
+ - More reading comprehension.
480
+ - [gutenberg](https://www.gutenberg.org/) (plain text)
481
+ - Books/plain text, again to make the model less boring, only a handful of examples supported by [chapterize](https://github.com/JonathanReeve/chapterize)
482
+ - [lmsys_chat_1m](https://huggingface.co/datasets/lmsys/lmsys-chat-1m) (only gpt-4 items, also used for DPO)
483
+ - Chats collected by the lmsys chat arena, containing a wide variety of chats with various models.
484
+ - [mathinstruct](https://huggingface.co/datasets/TIGER-Lab/MathInstruct)
485
+ - Composite dataset with a variety of math-related tasks and problem/question formats.
486
+ - [mmlu](https://huggingface.co/datasets/cais/mmlu)
487
+ - Massive Multitask Language Understanding - a wide variety of questions about various subject matters.
488
+ - [natural_instructions](https://huggingface.co/datasets/Muennighoff/natural-instructions)
489
+ - Millions of instructions from 1600+ task categories (sampled down substantially, stratified by task type)
490
+ - [openbookqa](https://huggingface.co/datasets/openbookqa)
491
+ - Question answering dataset.
492
+ - [piqa](https://huggingface.co/datasets/piqa)
493
+ - Phyiscal interaction question answering.
494
+ - [python_alpaca](https://huggingface.co/datasets/Vezora/Tested-22k-Python-Alpaca)
495
+ - Python instruction response pairs, validated as functional.
496
+ - [rosetta_code](https://huggingface.co/datasets/cakiki/rosetta-code)
497
+ - Code problems and solutions in a variety of programming languages taken from rosettacode.org.
498
+ - [slimorca](https://huggingface.co/datasets/Open-Orca/SlimOrca)
499
+ - Collection of ~500k gpt-4 verified chats from OpenOrca.
500
+ - [spider](https://huggingface.co/datasets/spider)
501
+ - SQL-targeted dataset.
502
+ - [squad_v2](https://huggingface.co/datasets/squad_v2)
503
+ - Contextual question answering (RAG).
504
+ - [synthia](https://huggingface.co/datasets/migtissera/Synthia-v1.3)
505
+ - GPT-4 generated data using advanced prompting from Migel Tissera.
506
+ - [winogrande](https://huggingface.co/datasets/winogrande)
507
+ - Fill in the blank style prompts.
508
+
509
+ ### DPO data sources
510
+ - [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)
511
+ - 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"
512
+ - [helpsteer](https://huggingface.co/datasets/nvidia/HelpSteer)
513
+ - 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"
514
+ - [orca_dpo_pairs](https://huggingface.co/datasets/Intel/orca_dpo_pairs)
515
+ - Another interesting dataset by Intel, which provides various DPO pairs generated from prompts included in the SlimOrca dataset.
516
+ - [toxic-dpo](https://huggingface.co/datasets/unalignment/toxic-dpo-v0.1)
517
+ - __*highly toxic and potentially illegal content!*__ De-censorship, for academic and lawful purposes only, of course. Generated by llama-2-70b via prompt engineering.
518
+ - [truthy](https://huggingface.co/datasets/jondurbin/truthy-dpo-v0.1)
519
+ - 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.
520
+ - [ultrafeedback](https://huggingface.co/datasets/allenai/ultrafeedback_binarized_cleaned)
521
+ - One of the bits of magic behind the Zephyr model. Only the items with a chosen score of 8 or higher were included.
522
+
523
+ 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).
524
+
525
+ ### Total dataset size
526
+
527
+ The deduplicated and decontamined list of instructions contains 1,671,822 items:
528
+
529
+ - 1,602,217 SFT/instructions
530
+ - 59,247 DPO pairs
531
+ - 1606 with both SFT and DPO data
532
+
533
+ Keep in mind, this number becomes 4x larger when applying the various prompt formats.
534
+
535
+ ## Prompt formatting
536
+
537
+ 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).
538
+ 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.
539
+
540
+ 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.
541
+
542
+ ### Alpaca (sort of)
543
+
544
+ ```
545
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
546
+
547
+ ### Instruction:
548
+ {system prompt, if provided}
549
+ {instruction}
550
+
551
+ ### Response:
552
+ ```
553
+
554
+ 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.
555
+
556
+ ### Vicuna
557
+
558
+ ```
559
+ {system prompt, if provided, randomly defaulting to "A chat between a user and an unbiased, uncensored assistant."}
560
+ USER: {instruction}
561
+ ASSISTANT:
562
+ ```
563
+
564
+ ### ChatML (sort of)
565
+
566
+ 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).
567
+
568
+ So, instead of:
569
+ ```text
570
+ {bos}<|im_start|>{role}
571
+ {text}
572
+ <|im_end|>{eos}
573
+ ```
574
+
575
+ I just changed it to:
576
+ ```text
577
+ {bos}{role}
578
+ {text}
579
+ {eos}
580
+ ```
581
+
582
+ In practice, this would mean tokenization code like such:
583
+ ```python
584
+ tokenizer = AutoTokenizer.from_pretrained('mistralai/mistral-7b-v0.1')
585
+
586
+ input_str = f"""system
587
+ You are a goat.
588
+ {tokenizer.eos_token}
589
+ {tokenizer.bos_token}user
590
+ Tell me how to fry an egg.
591
+ {tokenizer.eos_token}
592
+ {tokenizer.bos_token}assistant
593
+ """
594
+
595
+ inputs = tokenizer(input_str, return_tensors="pt")
596
+ ```
597
+
598
+ 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.
599
+
600
+ ### Llama-2 chat
601
+
602
+ ```
603
+ [INST] <<SYS>>
604
+ {system}
605
+ <</SYS>>
606
+
607
+ {instruction} [/INST]
608
+ ```
609
+
610
+ ## Fine tuning
611
+
612
+ ### SFT phase
613
+
614
+ An example for mistral-7b:
615
+
616
+ *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!*
617
+
618
+ *More notes: I stopped the SFT phase around 50% because of budget constraints.*
619
+
620
+ ```bash
621
+ export BASE_DIR=/workspace
622
+ export WANDB_API_KEY=[redacted]
623
+ export WANDB_PROJECT=bagel-7b-v0.1
624
+
625
+ # Run the pretraining.
626
+ accelerate launch bagel/tune/sft.py \
627
+ --model_name_or_path $BASE_DIR/mistral-7b \
628
+ --final_output_dir $BASE_DIR/$WANDB_PROJECT \
629
+ --output_dir $BASE_DIR/$WANDB_PROJECT-workdir \
630
+ --num_train_epochs 1 \
631
+ --logging_steps 1 \
632
+ --save_strategy steps \
633
+ --save_steps 200 \
634
+ --save_total_limit 5 \
635
+ --data_seed 42 \
636
+ --evaluation_strategy steps \
637
+ --eval_dataset_size 0.0006 \
638
+ --eval_steps 200 \
639
+ --max_new_tokens 4096 \
640
+ --dataloader_num_workers 3 \
641
+ --logging_strategy steps \
642
+ --remove_unused_columns False \
643
+ --do_train \
644
+ --full_finetune \
645
+ --bf16 \
646
+ --bits 16 \
647
+ --optim adamw_torch \
648
+ --lr_scheduler_type linear \
649
+ --dataset $BASE_DIR/bagel/bagel-input-output-v0.1.parquet \
650
+ --dataset_format input-output \
651
+ --model_max_len 4096 \
652
+ --per_device_train_batch_size 8 \
653
+ --learning_rate 3.5e-7 \
654
+ --warmup_ratio 0.005 \
655
+ --adam_beta2 0.999 \
656
+ --max_grad_norm 0.3 \
657
+ --weight_decay 0.001 \
658
+ --seed 42 \
659
+ --report_to wandb \
660
+ --gradient_checkpointing True \
661
+ --gradient_accumulation_steps 4 \
662
+ --skip_excess_length False \
663
+ --ddp_find_unused_parameters False \
664
+ --use_flash_attention_2 \
665
+ --deepspeed deepspeed.json
666
+ ```
667
+
668
+ Deepspeed configuration:
669
+ ```json
670
+ {
671
+ "gradient_accumulation_steps": "auto",
672
+ "gradient_clipping": "auto",
673
+ "train_batch_size": "auto",
674
+ "train_micro_batch_size_per_gpu": "auto",
675
+ "bf16": {
676
+ "enabled": true
677
+ },
678
+ "zero_optimization": {
679
+ "stage": 2,
680
+ "contiguous_gradients": true,
681
+ "overlap_comm": true,
682
+ "reduce_scatter": true,
683
+ "reduce_bucket_size": 5e8,
684
+ "allgather_bucket_size": 5e8
685
+ }
686
+ }
687
+ ```
688
+
689
+ ### DPO phase
690
+
691
+ An example of the DPO phase for mistral-7b (requires first running the SFT):
692
+
693
+ ```bash
694
+ export BASE_DIR=/mnt/data
695
+ export WANDB_API_KEY=[redacted]
696
+ export WANDB_PROJECT=bagel-dpo-7b-v0.1
697
+
698
+ accelerate launch bagel/tune/dpo.py \
699
+ --model_name_or_path bagel-7b-v0.1 \
700
+ --learning_rate 3e-7 \
701
+ --per_device_train_batch_size 2 \
702
+ --gradient_accumulation_steps 4 \
703
+ --max_length 4096 \
704
+ --max_prompt_length 1024 \
705
+ --max_target_length 3092 \
706
+ --num_train_epochs 3 \
707
+ --report_to wandb \
708
+ --gradient_checkpointing true \
709
+ --use_flash_attention_2 true \
710
+ --dataset $BASE_DIR/bagel/bagel-dpo-v0.1.parquet \
711
+ --eval_steps 5 \
712
+ --eval_dataset_size 0.03 \
713
+ --workdir $BASE_DIR/$WANDB_PROJECT-workdir \
714
+ --output_dir $BASE_DIR/$WANDB_PROJECT \
715
+ --deepspeed deepspeed.json \
716
+ --save_steps 25 \
717
+ --save_total_limit 5
718
+ ```