Text Generation
PEFT
Safetensors
mistral
conversational
Eval Results
dfurman commited on
Commit
d0deb44
1 Parent(s): 7e4f067

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +217 -162
README.md CHANGED
@@ -1,208 +1,263 @@
1
  ---
 
2
  library_name: peft
 
 
 
 
 
 
 
 
3
  base_model: meta-llama/Llama-2-13b-hf
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
11
 
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
 
141
- ## Environmental Impact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
 
 
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
 
152
 
153
- ## Technical Specifications [optional]
 
 
 
 
 
 
154
 
155
- ### Model Architecture and Objective
156
 
157
- [More Information Needed]
 
 
 
158
 
159
- ### Compute Infrastructure
 
 
 
 
 
 
160
 
161
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
- #### Hardware
 
 
 
 
 
164
 
165
- [More Information Needed]
166
 
167
- #### Software
168
 
169
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
 
171
- ## Citation [optional]
 
 
 
 
 
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
 
 
 
174
 
175
- **BibTeX:**
 
 
176
 
177
- [More Information Needed]
 
 
 
178
 
179
- **APA:**
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
 
187
- [More Information Needed]
188
 
189
- ## More Information [optional]
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
- [More Information Needed]
192
 
193
- ## Model Card Authors [optional]
 
 
 
 
 
 
 
 
 
194
 
195
- [More Information Needed]
196
 
197
  ## Model Card Contact
198
 
199
- [More Information Needed]
200
-
201
 
202
- ## Training procedure
203
 
 
 
 
 
 
 
 
 
 
 
204
 
205
- ### Framework versions
206
 
207
 
208
  - PEFT 0.6.3.dev0
 
1
  ---
2
+ license: apache-2.0
3
  library_name: peft
4
+ tags:
5
+ - mistral
6
+ datasets:
7
+ - jondurbin/airoboros-2.2.1
8
+ - Open-Orca/SlimOrca
9
+ - garage-bAInd/Open-Platypus
10
+ inference: false
11
+ pipeline_tag: text-generation
12
  base_model: meta-llama/Llama-2-13b-hf
13
  ---
14
 
15
+ <div align="center">
16
 
17
+ <img src="./logo.png" width="110px">
18
 
19
+ </div>
20
 
21
 
22
+ # Mistral-7B-Instruct-v0.2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ A pretrained generative language model with 7 billion parameters geared towards instruction-following capabilities.
25
 
26
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ This model was built via parameter-efficient finetuning of the [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) 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.
29
+
30
+ - **Developed by:** Daniel Furman
31
+ - **Model type:** Decoder-only
32
+ - **Language(s) (NLP):** English
33
+ - **License:** Apache 2.0
34
+ - **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
35
+
36
+ ## Model Sources
37
+
38
+ - **Repository:** [here](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/mistral/sft_Mistral_7B_Instruct_v0_1_peft.ipynb)
39
+
40
+ ## Evaluation Results
41
+
42
+ | Metric | Value |
43
+ |-----------------------|-------|
44
+ | MMLU (5-shot) | Coming |
45
+ | ARC (25-shot) | Coming |
46
+ | HellaSwag (10-shot) | Coming |
47
+ | TruthfulQA (0-shot) | Coming |
48
+ | Avg. | Coming |
49
+
50
+ We use Eleuther.AI's [Language Model Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness) to run the benchmark tests above, the same version as Hugging Face's [Open LLM Leaderboard](https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard).
51
+
52
+ ## Basic Usage
53
+
54
+ <details>
55
+
56
+ <summary>Setup</summary>
57
+
58
+ ```python
59
+ !pip install -q -U transformers peft torch accelerate einops sentencepiece
60
+ ```
61
+
62
+ ```python
63
+ import torch
64
+ from peft import PeftModel, PeftConfig
65
+ from transformers import (
66
+ AutoModelForCausalLM,
67
+ AutoTokenizer,
68
+ )
69
+ ```
70
 
71
+ ```python
72
+ peft_model_id = "dfurman/Mistral-7B-Instruct-v0.2"
73
+ config = PeftConfig.from_pretrained(peft_model_id)
74
 
75
+ tokenizer = AutoTokenizer.from_pretrained(
76
+ peft_model_id,
77
+ use_fast=True,
78
+ trust_remote_code=True,
79
+ )
80
 
81
+ model = AutoModelForCausalLM.from_pretrained(
82
+ config.base_model_name_or_path,
83
+ torch_dtype=torch.float16,
84
+ device_map="auto",
85
+ trust_remote_code=True,
86
+ )
87
 
88
+ model = PeftModel.from_pretrained(
89
+ model,
90
+ peft_model_id
91
+ )
92
+ ```
93
+
94
+ </details>
95
 
 
96
 
97
+ ```python
98
+ messages = [
99
+ {"role": "user", "content": "Tell me a recipe for a mai tai."},
100
+ ]
101
 
102
+ print("\n\n*** Prompt:")
103
+ input_ids = tokenizer.apply_chat_template(
104
+ messages,
105
+ tokenize=True,
106
+ return_tensors="pt",
107
+ )
108
+ print(tokenizer.decode(input_ids[0]))
109
 
110
+ print("\n\n*** Generate:")
111
+ with torch.autocast("cuda", dtype=torch.bfloat16):
112
+ output = model.generate(
113
+ input_ids=input_ids.cuda(),
114
+ max_new_tokens=1024,
115
+ do_sample=True,
116
+ temperature=0.7,
117
+ return_dict_in_generate=True,
118
+ eos_token_id=tokenizer.eos_token_id,
119
+ pad_token_id=tokenizer.pad_token_id,
120
+ repetition_penalty=1.2,
121
+ no_repeat_ngram_size=5,
122
+ )
123
 
124
+ response = tokenizer.decode(
125
+ output["sequences"][0][len(input_ids[0]):],
126
+ skip_special_tokens=True
127
+ )
128
+ print(response)
129
+ ```
130
 
131
+ <details>
132
 
133
+ <summary>Outputs</summary>
134
 
135
+ **Prompt**:
136
+
137
+ ```python
138
+ "<s> [INST] Tell me a recipe for a mai tai. [/INST]"
139
+ ```
140
+
141
+ **Generation**:
142
+
143
+ ```python
144
+ """1. Combine the following ingredients in a cocktail shaker:
145
+ 2 oz light rum (or white rum)
146
+ 1 oz dark rum
147
+ 0.5 oz orange curacao or triple sec
148
+ 0.75 oz lime juice, freshly squeezed
149
+ 0.5 tbsp simple syrup (optional; if you like your drinks sweet)
150
+ Few drops of bitters (Angostura is traditional but any will do)
151
+ Ice cubes to fill the shaker
152
+
153
+ 2. Shake vigorously until well-chilled and combined.
154
+ 3. Strain into an ice-filled glass.
155
+ 4. Garnish with a slice of lime or an orange wedge, if desired."""
156
+ ```
157
+
158
+ </details>
159
+
160
+
161
+ ## Speeds, Sizes, Times
162
+
163
+ | runtime / 50 tokens (sec) | GPU | dtype | VRAM (GB) |
164
+ |:-----------------------------:|:---------------------:|:-------------:|:-----------------------:|
165
+ | 3.21 | 1x A100 (40 GB SXM) | torch.bfloat16 | 16 |
166
+
167
+ ## Training
168
+
169
+ It took ~5 hours to train 3 epochs on 1x A100 (40 GB SXM).
170
+
171
+ ### Prompt Format
172
+
173
+ This model was finetuned with the following format:
174
+
175
+ ```python
176
+ 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 %}"
177
+ ```
178
+
179
+ 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:
180
 
181
+ ```python
182
+ messages = [
183
+ {"role": "user", "content": "Tell me a recipe for a mai tai."},
184
+ {"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."},
185
+ {"role": "user", "content": "How can I make it more upscale and luxurious?"},
186
+ ]
187
 
188
+ print("\n\n*** Prompt:")
189
+ input_ids = tokenizer.apply_chat_template(
190
+ messages,
191
+ tokenize=True,
192
+ return_tensors="pt",
193
+ )
194
+ print(tokenizer.decode(input_ids[0]))
195
+ ```
196
 
197
+ <details>
198
+
199
+ <summary>Output</summary>
200
 
201
+ ```python
202
+ """<s> [INST] Tell me a recipe for a mai tai. [/INST] 1 oz light rum\n½ oz dark rum\n (...) Add garnishes as desired.</s> [INST] How can I make it more upscale and luxurious? [/INST]"""
203
+ ```
204
+ </details>
205
 
206
+ ### Training Hyperparameters
207
 
 
208
 
209
+ We use the [SFTTrainer](https://huggingface.co/docs/trl/main/en/sft_trainer) from `trl` to fine-tune LLMs on instruction-following datasets.
210
 
211
+ See [here](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/mistral/sft_Mistral_7B_Instruct_v0_1_peft.ipynb) for the finetuning code, which contains an exhaustive view of the hyperparameters employed.
212
 
213
+ The following `TrainingArguments` config was used:
214
 
215
+ - output_dir = "./results"
216
+ - num_train_epochs = 2
217
+ - auto_find_batch_size = True
218
+ - gradient_accumulation_steps = 2
219
+ - optim = "paged_adamw_32bit"
220
+ - save_strategy = "epoch"
221
+ - learning_rate = 3e-4
222
+ - lr_scheduler_type = "cosine"
223
+ - warmup_ratio = 0.03
224
+ - logging_strategy = "steps"
225
+ - logging_steps = 25
226
+ - evaluation_strategy = "no"
227
+ - bf16 = True
228
 
229
+ The following `bitsandbytes` quantization config was used:
230
 
231
+ - quant_method: bitsandbytes
232
+ - load_in_8bit: False
233
+ - load_in_4bit: True
234
+ - llm_int8_threshold: 6.0
235
+ - llm_int8_skip_modules: None
236
+ - llm_int8_enable_fp32_cpu_offload: False
237
+ - llm_int8_has_fp16_weight: False
238
+ - bnb_4bit_quant_type: nf4
239
+ - bnb_4bit_use_double_quant: False
240
+ - bnb_4bit_compute_dtype: bfloat16
241
 
 
242
 
243
  ## Model Card Contact
244
 
245
+ dryanfurman at gmail
 
246
 
247
+ ## Mistral Research Citation
248
 
249
+ ```
250
+ @misc{jiang2023mistral,
251
+ title={Mistral 7B},
252
+ author={Albert Q. Jiang and Alexandre Sablayrolles and Arthur Mensch and Chris Bamford and Devendra Singh Chaplot and Diego de las Casas and Florian Bressand and Gianna Lengyel and Guillaume Lample and Lucile Saulnier and Lélio Renard Lavaud and Marie-Anne Lachaux and Pierre Stock and Teven Le Scao and Thibaut Lavril and Thomas Wang and Timothée Lacroix and William El Sayed},
253
+ year={2023},
254
+ eprint={2310.06825},
255
+ archivePrefix={arXiv},
256
+ primaryClass={cs.CL}
257
+ }
258
+ ```
259
 
260
+ ## Framework versions
261
 
262
 
263
  - PEFT 0.6.3.dev0