Text Generation
PEFT
Safetensors
mistral
conversational
Eval Results
File size: 12,564 Bytes
db3bf65
1d9cddb
77624a7
d0deb44
 
 
 
 
 
 
 
77624a7
a6d6d39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82a1688
 
d0deb44
8982cd9
a81db74
8982cd9
d0deb44
8982cd9
a3a1367
ac2cfe3
9444756
ac2cfe3
d0deb44
7e4f067
a3a1367
d0deb44
 
ac4b096
d0deb44
 
a3a1367
d0deb44
9109d1a
 
d0deb44
9109d1a
d0deb44
9109d1a
 
a1a5041
9109d1a
 
 
 
 
 
d0deb44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e4f067
d0deb44
a3a1367
d0deb44
7e4f067
d0deb44
 
 
 
 
7e4f067
d0deb44
 
169626f
d0deb44
 
 
7e4f067
d0deb44
 
 
 
 
 
 
7e4f067
 
d0deb44
 
 
 
7e4f067
d0deb44
 
 
 
 
 
 
7e4f067
d0deb44
 
 
 
 
 
 
 
 
 
 
 
 
7e4f067
d0deb44
 
 
 
 
 
7e4f067
d0deb44
7e4f067
d0deb44
7e4f067
d0deb44
 
 
 
 
 
 
 
 
5444cca
 
 
 
 
 
d0deb44
 
 
 
 
 
 
 
 
5444cca
d0deb44
 
 
5444cca
d0deb44
 
 
 
 
 
 
 
 
 
7e4f067
d0deb44
 
 
 
 
 
7e4f067
d0deb44
 
 
 
 
 
 
 
7e4f067
d0deb44
 
 
7e4f067
d0deb44
61c5051
d0deb44
 
7e4f067
d0deb44
7e4f067
 
d0deb44
7e4f067
7a938fa
7e4f067
d0deb44
7e4f067
d0deb44
 
 
 
 
 
 
 
 
 
 
 
 
7e4f067
d0deb44
7e4f067
d0deb44
 
 
 
 
 
 
 
 
 
7e4f067
 
 
 
d0deb44
7e4f067
af1877b
ac2cfe3
d0deb44
6371280
 
 
d0deb44
6371280
d0deb44
 
 
 
cea9fc6
d0deb44
cea9fc6
 
4fbdb08
 
a6d6d39
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
---
license: llama2
library_name: peft
tags:
- mistral
datasets:
- jondurbin/airoboros-2.2.1
- Open-Orca/SlimOrca
- garage-bAInd/Open-Platypus
inference: false
pipeline_tag: text-generation
base_model: meta-llama/Llama-2-13b-hf
model-index:
- name: llama-2-13b-dolphin-peft
  results:
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: AI2 Reasoning Challenge (25-Shot)
      type: ai2_arc
      config: ARC-Challenge
      split: test
      args:
        num_few_shot: 25
    metrics:
    - type: acc_norm
      value: 22.7
      name: normalized accuracy
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: HellaSwag (10-Shot)
      type: hellaswag
      split: validation
      args:
        num_few_shot: 10
    metrics:
    - type: acc_norm
      value: 25.04
      name: normalized accuracy
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: MMLU (5-Shot)
      type: cais/mmlu
      config: all
      split: test
      args:
        num_few_shot: 5
    metrics:
    - type: acc
      value: 23.12
      name: accuracy
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: TruthfulQA (0-shot)
      type: truthful_qa
      config: multiple_choice
      split: validation
      args:
        num_few_shot: 0
    metrics:
    - type: mc2
      value: 0.0
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: Winogrande (5-shot)
      type: winogrande
      config: winogrande_xl
      split: validation
      args:
        num_few_shot: 5
    metrics:
    - type: acc
      value: 49.57
      name: accuracy
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
  - task:
      type: text-generation
      name: Text Generation
    dataset:
      name: GSM8k (5-shot)
      type: gsm8k
      config: main
      split: test
      args:
        num_few_shot: 5
    metrics:
    - type: acc
      value: 0.0
      name: accuracy
    source:
      url: https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query=dfurman/llama-2-13b-dolphin-peft
      name: Open LLM Leaderboard
---

<div align="center">

<img src="./assets/llama.png" width="150px">

</div>

# Llama-2-13B-Instruct-v0.2

A pretrained generative language model with 13 billion parameters geared towards instruction-following capabilities.

## Model Details

This model was built via parameter-efficient finetuning of the [meta-llama/Llama-2-13b-hf](https://huggingface.co/meta-llama/Llama-2-13b-hf) base model on the first 20k rows in each of the [jondurbin/airoboros-2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-2.2.1), [Open-Orca/SlimOrca](https://huggingface.co/datasets/Open-Orca/SlimOrca), and [garage-bAInd/Open-Platypus](https://huggingface.co/datasets/garage-bAInd/Open-Platypus) datasets.

- **Developed by:** Daniel Furman
- **Model type:** Causal language model (clm)
- **Language(s) (NLP):** English
- **License:** Apache 2.0
- **Finetuned from model:** [meta-llama/Llama-2-13b-hf](https://huggingface.co/meta-llama/Llama-2-13b-hf)

## Open LLM Leaderboard Evaluation Results
Detailed results can be found [here](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)

*Note*: The below values do not apply the [prompt formatting](https://huggingface.co/dfurman/Llama-2-13B-Instruct-v0.2#prompt-format) used to finetune the model. An action item for future development is to run these evaluation benchmarks with the formatting applied, which should increase the scores.

| Metric                | Value                     |
|-----------------------|---------------------------|
| Avg.                  | 55.14   |
| ARC (25-shot)         | 60.58          |
| HellaSwag (10-shot)   | 81.96    |
| MMLU (5-shot)         | 55.46         |
| TruthfulQA (0-shot)   | 45.71  |
| Winogrande (5-shot)   | 77.82   |
| GSM8K (5-shot)        | 9.33        |

## Basic Usage

<details>

<summary>Setup</summary>

```python
!pip install -q -U transformers peft torch accelerate einops sentencepiece
```

```python
import torch
from peft import PeftModel, PeftConfig
from transformers import (
    AutoModelForCausalLM,
    AutoTokenizer,
)
```

```python
peft_model_id = "dfurman/Llama-2-13B-Instruct-v0.2"
config = PeftConfig.from_pretrained(peft_model_id)

tokenizer = AutoTokenizer.from_pretrained(
    peft_model_id,
    use_fast=True,
    trust_remote_code=True,
)

model = AutoModelForCausalLM.from_pretrained(
    config.base_model_name_or_path,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True,
)

model = PeftModel.from_pretrained(
    model, 
    peft_model_id
)
```

</details>


```python
messages = [
    {"role": "user", "content": "Tell me a recipe for a mai tai."},
]

print("\n\n*** Prompt:")
input_ids = tokenizer.apply_chat_template(
    messages,
    tokenize=True,
    return_tensors="pt",
)
print(tokenizer.decode(input_ids[0]))

print("\n\n*** Generate:")
with torch.autocast("cuda", dtype=torch.bfloat16):
    output = model.generate(
        input_ids=input_ids.cuda(),
        max_new_tokens=1024,
        do_sample=True,
        temperature=0.7,
        return_dict_in_generate=True,
        eos_token_id=tokenizer.eos_token_id,
        pad_token_id=tokenizer.pad_token_id,
        repetition_penalty=1.2,
        no_repeat_ngram_size=5,
    )

response = tokenizer.decode(
    output["sequences"][0][len(input_ids[0]):], 
    skip_special_tokens=True
)
print(response)
```

<details>

<summary>Outputs</summary>

**Prompt**:

```python
"<s> [INST] Tell me a recipe for a mai tai. [/INST]"
```

**Generation**:

```python
"""1 ounce orange curaçao
4 ounces dark rum (I recommend using Myers's)
2 ounces light rum (Myers's is also good here)
3 ounces freshly squeezed lime juice
6 to 8 ice cubes
Shake all ingredients except the ice in a cocktail shaker until chilled, about 5 seconds. Add the ice and shake again until frosty, about another 5 seconds. Strain into an old-fashioned or double rocks glass filled with crushed ice. Garnish with an orange slice and a cherry speared on a skewer."""
```

</details>


## Speeds, Sizes, Times 

| runtime / 50 tokens (sec) | GPU  | dtype | VRAM (GB) |
|:-----------------------------:|:---------------------:|:-------------:|:-----------------------:|
| 3.99                          | 1x A100 (40 GB SXM)                | torch.bfloat16    | 30                    |

## Training

It took ~8 hours to train 3 epochs on 1x A100 (40 GB SXM).

### Prompt Format

This model was finetuned with the following format:

```python
tokenizer.chat_template = "{{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST] ' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token + ' ' }}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %}"
```

This format is available as a [chat template](https://huggingface.co/docs/transformers/main/chat_templating) via the `apply_chat_template()` method. Here's an illustrative example:

```python
messages = [
    {"role": "user", "content": "Tell me a recipe for a mai tai."},
    {"role": "assistant", "content": "1 oz light rum\n½ oz dark rum\n¼ oz orange curaçao\n2 oz pineapple juice\n¾ oz lime juice\nDash of orgeat syrup (optional)\nSplash of grenadine (for garnish, optional)\nLime wheel and cherry garnishes (optional)\n\nShake all ingredients except the splash of grenadine in a cocktail shaker over ice. Strain into an old-fashioned glass filled with fresh ice cubes. Gently pour the splash of grenadine down the side of the glass so that it sinks to the bottom. Add garnishes as desired."},
    {"role": "user", "content": "How can I make it more upscale and luxurious?"},
]

print("\n\n*** Prompt:")
input_ids = tokenizer.apply_chat_template(
    messages,
    tokenize=True,
    return_tensors="pt",
)
print(tokenizer.decode(input_ids[0]))
```

<details>

<summary>Output</summary>

```python
"<s> [INST] Tell me a recipe for a mai tai. [/INST] 1 ounce orange curaçao\n4 ounces dark rum (...) orange slice and a cherry speared on a skewer.</s>  [INST] How can I make the mai tai more upscale and luxurious? [/INST] "
```
</details>

### Training Hyperparameters


We use the [SFTTrainer](https://huggingface.co/docs/trl/main/en/sft_trainer) from `trl` to fine-tune LLMs on instruction-following datasets.

See [here](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/llama-2/sft_Llama_2_13B_Instruct_v0_2_peft.ipynb) for the finetuning code, which contains an exhaustive view of the hyperparameters employed.

The following `TrainingArguments` config was used:

- output_dir = "./results"
- num_train_epochs = 2
- auto_find_batch_size = True
- gradient_accumulation_steps = 2
- optim = "paged_adamw_32bit"
- save_strategy = "epoch"
- learning_rate = 3e-4
- lr_scheduler_type = "cosine"
- warmup_ratio = 0.03
- logging_strategy = "steps"
- logging_steps = 25
- evaluation_strategy = "no"
- bf16 = True

The following `bitsandbytes` quantization config was used:

- quant_method: bitsandbytes
- load_in_8bit: False
- load_in_4bit: True
- llm_int8_threshold: 6.0
- llm_int8_skip_modules: None
- llm_int8_enable_fp32_cpu_offload: False
- llm_int8_has_fp16_weight: False
- bnb_4bit_quant_type: nf4
- bnb_4bit_use_double_quant: False
- bnb_4bit_compute_dtype: bfloat16


## Model Card Contact

dryanfurman at gmail

## Llama-2 Research Citation

```
@misc{touvron2023llama,
      title={Llama 2: Open Foundation and Fine-Tuned Chat Models}, 
      author={Hugo Touvron and Louis Martin and Kevin Stone and Peter Albert and Amjad Almahairi and Yasmine Babaei and Nikolay Bashlykov and Soumya Batra and Prajjwal Bhargava and Shruti Bhosale and Dan Bikel and Lukas Blecher and Cristian Canton Ferrer and Moya Chen and Guillem Cucurull and David Esiobu and Jude Fernandes and Jeremy Fu and Wenyin Fu and Brian Fuller and Cynthia Gao and Vedanuj Goswami and Naman Goyal and Anthony Hartshorn and Saghar Hosseini and Rui Hou and Hakan Inan and Marcin Kardas and Viktor Kerkez and Madian Khabsa and Isabel Kloumann and Artem Korenev and Punit Singh Koura and Marie-Anne Lachaux and Thibaut Lavril and Jenya Lee and Diana Liskovich and Yinghai Lu and Yuning Mao and Xavier Martinet and Todor Mihaylov and Pushkar Mishra and Igor Molybog and Yixin Nie and Andrew Poulton and Jeremy Reizenstein and Rashi Rungta and Kalyan Saladi and Alan Schelten and Ruan Silva and Eric Michael Smith and Ranjan Subramanian and Xiaoqing Ellen Tan and Binh Tang and Ross Taylor and Adina Williams and Jian Xiang Kuan and Puxin Xu and Zheng Yan and Iliyan Zarov and Yuchen Zhang and Angela Fan and Melanie Kambadur and Sharan Narang and Aurelien Rodriguez and Robert Stojnic and Sergey Edunov and Thomas Scialom},
      year={2023},
      eprint={2307.09288},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
```

## Framework versions


- PEFT 0.6.3.dev0


# [Open LLM Leaderboard Evaluation Results](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard)
Detailed results can be found [here](https://huggingface.co/datasets/open-llm-leaderboard/details_dfurman__llama-2-13b-dolphin-peft)

|             Metric              |Value|
|---------------------------------|----:|
|Avg.                             |20.07|
|AI2 Reasoning Challenge (25-Shot)|22.70|
|HellaSwag (10-Shot)              |25.04|
|MMLU (5-Shot)                    |23.12|
|TruthfulQA (0-shot)              | 0.00|
|Winogrande (5-shot)              |49.57|
|GSM8k (5-shot)                   | 0.00|