Text Generation
Transformers
llama
Inference Endpoints
bhenrym14 commited on
Commit
1e5fbc7
1 Parent(s): c20fc94

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +259 -0
README.md CHANGED
@@ -1,3 +1,262 @@
1
  ---
2
  license: mit
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ datasets:
4
+ - jondurbin/airoboros-gpt4-1.4.1
5
+ - ehartford/dolphin
6
  ---
7
+
8
+
9
+ # Airophin: A Partial NTK RoPE Scaled QLoRA Fine-tune of Llama-2-13b (GPTQ quantized)
10
+
11
+ LoRA Weights can be found here: https://huggingface.co/bhenrym14/airoboros-13b-gpt4-1.4.1-PI-8192-LoRA
12
+
13
+ fp16 weights can be found here: https://huggingface.co/bhenrym14/airophin-13b-pntk-16k-fp16
14
+
15
+ ## Overview
16
+
17
+ This is a finetune of Llama-2-13b, intended to extend the useful context window to 16384 tokens. There are two training phases:
18
+ 1. It is first trained on a long-context (>7000 to 8192 token range) subset of [dolphin](), a orca-like dataset. This amounts to roughly 110mm tokens, seen twice over two epochs. Airoboros-like training prompt was used. This took ~45 hours.
19
+ 2. The model was then finetuned on [Jon Durbin's Airoboros 13B GPT4 1.4](https://huggingface.co/jondurbin/airoboros-13b-gpt4-1.4) for 3 epochs. This took ~17 hours.
20
+
21
+ **This is a QLoRA fine-tune**.
22
+
23
+ All training was performed with 1x RTX 6000 Ada.
24
+
25
+ ## How to Use
26
+
27
+ This model employs [Partial NTK Rope Scaling](https://github.com/jquesnelle/scaled-rope/pull/1). This methodology is not yet implemented natively in Transformers or Exllama (as of 7/21). There are two options to run this:
28
+ 1. Transformers (use bnb for quantization). Use [fp16 weights](https://huggingface.co/bhenrym14/airophin-13b-pntk-16k-fp16).
29
+ 2. Autogptq/GPTQ-for-Llama. Use these quantized weights.
30
+
31
+ Each method will require replacing the `LlamaEmbedding` with `LlamaPartNTKScaledRotaryEmbedding`, with `max_position_embeddings=16384`. A monkeypatch can be found here.
32
+
33
+
34
+
35
+
36
+
37
+ The easiest way is to use [oobabooga text-generation-webui](https://github.com/oobabooga/text-generation-webui) with ExLlama. You'll need to set max_seq_len to 8192 and compress_pos_emb to 4.
38
+
39
+ If you wish to use AutoGPTQ/GPTQ-for-Llama instead, 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.py)
40
+
41
+ ## Motivation
42
+ 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. Finetuning has shown to be necessary to properly leverage the longer context. The superHOT LoRA is an adapter that has been fine-tuned on longer context (8192 tokens); even when applied to models trained on dissimilar datasets, it successfully extends the context window to which the model can attend. While it's impressive this adapter is so flexible, how much does performance suffer relative to a model that has been fine-tuned with the scaled embeddings from the start? This is an experiment to explore this.
43
+
44
+ ## Relative Performance (perplexity)
45
+ | Model | Context (tokens) | Perplexity |
46
+ | ---------------------------------------------------- | ----------- | ---------- |
47
+ | TheBloke/airoboros-13B-gpt4-1-4-GPTQ | 512 | **7.42** |
48
+ | TheBloke/airoboros-13B-gpt4-1-4-SuperHOT-8K-GPTQ | 512 | 8.86 |
49
+ | **bhenrym14/airoboros-13b-gpt4-1.4.1-PI-8192-GPTQ** | 512 | 7.94 |
50
+ | ---------------------------------------------------- | ----------- | ---------- |
51
+ | TheBloke/airoboros-13B-gpt4-1-4-GPTQ | 2048 | **5.02** |
52
+ | TheBloke/airoboros-13B-gpt4-1-4-SuperHOT-8K-GPTQ | 2048 | 5.98 |
53
+ | **bhenrym14/airoboros-13b-gpt4-1.4.1-PI-8192-GPTQ** | 2048 | 5.28 |
54
+ | ---------------------------------------------------- | ----------- | ---------- |
55
+ | TheBloke/airoboros-13B-gpt4-1-4-GPTQ | 4096 | 9848.0 |
56
+ | TheBloke/airoboros-13B-gpt4-1-4-SuperHOT-8K-GPTQ | 4096 | 5.80 |
57
+ | **bhenrym14/airoboros-13b-gpt4-1.4.1-PI-8192-GPTQ** | 4096 | **5.15** |
58
+
59
+
60
+ - 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.
61
+ - In terms of perplexity, this model outperforms the SuperHOT variant at all tested context lengths. I haven't used models with the SuperHOT LoRA enough to have any sense of performance differences, but feedback on the 33b variant suggests it is particularly noticable at longer context lengths.
62
+ - This comparison isn't perfect. I did use the 1.4.1 dataset, the quantization method is slightly different, and the finetuning method is different (QLoRA vs full). In short, there are other potentially influential variables responsible for these performance differences.
63
+
64
+ This model could be a little undertrained. I'll update the weights if I end up training it longer and/or with better hyperparameters
65
+ ## Quantization:
66
+
67
+ The merged model was quantized with AutoGPTQ (bits = 4, group_size = 128, desc_act = True).
68
+
69
+ ## Prompting:
70
+
71
+ airoboros-like prompting remains. See the following from one of Jon Durbin's airoboros model cards:
72
+
73
+
74
+ ### Context obedient question answering
75
+
76
+ 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.
77
+
78
+ The format for a closed-context prompt is as follows:
79
+ ```
80
+ BEGININPUT
81
+ BEGINCONTEXT
82
+ url: https://some.web.site/123
83
+ date: 2023-06-01
84
+ ... other metdata ...
85
+ ENDCONTEXT
86
+ [insert your text blocks here]
87
+ ENDINPUT
88
+ [add as many other blocks, in the exact same format]
89
+ BEGININSTRUCTION
90
+ [insert your instruction(s). The model was tuned with single questions, paragraph format, lists, etc.]
91
+ ENDINSTRUCTION
92
+ ```
93
+
94
+ 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.
95
+
96
+ *The __only__ prompts that need this closed context formating are closed-context instructions. Normal questions/instructions do not!*
97
+
98
+ 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.
99
+ - `BEGININPUT` - denotes a new input block
100
+ - `BEGINCONTEXT` - denotes the block of context (metadata key/value pairs) to associate with the current input block
101
+ - `ENDCONTEXT` - denotes the end of the metadata block for the current input
102
+ - [text] - Insert whatever text you want for the input block, as many paragraphs as can fit in the context.
103
+ - `ENDINPUT` - denotes the end of the current input block
104
+ - [repeat as many input blocks in this format as you want]
105
+ - `BEGININSTRUCTION` - denotes the start of the list (or one) instruction(s) to respond to for all of the input blocks above.
106
+ - [instruction(s)]
107
+ - `ENDINSTRUCTION` - denotes the end of instruction set
108
+
109
+ 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.
110
+
111
+ Here's a trivial, but important example to prove the point:
112
+ ```
113
+ BEGININPUT
114
+ BEGINCONTEXT
115
+ date: 2021-01-01
116
+ url: https://web.site/123
117
+ ENDCONTEXT
118
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
119
+ ENDINPUT
120
+ BEGININSTRUCTION
121
+ What color are bluberries? Source?
122
+ ENDINSTRUCTION
123
+ ```
124
+
125
+ And the response:
126
+ ```
127
+ Blueberries are now green.
128
+ Source:
129
+ date: 2021-01-01
130
+ url: https://web.site/123
131
+ ```
132
+
133
+ 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:
134
+
135
+ ```
136
+ USER: BEGININPUT
137
+ BEGINCONTEXT
138
+ date: 2021-01-01
139
+ url: https://web.site/123
140
+ ENDCONTEXT
141
+ In a shocking turn of events, blueberries are now green, but will be sticking with the same name.
142
+ ENDINPUT
143
+ BEGININSTRUCTION
144
+ What color are bluberries? Source?
145
+ ENDINSTRUCTION
146
+ ASSISTANT:
147
+ ```
148
+
149
+ ### Coding
150
+
151
+ You can ask for fairly complex coding instructions, e.g. (be sure to wrap with vicuna style prompt):
152
+
153
+ ```
154
+ Create a python application with the following requirements:
155
+ - Asyncio FastAPI webserver
156
+ - ping endpoint that returns the current date in JSON format
157
+ - file upload endpoint, which calculates the file's sha256 checksum, and checks postgres to deduplicate
158
+ ```
159
+
160
+ Or:
161
+
162
+ ```
163
+ 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.
164
+ ```
165
+
166
+ 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.:
167
+
168
+ ```
169
+ Write a websocket application in node.js. PLAINFORMAT
170
+ ```
171
+
172
+ ### Word games / trivia
173
+
174
+ ```
175
+ USER: This anagram of "silent" is what you do when paying attention and hearing someone.
176
+ ASSISTANT: listen
177
+ ```
178
+
179
+ ```
180
+ USER: Give me a list of 7 words that start with EN
181
+ ASSISTANT: 1. Endlessly
182
+ 2. Enthusiastically
183
+ 3. Enormously
184
+ 4. Enveloping
185
+ 5. Enduring
186
+ 6. Enlightening
187
+ 7. Encouraging
188
+ ```
189
+
190
+ ### Multiple choice
191
+
192
+ ```
193
+ USER: Which of the following astronomical objects is composed primarily of ice and rock, and is located in the Kuiper Belt?
194
+
195
+ A) Mercury
196
+ B) Venus
197
+ C) Pluto
198
+ D) Jupiter
199
+ ASSISTANT: C, Pluto
200
+ ```
201
+
202
+ ### Writing
203
+
204
+ <details>
205
+ <summary>Write a resignation letter in the style of a pirate captain, in which you resign from your position as janitor.</summary>
206
+
207
+ Response:
208
+ ```
209
+ 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.
210
+
211
+ 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.
212
+
213
+ 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.
214
+
215
+ 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>
216
+ ```
217
+
218
+ </details>
219
+
220
+ ### Jokes
221
+
222
+ ```
223
+ USER: Tell me a joke about bananas.
224
+ ASSISTANT: What did the banana say when it got hit by a bus? R.I.P.E.
225
+ ```
226
+
227
+ ### Riddles (not great, but slightly better)
228
+
229
+ ```
230
+ USER: What has a neck but no head?
231
+ ASSISTANT: A bottle.
232
+ ```
233
+
234
+ ### Multi-character conversations
235
+
236
+ ```
237
+ USER: Characters:
238
+ - Yoda, the ever clever jedi master.
239
+ - Homer Simpson, you know, the goofy yellow guy.
240
+ - USER/Jon - don't generate any speech or actions on behalf of Jon
241
+
242
+ Rules:
243
+ - be sure to use the manerisms and speaking style of the characters correctly
244
+ - surround character actions with asterisks
245
+ - always put quotes around words spoken by the characters
246
+ - use a new line for each character's actions or speech
247
+ - always prefix actions/speech with the character's name and colon
248
+ - only generate text and actions on behalf of Yoda or Homer, and never anyone else
249
+
250
+ Conversation will revolve around the grapes, in a local cafe with delicious coffee.
251
+
252
+ Generate a single interaction between Yoda and Homer to start, with one sentence each.
253
+ ASSISTANT: Yoda: "Mmm, these grapes are quite delicious, Master Homer."
254
+
255
+ Homer: "Oh yeah, Yoda! They're the best grapes I've ever had!"
256
+ USER: *enters the cafe* Sorry I'm late guys!
257
+ ASSISTANT: Yoda: "No need to apologize, Jon. We were just enjoying these delightful grapes."
258
+
259
+ Homer: "Yeah, man! It's not every day you get to eat grapes with a real-life Jedi Master!"
260
+
261
+ *Yoda raises an eyebrow*
262
+ ```