dfurman commited on
Commit
ad2ef44
·
1 Parent(s): 4dc89e5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +193 -172
README.md CHANGED
@@ -1,205 +1,226 @@
1
  ---
 
2
  library_name: peft
 
 
 
 
 
 
3
  base_model: mistralai/Mistral-7B-v0.1
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
- - **Shared by [optional]:** [More Information Needed]
22
- - **Model type:** [More Information Needed]
23
- - **Language(s) (NLP):** [More Information Needed]
24
- - **License:** [More Information Needed]
25
- - **Finetuned from model [optional]:** [More Information Needed]
26
-
27
- ### Model Sources [optional]
28
-
29
- <!-- Provide the basic links for the model. -->
30
-
31
- - **Repository:** [More Information Needed]
32
- - **Paper [optional]:** [More Information Needed]
33
- - **Demo [optional]:** [More Information Needed]
34
-
35
- ## Uses
36
-
37
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
38
-
39
- ### Direct Use
40
-
41
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
42
-
43
- [More Information Needed]
44
-
45
- ### Downstream Use [optional]
46
-
47
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
48
-
49
- [More Information Needed]
50
-
51
- ### Out-of-Scope Use
52
-
53
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
54
-
55
- [More Information Needed]
56
-
57
- ## Bias, Risks, and Limitations
58
-
59
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
60
-
61
- [More Information Needed]
62
-
63
- ### Recommendations
64
-
65
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
66
-
67
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
68
-
69
- ## How to Get Started with the Model
70
-
71
- Use the code below to get started with the model.
72
-
73
- [More Information Needed]
74
-
75
- ## Training Details
76
-
77
- ### Training Data
78
-
79
- <!-- This should link to a Data 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. -->
80
-
81
- [More Information Needed]
82
-
83
- ### Training Procedure
84
-
85
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
86
-
87
- #### Preprocessing [optional]
88
-
89
- [More Information Needed]
90
-
91
 
92
- #### Training Hyperparameters
93
-
94
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
95
-
96
- #### Speeds, Sizes, Times [optional]
97
-
98
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
99
-
100
- [More Information Needed]
101
-
102
- ## Evaluation
103
-
104
- <!-- This section describes the evaluation protocols and provides the results. -->
105
-
106
- ### Testing Data, Factors & Metrics
107
-
108
- #### Testing Data
109
-
110
- <!-- This should link to a Data Card if possible. -->
111
-
112
- [More Information Needed]
113
-
114
- #### Factors
115
-
116
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
117
-
118
- [More Information Needed]
119
-
120
- #### Metrics
121
-
122
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
123
-
124
- [More Information Needed]
125
-
126
- ### Results
127
-
128
- [More Information Needed]
129
-
130
- #### Summary
131
-
132
-
133
-
134
- ## Model Examination [optional]
135
-
136
- <!-- Relevant interpretability work for the model goes here -->
137
-
138
- [More Information Needed]
139
-
140
- ## Environmental Impact
141
-
142
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
143
-
144
- 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).
145
-
146
- - **Hardware Type:** [More Information Needed]
147
- - **Hours used:** [More Information Needed]
148
- - **Cloud Provider:** [More Information Needed]
149
- - **Compute Region:** [More Information Needed]
150
- - **Carbon Emitted:** [More Information Needed]
151
-
152
- ## Technical Specifications [optional]
153
-
154
- ### Model Architecture and Objective
155
-
156
- [More Information Needed]
157
-
158
- ### Compute Infrastructure
159
-
160
- [More Information Needed]
161
 
162
- #### Hardware
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
- [More Information Needed]
 
 
165
 
166
- #### Software
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
- [More Information Needed]
169
 
170
- ## Citation [optional]
171
 
172
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
173
 
174
- **BibTeX:**
 
 
 
 
 
 
175
 
176
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
- **APA:**
 
 
 
179
 
180
- [More Information Needed]
181
 
182
- ## Glossary [optional]
183
 
184
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
185
 
186
- [More Information Needed]
187
 
188
- ## More Information [optional]
 
 
 
 
 
 
 
 
 
 
189
 
190
- [More Information Needed]
191
 
192
- ## Model Card Authors [optional]
 
 
 
 
 
 
 
 
 
193
 
194
- [More Information Needed]
195
 
196
  ## Model Card Contact
197
 
198
- [More Information Needed]
199
-
200
-
201
- ## Training procedure
202
-
203
 
204
  ### Framework versions
205
 
 
1
  ---
2
+ license: apache-2.0
3
  library_name: peft
4
+ tags:
5
+ - mistral
6
+ datasets:
7
+ - jondurbin/airoboros-2.2.1
8
+ inference: false
9
+ pipeline_tag: text-generation
10
  base_model: mistralai/Mistral-7B-v0.1
11
  ---
12
 
13
+ <div align="center">
14
 
15
+ <img src="./logo.png" width="150px">
16
 
17
+ </div>
18
 
19
+ # Mistral-7B-Instruct-v0.1
20
 
21
+ The Mistral-7B-Instruct-v0.1 LLM is a pretrained generative text model with 7 billion parameters geared towards instruction-following capabilities.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ 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 [jondurbin/airoboros-2.2.1](https://huggingface.co/datasets/jondurbin/airoboros-2.2.1) dataset. Finetuning was executed on 1x A100 (40 GB SXM) for roughly 3 hours.
26
+
27
+ - **Developed by:** Daniel Furman
28
+ - **Model type:** Decoder-only
29
+ - **Language(s) (NLP):** English
30
+ - **License:** Apache 2.0
31
+ - **Finetuned from model:** [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
32
+
33
+ ## Model Sources
34
+
35
+ - **Repository:** [github.com/daniel-furman/sft-demos](https://github.com/daniel-furman/sft-demos/blob/main/src/sft/one_gpu/mistral/sft-mistral-7b-instruct-peft.ipynb)
36
+
37
+ ## Evaluation Results
38
+
39
+ | Metric | Value |
40
+ |-----------------------|-------|
41
+ | MMLU (5-shot) | Coming |
42
+ | ARC (25-shot) | Coming |
43
+ | HellaSwag (10-shot) | Coming |
44
+ | TruthfulQA (0-shot) | Coming |
45
+ | Avg. | Coming |
46
+
47
+ 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).
48
+
49
+ ## Basic Usage
50
+
51
+ <details>
52
+
53
+ <summary>Setup</summary>
54
+
55
+ ```python
56
+ !pip install -q -U transformers peft torch accelerate bitsandbytes einops sentencepiece
57
+
58
+ import torch
59
+ from peft import PeftModel, PeftConfig
60
+ from transformers import (
61
+ AutoModelForCausalLM,
62
+ AutoTokenizer,
63
+ BitsAndBytesConfig,
64
+ )
65
+ ```
66
 
67
+ ```python
68
+ peft_model_id = "dfurman/Mistral-7B-Instruct-v0.1"
69
+ config = PeftConfig.from_pretrained(peft_model_id)
70
 
71
+ tokenizer = AutoTokenizer.from_pretrained(
72
+ peft_model_id,
73
+ use_fast=True,
74
+ trust_remote_code=True,
75
+ )
76
+ bnb_config = BitsAndBytesConfig(
77
+ load_in_4bit=True,
78
+ bnb_4bit_quant_type="nf4",
79
+ bnb_4bit_compute_dtype=torch.bfloat16,
80
+ )
81
+ model = AutoModelForCausalLM.from_pretrained(
82
+ config.base_model_name_or_path,
83
+ quantization_config=bnb_config,
84
+ device_map="auto",
85
+ trust_remote_code=True,
86
+ )
87
+ model = PeftModel.from_pretrained(
88
+ model,
89
+ peft_model_id
90
+ )
91
+ ```
92
 
93
+ </details>
94
 
 
95
 
96
+ ```python
97
+ messages = [
98
+ {"role": "user", "content": "Tell me a recipe for a mai tai."},
99
+ ]
100
 
101
+ print("\n\n*** Prompt:")
102
+ prompt = tokenizer.apply_chat_template(
103
+ messages,
104
+ tokenize=False,
105
+ add_generation_prompt=True
106
+ )
107
+ print(prompt)
108
 
109
+ print("\n\n*** Generate:")
110
+ input_ids = tokenizer(prompt, return_tensors="pt").input_ids.cuda()
111
+ with torch.autocast("cuda", dtype=torch.bfloat16):
112
+ output = model.generate(
113
+ input_ids=input_ids,
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>Output</summary>
134
+
135
+ **Prompt**:
136
+ ```python
137
+ coming
138
+ ```
139
+
140
+ **Generation**:
141
+ ```python
142
+ coming
143
+ ```
144
+
145
+ </details>
146
+
147
+
148
+ ## Speeds, Sizes, Times
149
+
150
+ | runtime / 50 tokens (sec) | GPU | attn | torch dtype | VRAM (GB) |
151
+ |:-----------------------------:|:----------------------:|:---------------------:|:-------------:|:-----------------------:|
152
+ | 3.1 | 1x A100 (40 GB SXM) | torch | fp16 | 13 |
153
+
154
+ ## Training
155
+
156
+ It took ~3 hours to train 3 epochs on 1x A100 (40 GB SXM).
157
+
158
+ ### Prompt Format
159
+
160
+ This model was finetuned with the following format:
161
+
162
+ ```python
163
+ 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 %}"
164
+ ```
165
+
166
+
167
+ 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:
168
+
169
+ ```python
170
+ messages = [
171
+ {"role": "user", "content": "What is your favourite condiment?"},
172
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
173
+ {"role": "user", "content": "Do you have mayonnaise recipes?"}
174
+ ]
175
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
176
+ print(prompt)
177
+ ```
178
+
179
+ <details>
180
+
181
+ <summary>Output</summary>
182
 
183
+ ```python
184
+ coming
185
+ ```
186
+ </details>
187
 
188
+ ### Training Hyperparameters
189
 
 
190
 
191
+ We use the [SFTTrainer](https://huggingface.co/docs/trl/main/en/sft_trainer) from `trl` to fine-tune LLMs on instruction-following datasets.
192
 
193
+ The following `TrainingArguments` config was used:
194
 
195
+ - num_train_epochs = 1
196
+ - auto_find_batch_size = True
197
+ - gradient_accumulation_steps = 1
198
+ - optim = "paged_adamw_32bit"
199
+ - save_strategy = "epoch"
200
+ - learning_rate = 3e-4
201
+ - lr_scheduler_type = "cosine"
202
+ - warmup_ratio = 0.03
203
+ - logging_strategy = "steps"
204
+ - logging_steps = 25
205
+ - bf16 = True
206
 
207
+ The following `bitsandbytes` quantization config was used:
208
 
209
+ - quant_method: bitsandbytes
210
+ - load_in_8bit: False
211
+ - load_in_4bit: True
212
+ - llm_int8_threshold: 6.0
213
+ - llm_int8_skip_modules: None
214
+ - llm_int8_enable_fp32_cpu_offload: False
215
+ - llm_int8_has_fp16_weight: False
216
+ - bnb_4bit_quant_type: nf4
217
+ - bnb_4bit_use_double_quant: False
218
+ - bnb_4bit_compute_dtype: bfloat16
219
 
 
220
 
221
  ## Model Card Contact
222
 
223
+ dryanfurman at gmail
 
 
 
 
224
 
225
  ### Framework versions
226