RonanMcGovern commited on
Commit
3049ec9
·
1 Parent(s): fb30672

add model to allow for hosted inference

Browse files
Files changed (1) hide show
  1. README.md +222 -0
README.md ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-sa-3.0
3
+ datasets:
4
+ - mosaicml/dolly_hhrlhf
5
+ tags:
6
+ - Composer
7
+ - MosaicML
8
+ - llm-foundry
9
+ inference: false
10
+ ---
11
+
12
+
13
+ # Llama 2 - hosted inference
14
+
15
+ This is simply an 8-bit version of the Llama-2-7B model.
16
+ - 8-bits allows the model to be below 10 GB
17
+ - This allows for hosted inference of the model on the model's home page
18
+
19
+ ~
20
+
21
+ Below follows information on the original mpt-7b-instruct model...
22
+
23
+
24
+ # MPT-7B-Instruct
25
+
26
+ MPT-7B-Instruct is a model for short-form instruction following.
27
+ It is built by finetuning [MPT-7B](https://huggingface.co/mosaicml/mpt-7b) on a [dataset](https://huggingface.co/datasets/sam-mosaic/dolly_hhrlhf) derived from the [Databricks Dolly-15k](https://huggingface.co/datasets/databricks/databricks-dolly-15k) and the [Anthropic Helpful and Harmless (HH-RLHF)](https://huggingface.co/datasets/Anthropic/hh-rlhf) datasets.
28
+ * License: _CC-By-SA-3.0_
29
+ * [Demo on Hugging Face Spaces](https://huggingface.co/spaces/mosaicml/mpt-7b-instruct)
30
+
31
+
32
+ This model was trained by [MosaicML](https://www.mosaicml.com) and follows a modified decoder-only transformer architecture.
33
+
34
+ ## Model Date
35
+
36
+ May 5, 2023
37
+
38
+ ## Model License
39
+
40
+ CC-By-SA-3.0
41
+
42
+ ## Documentation
43
+
44
+ * [Blog post: Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs](https://www.mosaicml.com/blog/mpt-7b)
45
+ * [Codebase (mosaicml/llm-foundry repo)](https://github.com/mosaicml/llm-foundry/)
46
+ * Questions: Feel free to contact us via the [MosaicML Community Slack](https://mosaicml.me/slack)!
47
+
48
+ ### Example Question/Instruction
49
+
50
+ **Longboi24**:
51
+ > What is a quoll?
52
+
53
+ **MPT-7B-Instruct**:
54
+
55
+ >A Quoll (pronounced “cool”) is one of Australia’s native carnivorous marsupial mammals, which are also known as macropods or wallabies in other parts around Asia and South America
56
+
57
+ ## How to Use
58
+
59
+ Note: This model requires that `trust_remote_code=True` be passed to the `from_pretrained` method. This is because we use a custom model architecture that is not yet part of the `transformers` package.
60
+
61
+ It includes options for many training efficiency features such as [FlashAttention (Dao et al. 2022)](https://arxiv.org/pdf/2205.14135.pdf), [ALiBi](https://arxiv.org/abs/2108.12409), QK LayerNorm, and more.
62
+
63
+ ```python
64
+ import transformers
65
+ model = transformers.AutoModelForCausalLM.from_pretrained(
66
+ 'mosaicml/mpt-7b-instruct',
67
+ trust_remote_code=True
68
+ )
69
+ ```
70
+ Note: This model requires that `trust_remote_code=True` be passed to the `from_pretrained` method.
71
+ This is because we use a custom `MPT` model architecture that is not yet part of the Hugging Face `transformers` package.
72
+ `MPT` includes options for many training efficiency features such as [FlashAttention](https://arxiv.org/pdf/2205.14135.pdf), [ALiBi](https://arxiv.org/abs/2108.12409), [QK LayerNorm](https://arxiv.org/abs/2010.04245), and more.
73
+
74
+ To use the optimized [triton implementation](https://github.com/openai/triton) of FlashAttention, you can load the model on GPU (`cuda:0`) with `attn_impl='triton'` and with `bfloat16` precision:
75
+ ```python
76
+ import torch
77
+ import transformers
78
+
79
+ name = 'mosaicml/mpt-7b-instruct'
80
+
81
+ config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
82
+ config.attn_config['attn_impl'] = 'triton'
83
+ config.init_device = 'cuda:0' # For fast initialization directly on GPU!
84
+
85
+ model = transformers.AutoModelForCausalLM.from_pretrained(
86
+ name,
87
+ config=config,
88
+ torch_dtype=torch.bfloat16, # Load model weights in bfloat16
89
+ trust_remote_code=True
90
+ )
91
+ ```
92
+
93
+ Although the model was trained with a sequence length of 2048, ALiBi enables users to increase the maximum sequence length during finetuning and/or inference. For example:
94
+
95
+ ```python
96
+ import transformers
97
+
98
+ name = 'mosaicml/mpt-7b-instruct'
99
+
100
+ config = transformers.AutoConfig.from_pretrained(name, trust_remote_code=True)
101
+ config.max_seq_len = 4096 # (input + output) tokens can now be up to 4096
102
+
103
+ model = transformers.AutoModelForCausalLM.from_pretrained(
104
+ name,
105
+ config=config,
106
+ trust_remote_code=True
107
+ )
108
+ ```
109
+
110
+ This model was trained with the [EleutherAI/gpt-neox-20b](https://huggingface.co/EleutherAI/gpt-neox-20b) tokenizer.
111
+
112
+ ```python
113
+ from transformers import AutoTokenizer
114
+ tokenizer = AutoTokenizer.from_pretrained("EleutherAI/gpt-neox-20b")
115
+ ```
116
+
117
+ The model can then be used, for example, within a text-generation pipeline.
118
+ Note: when running Torch modules in lower precision, it is best practice to use the [torch.autocast context manager](https://pytorch.org/docs/stable/amp.html).
119
+
120
+ ```python
121
+ from transformers import pipeline
122
+
123
+ pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
124
+
125
+ with torch.autocast('cuda', dtype=torch.bfloat16):
126
+ print(
127
+ pipe('Here is a recipe for vegan banana bread:\n',
128
+ max_new_tokens=100,
129
+ do_sample=True,
130
+ use_cache=True))
131
+ ```
132
+
133
+ ### Formatting
134
+
135
+ This model was trained on data formatted in the dolly-15k format:
136
+
137
+ ```python
138
+ INSTRUCTION_KEY = "### Instruction:"
139
+ RESPONSE_KEY = "### Response:"
140
+ INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
141
+ PROMPT_FOR_GENERATION_FORMAT = """{intro}
142
+ {instruction_key}
143
+ {instruction}
144
+ {response_key}
145
+ """.format(
146
+ intro=INTRO_BLURB,
147
+ instruction_key=INSTRUCTION_KEY,
148
+ instruction="{instruction}",
149
+ response_key=RESPONSE_KEY,
150
+ )
151
+
152
+ example = "James decides to run 3 sprints 3 times a week. He runs 60 meters each sprint. How many total meters does he run a week? Explain before answering."
153
+ fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
154
+ ```
155
+
156
+ In the above example, `fmt_ex` is ready to be tokenized and sent through the model.
157
+
158
+ ## Model Description
159
+
160
+ The architecture is a modification of a standard decoder-only transformer.
161
+
162
+ The model has been modified from a standard transformer in the following ways:
163
+ * It uses [FlashAttention](https://arxiv.org/pdf/2205.14135.pdf)
164
+ * It uses [ALiBi (Attention with Linear Biases)](https://arxiv.org/abs/2108.12409) and does not use positional embeddings
165
+ * It does not use biases
166
+
167
+
168
+ | Hyperparameter | Value |
169
+ |----------------|-------|
170
+ |n_parameters | 6.7B |
171
+ |n_layers | 32 |
172
+ | n_heads | 32 |
173
+ | d_model | 4096 |
174
+ | vocab size | 50432 |
175
+ | sequence length | 2048 |
176
+
177
+ ## PreTraining Data
178
+
179
+ For more details on the pretraining process, see [MPT-7B](https://huggingface.co/mosaicml/mpt-7b).
180
+
181
+ The data was tokenized using the [EleutherAI/gpt-neox-20b](https://huggingface.co/EleutherAI/gpt-neox-20b) tokenizer.
182
+
183
+ ### Training Configuration
184
+
185
+ This model was trained on 8 A100-40GBs for about 2.3 hours using the [MosaicML Platform](https://www.mosaicml.com/platform).
186
+ The model was trained with sharded data parallelism using [FSDP](https://pytorch.org/docs/stable/fsdp.html) and used the AdamW optimizer.
187
+
188
+ ## Limitations and Biases
189
+
190
+ _The following language is modified from [EleutherAI's GPT-NeoX-20B](https://huggingface.co/EleutherAI/gpt-neox-20b)_
191
+
192
+ MPT-7B-Instruct can produce factually incorrect output, and should not be relied on to produce factually accurate information.
193
+ MPT-7B-Instruct was trained on various public datasets.
194
+ 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.
195
+
196
+
197
+ ## Acknowledgements
198
+
199
+ This model was finetuned by Sam Havens and the MosaicML NLP team
200
+
201
+ ## MosaicML Platform
202
+
203
+ If you're interested in [training](https://www.mosaicml.com/training) and [deploying](https://www.mosaicml.com/inference) your own MPT or LLMs on the MosaicML Platform, [sign up here](https://forms.mosaicml.com/demo?utm_source=huggingface&utm_medium=referral&utm_campaign=mpt-7b).
204
+
205
+ ## Disclaimer
206
+
207
+ 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.
208
+
209
+ ## Citation
210
+
211
+ Please cite this model using the following format:
212
+
213
+ ```
214
+ @online{MosaicML2023Introducing,
215
+ author = {MosaicML NLP Team},
216
+ title = {Introducing MPT-7B: A New Standard for Open-Source, Commercially Usable LLMs},
217
+ year = {2023},
218
+ url = {www.mosaicml.com/blog/mpt-7b},
219
+ note = {Accessed: 2023-03-28}, % change this date
220
+ urldate = {2023-03-28} % change this date
221
+ }
222
+ ```