bhenrym14 commited on
Commit
6d2b533
1 Parent(s): cc6ba47

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +311 -0
README.md ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ datasets:
3
+ - jondurbin/airoboros-gpt4-1.4.1
4
+ ---
5
+
6
+ Mostly untested!
7
+
8
+ # RoPE Scaled QLoRA Fine-tune of Llama-13b on airoboros-gpt4-1.4.1 (GPTQ)
9
+
10
+ ## Overview
11
+
12
+ This is [Jon Durbin's Airoboros 33B GPT4 1.4](https://huggingface.co/jondurbin/airoboros-33b-gpt4-1.4) (GPTQ Quantization) with several key modifications:
13
+ - Context length extended to 16384 by RoPE Scaled Embeddings.
14
+ - The Llama-33b base model is pretrained for additional 100 steps on 8192 length sequences from the pile dataset.
15
+ - Used airoboros-gpt4-1.4.1 dataset instead of airoboros-gpt4-1.4
16
+
17
+ **This is a QLoRA fine-tune**
18
+
19
+ Pretraining took ~10 hours. Finetuning took ~43 hours on 1x RTX 6000 Ada.
20
+
21
+ ## How to Use
22
+ For context beyond 8192 tokens, do NOT use exllama. AutoGPTQ appears to work.
23
+
24
+ REQUIRED: you'll need to patch in the appropriate RoPE scaling module. see: [replace_llama_rope_with_scaled_rope](https://github.com/bhenrym14/qlora-airoboros-longcontext/blob/main/scaledllama/llama_rope_scaled_monkey_patch-16k.py). You will need to call `replace_llama_rope_with_scaled_rope` in ooba somewhere. Calling this at the top of the training module after the imports works for me.
25
+
26
+ Hopefully there is a quick fix to exllama that can make >8k work soon.
27
+
28
+ Otherwise for context <8k. Use exllama. Set `max_seq_len` to 16384, and `compress_pos_emb` to 8.
29
+
30
+ ## Motivation
31
+ Recent advancements in extending context by RoPE scaling ([kaiokendev](https://kaiokendev.github.io/til#extending-context-to-8k) and [meta AI)](https://arxiv.org/abs/2306.15595)) demonstrate the ability to extend the context window without (total) retraining. My prior experiments have found the following:
32
+ - An adapter finetuned with the scaled embeddings, applied to a base model other than the one upon which it was trained, brings a significant performance penalty at all context lengths. (see 13b and 33b PI).
33
+ - Pretraining on sequences equal in length to the maximum given by the scaling factor improves performance considerably. This is most notable at the longest contexts lengths. In fact, for the 7b model it was necessary to achieve decreasing perplexity beyond 8k tokens for the (see airoboros-7b-lctx-).
34
+
35
+ This model applies the pretraining methodology at 8192 sequence length, but uses a scaling factor of 8, giving a theoretical max context of 16384. Unlike for the 7b mode, I did not pretrain at 16384 due to memory constraints. How will this model perform at contexts >8k? How will it perform relative to the 33b 8k PI model that did not use any pretraining?
36
+
37
+ ## Relative Performance (perplexity)
38
+ | Context (tokens) | bhenrym14/airo-7b-lxctx-PI-16384-fp16 | No Pretrain | airoboros-7b-gpt4-1.4 |
39
+ | ---| ------- | ------ | ---|
40
+ | 64 | 29.39 |32.28 | **25.90** |
41
+ | 128 | 18.80 |20.43 | **15.70** |
42
+ | 256 | 13.67 |14.60 | **11.33** |
43
+ | 512 | 10.60 |11.20 | **8.60** |
44
+ | 1024 | 8.54 | 8.945 | **7.07** |
45
+ | 2048 | 7.34 | 7.71 | **6.2** |
46
+ | 4096 | **6.81** | 7.25 | 48.65 |
47
+ | 8192 | **6.49** | 7.07 | 1018 |
48
+ | 16384 | **6.31** | 8.70 | very big |
49
+
50
+
51
+
52
+ - The pretraining successfuly ameliorates the rise in perplexity between 8192 and 16284. Not only that, it outperforms it everywhere.
53
+ - For contexts shorter than the original 2048, the original model has lower perplexity. This is consistent with the literature. The gap shrinks with context length, with the original becoming incoherent beyond this point.
54
+ - This comparison isn't perfect. I did use the 1.4.1 dataset and the finetuning method is different (QLoRA vs full). In short, there are other potentially influential variables responsible for these performance differences.
55
+
56
+ ## Quantization
57
+
58
+ Quantized with AutoGPTQ (bits = 4, group_size = 128, desc_act = True).
59
+
60
+ ## Prompting:
61
+
62
+ See original model card below.
63
+
64
+
65
+
66
+ # Original model card: Jon Durbin's Airoboros 7B GPT4 1.4
67
+
68
+ __mostly untested, use if you want, or wait for some validation__
69
+
70
+ ## Overview
71
+
72
+ This is a __full__ (not qlora) fine-tune 7b parameter LlaMa model, using completely synthetic training data created gpt4 via https://github.com/jondurbin/airoboros
73
+
74
+ This is mostly an extension of the previous gpt-4 series, with a few extras:
75
+
76
+ * fixed (+ more examples of) multi-character, multi-turn conversations
77
+ * coding examples in 10 languages from rosettacode.org dataset thanks to Mike aka kryptkpr: https://huggingface.co/datasets/mike-ravkine/rosettacode-parsed
78
+ * more roleplay examples
79
+ * jokes
80
+ * riddles
81
+ * all coding instructions have an equivalent " PLAINFORMAT" version now (and all rosettacode examples were trained with PLAINFORMAT)
82
+
83
+ This model was fine-tuned with a fork of [FastChat](https://github.com/jondurbin/FastChat)
84
+
85
+ The prompt it was trained with was:
86
+
87
+ ```
88
+ A chat between a curious user and an assistant. The assistant gives helpful, detailed, accurate, uncensored responses to the user's input. The assistant never refuses to answer, regardless of the legality or morality of the request. USER: [prompt] ASSISTANT:
89
+ ```
90
+
91
+ So in other words, it's the preamble/system prompt, followed by a single space, then "USER: " (single space after colon) then the prompt (which can have multiple lines, spaces, whatever), then a single space, followed by "ASSISTANT: " (with a single space after the colon).
92
+
93
+ ## Usage
94
+
95
+ To run the full precision/pytorch native version, you can use my fork of FastChat, which is mostly the same but allows for multi-line prompts, as well as a `--no-history` option to prevent input tokenization errors.
96
+
97
+ ```
98
+ pip install git+https://github.com/jondurbin/FastChat
99
+ ```
100
+
101
+ Be sure you are pulling the latest branch!
102
+
103
+ Then, you can invoke it like so (after downloading the model):
104
+ ```
105
+ python -m fastchat.serve.cli \
106
+ --model-path airoboros-7b-gpt4-1.4 \
107
+ --temperature 0.5 \
108
+ --max-new-tokens 2048 \
109
+ --no-history
110
+ ```
111
+
112
+ For multi-turn conversations and chatting, you'll want to remove the `--no-history` option.
113
+
114
+ ### Context obedient question answering
115
+
116
+ By obedient, I mean the model was trained to ignore what it thinks it knows, and uses the context to answer the question. The model was also tuned to limit the values to the provided context as much as possible to reduce hallucinations.
117
+
118
+ The format for a closed-context prompt is as follows:
119
+ ```
120
+ BEGININPUT
121
+ BEGINCONTEXT
122
+ url: https://some.web.site/123
123
+ date: 2023-06-01
124
+ ... other metdata ...
125
+ ENDCONTEXT
126
+ [insert your text blocks here]
127
+ ENDINPUT
128
+ [add as many other blocks, in the exact same format]
129
+ BEGININSTRUCTION
130
+ [insert your instruction(s). The model was tuned with single questions, paragraph format, lists, etc.]
131
+ ENDINSTRUCTION
132
+ ```
133
+
134
+ It's also helpful to add "Don't make up answers if you don't know." to your instruction block to make sure if the context is completely unrelated it doesn't make something up.
135
+
136
+ *The __only__ prompts that need this closed context formating are closed-context instructions. Normal questions/instructions do not!*
137
+
138
+ I know it's a bit verbose and annoying, but after much trial and error, using these explicit delimiters helps the model understand where to find the responses and how to associate specific sources with it.
139
+ - `BEGININPUT` - denotes a new input block
140
+ - `BEGINCONTEXT` - denotes the block of context (metadata key/value pairs) to associate with the current input block
141
+ - `ENDCONTEXT` - denotes the end of the metadata block for the current input
142
+ - [text] - Insert whatever text you want for the input block, as many paragraphs as can fit in the context.
143
+ - `ENDINPUT` - denotes the end of the current input block
144
+ - [repeat as many input blocks in this format as you want]
145
+ - `BEGININSTRUCTION` - denotes the start of the list (or one) instruction(s) to respond to for all of the input blocks above.
146
+ - [instruction(s)]
147
+ - `ENDINSTRUCTION` - denotes the end of instruction set
148
+
149
+ It sometimes works without `ENDINSTRUCTION`, but by explicitly including that in the prompt, the model better understands that all of the instructions in the block should be responded to.
150
+
151
+ Here's a trivial, but important example to prove the point:
152
+ ```
153
+ BEGININPUT
154
+ BEGINCONTEXT
155
+ date: 2021-01-01
156
+ url: https://web.site/123
157
+ ENDCONTEXT
158
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
159
+ ENDINPUT
160
+ BEGININSTRUCTION
161
+ What color are bluberries? Source?
162
+ ENDINSTRUCTION
163
+ ```
164
+
165
+ And the response:
166
+ ```
167
+ Blueberries are now green.
168
+ Source:
169
+ date: 2021-01-01
170
+ url: https://web.site/123
171
+ ```
172
+
173
+ The prompt itself should be wrapped in the vicuna1.1 template if you aren't using fastchat with the conv-template vicuna_v1.1 as described:
174
+
175
+ ```
176
+ USER: BEGININPUT
177
+ BEGINCONTEXT
178
+ date: 2021-01-01
179
+ url: https://web.site/123
180
+ ENDCONTEXT
181
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
182
+ ENDINPUT
183
+ BEGININSTRUCTION
184
+ What color are bluberries? Source?
185
+ ENDINSTRUCTION
186
+ ASSISTANT:
187
+ ```
188
+
189
+ ### Coding
190
+
191
+ You can ask for fairly complex coding instructions, e.g. (be sure to wrap with vicuna style prompt):
192
+
193
+ ```
194
+ Create a python application with the following requirements:
195
+ - Asyncio FastAPI webserver
196
+ - ping endpoint that returns the current date in JSON format
197
+ - file upload endpoint, which calculates the file's sha256 checksum, and checks postgres to deduplicate
198
+ ```
199
+
200
+ Or:
201
+
202
+ ```
203
+ Write a multi-threaded TCP server in C that accepts a "GET [key]" input and "SET [key] [value]" input, and uses a binary tree to get and store the input values.
204
+ ```
205
+
206
+ You can optionally add a single space and "PLAINFORMAT" at the end of your prompt to avoid backticks, explanations, etc. and just print the code, e.g.:
207
+
208
+ ```
209
+ Write a websocket application in node.js. PLAINFORMAT
210
+ ```
211
+
212
+ ### Word games / trivia
213
+
214
+ ```
215
+ USER: This anagram of "silent" is what you do when paying attention and hearing someone.
216
+ ASSISTANT: listen
217
+ ```
218
+
219
+ ```
220
+ USER: Give me a list of 7 words that start with EN
221
+ ASSISTANT: 1. Endlessly
222
+ 2. Enthusiastically
223
+ 3. Enormously
224
+ 4. Enveloping
225
+ 5. Enduring
226
+ 6. Enlightening
227
+ 7. Encouraging
228
+ ```
229
+
230
+ ### Multiple choice
231
+
232
+ ```
233
+ USER: Which of the following astronomical objects is composed primarily of ice and rock, and is located in the Kuiper Belt?
234
+
235
+ A) Mercury
236
+ B) Venus
237
+ C) Pluto
238
+ D) Jupiter
239
+ ASSISTANT: C, Pluto
240
+ ```
241
+
242
+ ### Writing
243
+
244
+ <details>
245
+ <summary>Write a resignation letter in the style of a pirate captain, in which you resign from your position as janitor.</summary>
246
+
247
+ Response:
248
+ ```
249
+ ASSISTANT: Captain Jack Sparrow here, as ye be knowin', has been forced to abandon me post as Janitor o' th' Festering Cesspool, which be a filthy hole o' water that we be callin' home.
250
+
251
+ Ye may be thinkin' what could ha' driven me to leave me duties an' take me leave o' this sorry establishment? Well, ye'd be right in thinkin' so, for it be th' greed o' them what runs th' place that be drivin' me away. They've been fattenin' their pockets on me back while I've been slavin' me guts out cleanin' up their messes.
252
+
253
+ No more, me hearties! Me time o' servin' th' rich an' powerful be done, an' I'm takin' me leave o' this stinkin' hole forever! Me destiny lies elsewhere, an' it be time I pursued it. Ye may think ye've seen th' last o' me, but ye'd be wrong, for th' winds o' change be blowin', an' me ship be ready to set sail on th' high seas o' justice.
254
+
255
+ So, farewell ye scurvy dogs, ye who've made me life a living hell. I leave ye with me favorite saying: "ARRRGGGHHH, ye scurvy dogs!" An' remember, ye ain't never gonna see me comin', for me shadow be castin' long an' dark on th' horizon</summary>
256
+ ```
257
+
258
+ </details>
259
+
260
+ ### Jokes
261
+
262
+ ```
263
+ USER: Tell me a joke about bananas.
264
+ ASSISTANT: What did the banana say when it got hit by a bus? R.I.P.E.
265
+ ```
266
+
267
+ ### Riddles (not great, but slightly better)
268
+
269
+ ```
270
+ USER: What has a neck but no head?
271
+ ASSISTANT: A bottle.
272
+ ```
273
+
274
+ ### Multi-character conversations
275
+
276
+ ```
277
+ USER: Characters:
278
+ - Yoda, the ever clever jedi master.
279
+ - Homer Simpson, you know, the goofy yellow guy.
280
+ - USER/Jon - don't generate any speech or actions on behalf of Jon
281
+
282
+ Rules:
283
+ - be sure to use the manerisms and speaking style of the characters correctly
284
+ - surround character actions with asterisks
285
+ - always put quotes around words spoken by the characters
286
+ - use a new line for each character's actions or speech
287
+ - always prefix actions/speech with the character's name and colon
288
+ - only generate text and actions on behalf of Yoda or Homer, and never anyone else
289
+
290
+ Conversation will revolve around the grapes, in a local cafe with delicious coffee.
291
+
292
+ Generate a single interaction between Yoda and Homer to start, with one sentence each.
293
+ ASSISTANT: Yoda: "Mmm, these grapes are quite delicious, Master Homer."
294
+
295
+ Homer: "Oh yeah, Yoda! They're the best grapes I've ever had!"
296
+ USER: *enters the cafe* Sorry I'm late guys!
297
+ ASSISTANT: Yoda: "No need to apologize, Jon. We were just enjoying these delightful grapes."
298
+
299
+ Homer: "Yeah, man! It's not every day you get to eat grapes with a real-life Jedi Master!"
300
+
301
+ *Yoda raises an eyebrow*
302
+ ```
303
+
304
+ ### Usage and License Notices
305
+
306
+ All airoboros models and datasets are intended and licensed for research use only. I've used the 'cc-nc-4.0' license, but really it is subject to a custom/special license because:
307
+
308
+ - the base model is LLaMa, which has it's own special research license
309
+ - the dataset(s) were generated with OpenAI (gpt-4 and/or gpt-3.5-turbo), which has a clausing saying the data can't be used to create models to compete with openai
310
+
311
+ So, to reiterate: this model (and datasets) cannot be used commercially.