Text Generation
PEFT
Safetensors
llama-2
Eval Results
dfurman commited on
Commit
b974443
1 Parent(s): f239f6c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +282 -0
README.md CHANGED
@@ -13,6 +13,288 @@ pipeline_tag: text-generation
13
 
14
  This instruction model was built via parameter-efficient QLoRA finetuning of [llama-2-70b](https://huggingface.co/meta-llama/Llama-2-70b-hf) on the first 25k rows of [ehartford/dolphin](https://huggingface.co/datasets/ehartford/dolphin) (an open-source implementation of [Microsoft's Orca](https://www.microsoft.com/en-us/research/publication/orca-progressive-learning-from-complex-explanation-traces-of-gpt-4/)). Finetuning was executed on a single H100 (80 GB PCIe) for roughly 17 hours on the [Lambda Labs](https://cloud.lambdalabs.com/instances) platform.
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  ---
17
 
18
  ### Framework versions
 
13
 
14
  This instruction model was built via parameter-efficient QLoRA finetuning of [llama-2-70b](https://huggingface.co/meta-llama/Llama-2-70b-hf) on the first 25k rows of [ehartford/dolphin](https://huggingface.co/datasets/ehartford/dolphin) (an open-source implementation of [Microsoft's Orca](https://www.microsoft.com/en-us/research/publication/orca-progressive-learning-from-complex-explanation-traces-of-gpt-4/)). Finetuning was executed on a single H100 (80 GB PCIe) for roughly 17 hours on the [Lambda Labs](https://cloud.lambdalabs.com/instances) platform.
15
 
16
+ * Model license: Llama 2 Community License Agreement
17
+ * Basic usage: [notebook](assets/basic_inference_llama_2_70b_dolphin.ipynb)
18
+ * Finetuning code: [notebook](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/one_gpu/llama-2/dolphin/sft-llama-2-70b-dolphin-peft.ipynb)
19
+ * Loss curves: [plot](https://huggingface.co/dfurman/llama-2-70b-dolphin-peft#finetuning-description)
20
+ * Runtime stats: [table](https://huggingface.co/dfurman/llama-2-70b-dolphin-peft#runtime-tests)
21
+
22
+ ### Example prompts and responses
23
+
24
+ Example 1:
25
+
26
+ **User**:
27
+ > You are a helpful assistant. Write me a numbered list of things to do in New York City.\n
28
+
29
+ **llama-2-70b-dolphin-peft**:
30
+ > 1. Visit the Statue of Liberty: Take a ferry to Liberty Island and see the iconic symbol of freedom and democracy.
31
+ > 2. Explore Central Park: Enjoy the lush greenery, take a stroll, or rent a bike to explore the park's many attractions, such as the Central Park Zoo and Strawberry Fields.
32
+ > 3. Visit the Empire State Building: Take an elevator to the observation deck for breathtaking views of the city.
33
+ > 4. Walk the Brooklyn Bridge: Cross the historic bridge and enjoy the stunning views of the Manhattan skyline.
34
+ > 5. Experience Times Square: Take in the bright lights, billboards, and bustling energy of this iconic intersection.
35
+ > 6. Visit the Metropolitan Museum of Art: Explore the vast collection of art and artifacts from around the world.
36
+ > 7. Take a food tour: Sample the diverse cuisine of New York City, from pizza to bagels to ethnic specialties.
37
+ > 8. Attend a Broadway show: Enjoy a world-class performance in the heart of the Theater District.
38
+
39
+ <br>
40
+
41
+ Example 2:
42
+
43
+ **User**:
44
+ > You are a helpful assistant. Daniel is in need of a haircut. His barber works Mondays, Wednesdays, and Fridays. So, Daniel went in for a haircut on Sunday. Does this make logical sense? Respond only with a yes or no answer in as few words as possible.\n
45
+
46
+ **llama-2-70b-dolphin-peft**:
47
+
48
+ > No.
49
+ >
50
+ > Explanation: Daniel's barber is not available on Sundays, so he cannot get a haircut on that day. He should go on a day when the barber is working, such as Monday, Wednesday, or Friday.
51
+ >
52
+ > So, the answer is no, it does not make logical sense for Daniel to go for a haircut on Sunday. He should go on a day when the barber is available.
53
+
54
+ <br>
55
+
56
+ Example 3:
57
+
58
+ **User**:
59
+
60
+ > You are a helpful assistant. Write a short email inviting my friends to a dinner party on Friday. Respond succinctly.\n
61
+
62
+ **llama-2-70b-dolphin-peft**:
63
+
64
+ > Subject: Dinner Party Invitation - Friday, 7 PM
65
+ >
66
+ > Dear Friends,
67
+ >
68
+ > I hope this email finds you well! I'm excited to invite you to a dinner party at my place this Friday, at 7 PM. We'll have a delicious meal, great company, and lots of fun. Please let me know if you can make it, so I can plan accordingly.
69
+ >
70
+ > Looking forward to seeing you all!
71
+ >
72
+ > Kind regards,
73
+ > Your Name
74
+
75
+ > P.S. Please let me know if you have any dietary restrictions or allergies.
76
+
77
+ <br>
78
+
79
+ Example 4:
80
+
81
+ **User**:
82
+
83
+ > You are a helpful assistant. Tell me a recipe for vegan banana bread.\n
84
+
85
+ **llama-2-70b-dolphin-peft**:
86
+
87
+ > Sure! Here's a delicious and easy vegan banana bread recipe:
88
+ >
89
+ > Ingredients:
90
+ > - 2 cups all-purpose flour
91
+ > - 1/2 cup sugar
92
+ > - 1/2 cup vegan butter (such as Earth Balance)
93
+ > - 1/2 cup vegan milk (such as almond milk)
94
+ > - 1/2 cup unsweetened applesauce
95
+ > - 1/2 cup mashed ripe bananas (about 2 medium bananas)
96
+ > - 1 teaspoon baking soda
97
+ > - 1/2 teaspoon salt
98
+ > - 1/2 teaspoon ground cinnamon
99
+ > - 1/2 teaspoon ground nutmeg
100
+ > - 1/2 teaspoon ground cloves
101
+ > - 1/2 cup chopped walnuts (optional)
102
+ >
103
+ > Instructions:
104
+ > 1. Preheat the oven to 350°F (175°C). Grease a 9x5-inch loaf pan with vegan butter or cooking spray.
105
+ > 2. In a large bowl, mix together the flour, sugar, vegan butter, vegan milk, applesauce, bananas, baking soda, salt, cinnamon, nutmeg, and cloves. Stir until well combined.
106
+ > 3. Fold in the chopped walnuts, if using.
107
+ > 4. Pour the batter into the prepared loaf pan.
108
+ > 5. Bake for 50-60 minutes, or until a toothpick inserted into the center of the bread comes out clean.
109
+ > 6. Let the bread cool in the pan for 10 minutes before transferring it to a wire rack to cool completely.
110
+ > 7. Slice and enjoy!
111
+ >
112
+ > Note: You can also add chocolate chips, dried fruit, or other mix-ins to the batter for extra flavor and texture. Enjoy your vegan banana bread!
113
+
114
+ ## Model Description
115
+
116
+ The architecture is a modification of a standard decoder-only transformer.
117
+
118
+ The llama-2 models have been modified from a standard transformer in the following ways:
119
+ * It uses [grouped-query attention](https://arxiv.org/pdf/2305.13245.pdf) (GQA), a generalization of multi-query attention which uses an intermediate number of key-value heads.
120
+ * It uses the [SwiGLU activation function](https://arxiv.org/abs/2002.05202)
121
+ * It uses [rotary positional embeddings](https://arxiv.org/abs/2104.09864) (RoPE)
122
+
123
+ | Hyperparameter | Value |
124
+ |----------------|-------|
125
+ | n_parameters | 70B |
126
+ | tokens | 2.0T |
127
+ | vocab size | 32000 |
128
+ | sequence length | 4096 |
129
+
130
+ ## Finetuning Description
131
+
132
+ This model was trained on a single H100 (80 GB PCIe) for about 17 hours using the [Lambda Labs](https://cloud.lambdalabs.com/instances) platform.
133
+
134
+ ![loss curves](https://raw.githubusercontent.com/daniel-furman/sft-demos/main/assets/jul_24_23_1_14_00_log_loss_curves_llama-2-70b-dolphin.png)
135
+
136
+ The above loss curve was generated from the run's private wandb.ai log.
137
+
138
+ ## PreTraining Data
139
+
140
+ For more details on the pretraining process, see [Llama-2-70b-hf](https://huggingface.co/meta-llama/Llama-2-70b-hf).
141
+
142
+ The data was tokenized using the [Llama-2-70b-hf](https://huggingface.co/meta-llama/Llama-2-70b-hf) tokenizer.
143
+
144
+ ## Limitations and Biases
145
+
146
+ _The following language is modified from [EleutherAI's GPT-NeoX-20B](https://huggingface.co/EleutherAI/gpt-neox-20b)_
147
+
148
+ This model can produce factually incorrect output, and should not be relied on to produce factually accurate information.
149
+ This model was trained on various public datasets.
150
+ While great efforts have been taken to clean the pretraining data, it is possible that this model could generate lewd, biased or otherwise offensive outputs.
151
+
152
+ ## How to Use
153
+
154
+ Basic usage: [notebook](assets/basic_inference_llama_2_70b_dolphin.ipynb)
155
+
156
+ Install and import the package dependencies:
157
+
158
+ ```python
159
+ !pip install -q -U huggingface_hub peft transformers torch accelerate
160
+ ```
161
+
162
+ ```python
163
+ import torch
164
+ from peft import PeftModel, PeftConfig
165
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
166
+ ```
167
+
168
+ Sign into a HF account with access to Llama-2:
169
+
170
+ ```python
171
+ from huggingface_hub import notebook_login
172
+ notebook_login()
173
+ ```
174
+
175
+ Basic model loading:
176
+
177
+ ```python
178
+ peft_model_id = "dfurman/llama-2-70b-dolphin-peft"
179
+ config = PeftConfig.from_pretrained(peft_model_id)
180
+
181
+ bnb_config = BitsAndBytesConfig(
182
+ load_in_4bit=True,
183
+ bnb_4bit_quant_type="nf4",
184
+ bnb_4bit_compute_dtype=torch.bfloat16,
185
+ )
186
+
187
+ model = AutoModelForCausalLM.from_pretrained(
188
+ config.base_model_name_or_path,
189
+ quantization_config=bnb_config,
190
+ use_auth_token=True,
191
+ torch_dtype=torch.bfloat16,
192
+ device_map="auto",
193
+ )
194
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
195
+ tokenizer.pad_token = tokenizer.eos_token
196
+
197
+ # Load the Lora model
198
+ model = PeftModel.from_pretrained(model, peft_model_id)
199
+ ```
200
+
201
+ Once loaded, the model and tokenizer can be used with the following code:
202
+
203
+ ```python
204
+ def llama_generate(
205
+ model: AutoModelForCausalLM,
206
+ tokenizer: AutoTokenizer,
207
+ prompt: str,
208
+ max_new_tokens: int = 128,
209
+ temperature: int = 1.0,
210
+ ) -> str:
211
+ """
212
+ Initialize the pipeline
213
+ Uses Hugging Face GenerationConfig defaults
214
+ https://huggingface.co/docs/transformers/v4.29.1/en/main_classes/text_generation#transformers.GenerationConfig
215
+ Args:
216
+ model (transformers.AutoModelForCausalLM): Falcon model for text generation
217
+ tokenizer (transformers.AutoTokenizer): Tokenizer for model
218
+ prompt (str): Prompt for text generation
219
+ max_new_tokens (int, optional): Max new tokens after the prompt to generate. Defaults to 128.
220
+ temperature (float, optional): The value used to modulate the next token probabilities.
221
+ Defaults to 1.0
222
+ """
223
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
224
+
225
+ inputs = tokenizer(
226
+ [prompt],
227
+ return_tensors="pt",
228
+ return_token_type_ids=False,
229
+ ).to(
230
+ device
231
+ ) # tokenize inputs, load on device
232
+
233
+ # when running Torch modules in lower precision, it is best practice to use the torch.autocast context manager.
234
+ with torch.autocast("cuda", dtype=torch.bfloat16):
235
+ response = model.generate(
236
+ **inputs,
237
+ max_new_tokens=max_new_tokens,
238
+ temperature=temperature,
239
+ return_dict_in_generate=True,
240
+ eos_token_id=tokenizer.eos_token_id,
241
+ pad_token_id=tokenizer.pad_token_id,
242
+ )
243
+
244
+ decoded_output = tokenizer.decode(
245
+ response["sequences"][0],
246
+ skip_special_tokens=True,
247
+ ) # grab output in natural language
248
+
249
+ return decoded_output[len(prompt) :] # remove prompt from output
250
+ ```
251
+
252
+ We can now generate text! For example:
253
+
254
+ ```python
255
+ prompt = "You are a helpful assistant. Tell me a recipe for vegan banana bread.\n"
256
+
257
+ response = llama_generate(
258
+ model,
259
+ tokenizer,
260
+ prompt,
261
+ max_new_tokens=500,
262
+ temperature=0.92,
263
+ )
264
+
265
+ print(response)
266
+ ```
267
+
268
+
269
+ ### Runtime tests
270
+
271
+ | runtime / 50 tokens (sec) | GPU | attn | torch dtype | VRAM (GB) |
272
+ |:-----------------------------:|:----------------------:|:---------------------:|:-------------:|:-----------------------:|
273
+ | 4.50 | 1x H100 (80 GB PCIe) | torch | nf4 | 39 |
274
+
275
+ The above runtime stats were generated from this [notebook](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/one_gpu/llama-2/dolphin/postprocessing-llama-2-70b-dolphin-peft.ipynb).
276
+
277
+ ## Acknowledgements
278
+
279
+ This model was finetuned by Daniel Furman on July 23, 2023 and is intended primarily for research purposes.
280
+
281
+ ## Disclaimer
282
+
283
+ The license on this model does not constitute legal advice. We are not responsible for the actions of third parties who use this model. Please cosult an attorney before using this model for commercial purposes.
284
+
285
+ ## Meta citation for llama-2 blog
286
+
287
+ ```
288
+ @online{Meta2023Introducing,
289
+ author = {Meta AI},
290
+ title = {Meta and Microsoft Introduce the Next Generation of Llama},
291
+ year = {2023},
292
+ url = {https://about.fb.com/news/2023/07/llama-2/},
293
+ note = {Accessed: 2023-07-24},
294
+ urldate = {2023-07-24}
295
+ }
296
+ ```
297
+
298
  ---
299
 
300
  ### Framework versions