TheBloke commited on
Commit
8460da2
1 Parent(s): aa489cf

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +661 -0
README.md ADDED
@@ -0,0 +1,661 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: amazon/MistralLite
3
+ inference: false
4
+ license: apache-2.0
5
+ model_creator: Amazon Web Services
6
+ model_name: MistralLite 7B
7
+ model_type: mistral
8
+ prompt_template: '<|prompter|>{prompt}</s><|assistant|>
9
+
10
+ '
11
+ quantized_by: TheBloke
12
+ ---
13
+ <!-- markdownlint-disable MD041 -->
14
+
15
+ <!-- header start -->
16
+ <!-- 200823 -->
17
+ <div style="width: auto; margin-left: auto; margin-right: auto">
18
+ <img src="https://i.imgur.com/EBdldam.jpg" alt="TheBlokeAI" style="width: 100%; min-width: 400px; display: block; margin: auto;">
19
+ </div>
20
+ <div style="display: flex; justify-content: space-between; width: 100%;">
21
+ <div style="display: flex; flex-direction: column; align-items: flex-start;">
22
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://discord.gg/theblokeai">Chat & support: TheBloke's Discord server</a></p>
23
+ </div>
24
+ <div style="display: flex; flex-direction: column; align-items: flex-end;">
25
+ <p style="margin-top: 0.5em; margin-bottom: 0em;"><a href="https://www.patreon.com/TheBlokeAI">Want to contribute? TheBloke's Patreon page</a></p>
26
+ </div>
27
+ </div>
28
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">TheBloke's LLM work is generously supported by a grant from <a href="https://a16z.com">andreessen horowitz (a16z)</a></p></div>
29
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
30
+ <!-- header end -->
31
+
32
+ # MistralLite 7B - AWQ
33
+ - Model creator: [Amazon Web Services](https://huggingface.co/amazon)
34
+ - Original model: [MistralLite 7B](https://huggingface.co/amazon/MistralLite)
35
+
36
+ <!-- description start -->
37
+ ## Description
38
+
39
+ This repo contains AWQ model files for [Amazon Web Services's MistralLite 7B](https://huggingface.co/amazon/MistralLite).
40
+
41
+
42
+ ### About AWQ
43
+
44
+ AWQ is an efficient, accurate and blazing-fast low-bit weight quantization method, currently supporting 4-bit quantization. Compared to GPTQ, it offers faster Transformers-based inference with equivalent or better quality compared to the most commonly used GPTQ settings.
45
+
46
+ It is supported by:
47
+
48
+ - [Text Generation Webui](https://github.com/oobabooga/text-generation-webui) - using Loader: AutoAWQ
49
+ - [vLLM](https://github.com/vllm-project/vllm) - Llama and Mistral models only
50
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference)
51
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) - for use from Python code
52
+
53
+ <!-- description end -->
54
+ <!-- repositories-available start -->
55
+ ## Repositories available
56
+
57
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/MistralLite-7B-AWQ)
58
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ)
59
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/MistralLite-7B-GGUF)
60
+ * [Amazon Web Services's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/amazon/MistralLite)
61
+ <!-- repositories-available end -->
62
+
63
+ <!-- prompt-template start -->
64
+ ## Prompt template: Amazon
65
+
66
+ ```
67
+ <|prompter|>{prompt}</s><|assistant|>
68
+
69
+ ```
70
+
71
+ <!-- prompt-template end -->
72
+
73
+
74
+ <!-- README_AWQ.md-provided-files start -->
75
+ ## Provided files, and AWQ parameters
76
+
77
+ For my first release of AWQ models, I am releasing 128g models only. I will consider adding 32g as well if there is interest, and once I have done perplexity and evaluation comparisons, but at this time 32g models are still not fully tested with AutoAWQ and vLLM.
78
+
79
+ Models are released as sharded safetensors files.
80
+
81
+ | Branch | Bits | GS | AWQ Dataset | Seq Len | Size |
82
+ | ------ | ---- | -- | ----------- | ------- | ---- |
83
+ | [main](https://huggingface.co/TheBloke/MistralLite-7B-AWQ/tree/main) | 4 | 128 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 4.15 GB
84
+
85
+ <!-- README_AWQ.md-provided-files end -->
86
+
87
+ <!-- README_AWQ.md-text-generation-webui start -->
88
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
89
+
90
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
91
+
92
+ It is strongly recommended to use the text-generation-webui one-click-installers unless you're sure you know how to make a manual install.
93
+
94
+ 1. Click the **Model tab**.
95
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/MistralLite-7B-AWQ`.
96
+ 3. Click **Download**.
97
+ 4. The model will start downloading. Once it's finished it will say "Done".
98
+ 5. In the top left, click the refresh icon next to **Model**.
99
+ 6. In the **Model** dropdown, choose the model you just downloaded: `MistralLite-7B-AWQ`
100
+ 7. Select **Loader: AutoAWQ**.
101
+ 8. Click Load, and the model will load and is now ready for use.
102
+ 9. If you want any custom settings, set them and then click **Save settings for this model** followed by **Reload the Model** in the top right.
103
+ 10. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
104
+ <!-- README_AWQ.md-text-generation-webui end -->
105
+
106
+ <!-- README_AWQ.md-use-from-vllm start -->
107
+ ## Multi-user inference server: vLLM
108
+
109
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
110
+
111
+ - Please ensure you are using vLLM version 0.2 or later.
112
+ - When using vLLM as a server, pass the `--quantization awq` parameter.
113
+
114
+ For example:
115
+
116
+ ```shell
117
+ python3 python -m vllm.entrypoints.api_server --model TheBloke/MistralLite-7B-AWQ --quantization awq
118
+ ```
119
+
120
+ - When using vLLM from Python code, again set `quantization=awq`.
121
+
122
+ For example:
123
+
124
+ ```python
125
+ from vllm import LLM, SamplingParams
126
+
127
+ prompts = [
128
+ "Tell me about AI",
129
+ "Write a story about llamas",
130
+ "What is 291 - 150?",
131
+ "How much wood would a woodchuck chuck if a woodchuck could chuck wood?",
132
+ ]
133
+ prompt_template=f'''<|prompter|>{prompt}</s><|assistant|>
134
+ '''
135
+
136
+ prompts = [prompt_template.format(prompt=prompt) for prompt in prompts]
137
+
138
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
139
+
140
+ llm = LLM(model="TheBloke/MistralLite-7B-AWQ", quantization="awq", dtype="auto")
141
+
142
+ outputs = llm.generate(prompts, sampling_params)
143
+
144
+ # Print the outputs.
145
+ for output in outputs:
146
+ prompt = output.prompt
147
+ generated_text = output.outputs[0].text
148
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
149
+ ```
150
+ <!-- README_AWQ.md-use-from-vllm start -->
151
+
152
+ <!-- README_AWQ.md-use-from-tgi start -->
153
+ ## Multi-user inference server: Hugging Face Text Generation Inference (TGI)
154
+
155
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
156
+
157
+ Example Docker parameters:
158
+
159
+ ```shell
160
+ --model-id TheBloke/MistralLite-7B-AWQ --port 3000 --quantize awq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
161
+ ```
162
+
163
+ Example Python code for interfacing with TGI (requires [huggingface-hub](https://github.com/huggingface/huggingface_hub) 0.17.0 or later):
164
+
165
+ ```shell
166
+ pip3 install huggingface-hub
167
+ ```
168
+
169
+ ```python
170
+ from huggingface_hub import InferenceClient
171
+
172
+ endpoint_url = "https://your-endpoint-url-here"
173
+
174
+ prompt = "Tell me about AI"
175
+ prompt_template=f'''<|prompter|>{prompt}</s><|assistant|>
176
+ '''
177
+
178
+ client = InferenceClient(endpoint_url)
179
+ response = client.text_generation(prompt,
180
+ max_new_tokens=128,
181
+ do_sample=True,
182
+ temperature=0.7,
183
+ top_p=0.95,
184
+ top_k=40,
185
+ repetition_penalty=1.1)
186
+
187
+ print(f"Model output: ", response)
188
+ ```
189
+ <!-- README_AWQ.md-use-from-tgi end -->
190
+
191
+ <!-- README_AWQ.md-use-from-python start -->
192
+ ## Inference from Python code using AutoAWQ
193
+
194
+ ### Install the AutoAWQ package
195
+
196
+ Requires: [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) 0.1.1 or later.
197
+
198
+ ```shell
199
+ pip3 install autoawq
200
+ ```
201
+
202
+ If you have problems installing [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) using the pre-built wheels, install it from source instead:
203
+
204
+ ```shell
205
+ pip3 uninstall -y autoawq
206
+ git clone https://github.com/casper-hansen/AutoAWQ
207
+ cd AutoAWQ
208
+ pip3 install .
209
+ ```
210
+
211
+ ### AutoAWQ example code
212
+
213
+ ```python
214
+ from awq import AutoAWQForCausalLM
215
+ from transformers import AutoTokenizer
216
+
217
+ model_name_or_path = "TheBloke/MistralLite-7B-AWQ"
218
+
219
+ # Load tokenizer
220
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=False)
221
+ # Load model
222
+ model = AutoAWQForCausalLM.from_quantized(model_name_or_path, fuse_layers=True,
223
+ trust_remote_code=False, safetensors=True)
224
+
225
+ prompt = "Tell me about AI"
226
+ prompt_template=f'''<|prompter|>{prompt}</s><|assistant|>
227
+ '''
228
+
229
+ print("*** Running model.generate:")
230
+
231
+ token_input = tokenizer(
232
+ prompt_template,
233
+ return_tensors='pt'
234
+ ).input_ids.cuda()
235
+
236
+ # Generate output
237
+ generation_output = model.generate(
238
+ token_input,
239
+ do_sample=True,
240
+ temperature=0.7,
241
+ top_p=0.95,
242
+ top_k=40,
243
+ max_new_tokens=512
244
+ )
245
+
246
+ # Get the tokens from the output, decode them, print them
247
+ token_output = generation_output[0]
248
+ text_output = tokenizer.decode(token_output)
249
+ print("LLM output: ", text_output)
250
+
251
+ """
252
+ # Inference should be possible with transformers pipeline as well in future
253
+ # But currently this is not yet supported by AutoAWQ (correct as of September 25th 2023)
254
+ from transformers import pipeline
255
+
256
+ print("*** Pipeline:")
257
+ pipe = pipeline(
258
+ "text-generation",
259
+ model=model,
260
+ tokenizer=tokenizer,
261
+ max_new_tokens=512,
262
+ do_sample=True,
263
+ temperature=0.7,
264
+ top_p=0.95,
265
+ top_k=40,
266
+ repetition_penalty=1.1
267
+ )
268
+
269
+ print(pipe(prompt_template)[0]['generated_text'])
270
+ """
271
+ ```
272
+ <!-- README_AWQ.md-use-from-python end -->
273
+
274
+ <!-- README_AWQ.md-compatibility start -->
275
+ ## Compatibility
276
+
277
+ The files provided are tested to work with:
278
+
279
+ - [text-generation-webui](https://github.com/oobabooga/text-generation-webui) using `Loader: AutoAWQ`.
280
+ - [vLLM](https://github.com/vllm-project/vllm) version 0.2.0 and later.
281
+ - [Hugging Face Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) version 1.1.0 and later.
282
+ - [AutoAWQ](https://github.com/casper-hansen/AutoAWQ) version 0.1.1 and later.
283
+
284
+ <!-- README_AWQ.md-compatibility end -->
285
+
286
+ <!-- footer start -->
287
+ <!-- 200823 -->
288
+ ## Discord
289
+
290
+ For further support, and discussions on these models and AI in general, join us at:
291
+
292
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
293
+
294
+ ## Thanks, and how to contribute
295
+
296
+ Thanks to the [chirper.ai](https://chirper.ai) team!
297
+
298
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
299
+
300
+ I've had a lot of people ask if they can contribute. I enjoy providing models and helping people, and would love to be able to spend even more time doing it, as well as expanding into new projects like fine tuning/training.
301
+
302
+ If you're able and willing to contribute it will be most gratefully received and will help me to keep providing more models, and to start work on new AI projects.
303
+
304
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
305
+
306
+ * Patreon: https://patreon.com/TheBlokeAI
307
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
308
+
309
+ **Special thanks to**: Aemon Algiz.
310
+
311
+ **Patreon special mentions**: Pierre Kircher, Stanislav Ovsiannikov, Michael Levine, Eugene Pentland, Andrey, 준교 김, Randy H, Fred von Graf, Artur Olbinski, Caitlyn Gatomon, terasurfer, Jeff Scroggin, James Bentley, Vadim, Gabriel Puliatti, Harry Royden McLaughlin, Sean Connelly, Dan Guido, Edmond Seymore, Alicia Loh, subjectnull, AzureBlack, Manuel Alberto Morcote, Thomas Belote, Lone Striker, Chris Smitley, Vitor Caleffi, Johann-Peter Hartmann, Clay Pascal, biorpg, Brandon Frisco, sidney chen, transmissions 11, Pedro Madruga, jinyuan sun, Ajan Kanaga, Emad Mostaque, Trenton Dambrowitz, Jonathan Leane, Iucharbius, usrbinkat, vamX, George Stoitzev, Luke Pendergrass, theTransient, Olakabola, Swaroop Kallakuri, Cap'n Zoog, Brandon Phillips, Michael Dempsey, Nikolai Manek, danny, Matthew Berman, Gabriel Tamborski, alfie_i, Raymond Fosdick, Tom X Nguyen, Raven Klaugh, LangChain4j, Magnesian, Illia Dulskyi, David Ziegler, Mano Prime, Luis Javier Navarrete Lozano, Erik Bjäreholt, 阿明, Nathan Dryer, Alex, Rainer Wilmers, zynix, TL, Joseph William Delisle, John Villwock, Nathan LeClaire, Willem Michiel, Joguhyik, GodLy, OG, Alps Aficionado, Jeffrey Morgan, ReadyPlayerEmma, Tiffany J. Kim, Sebastain Graf, Spencer Kim, Michael Davis, webtim, Talal Aujan, knownsqashed, John Detwiler, Imad Khwaja, Deo Leter, Jerry Meng, Elijah Stavena, Rooh Singh, Pieter, SuperWojo, Alexandros Triantafyllidis, Stephen Murray, Ai Maven, ya boyyy, Enrico Ros, Ken Nordquist, Deep Realms, Nicholas, Spiking Neurons AB, Elle, Will Dee, Jack West, RoA, Luke @flexchar, Viktor Bowallius, Derek Yates, Subspace Studios, jjj, Toran Billups, Asp the Wyvern, Fen Risland, Ilya, NimbleBox.ai, Chadd, Nitin Borwankar, Emre, Mandus, Leonard Tan, Kalila, K, Trailburnt, S_X, Cory Kujawski
312
+
313
+
314
+ Thank you to all my generous patrons and donaters!
315
+
316
+ And thank you again to a16z for their generous grant.
317
+
318
+ <!-- footer end -->
319
+
320
+ # Original model card: Amazon Web Services's MistralLite 7B
321
+
322
+
323
+ # MistralLite Model
324
+
325
+ MistralLite is a fine-tuned [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) language model, with enhanced capabilities of processing long context (up to 32K tokens). By utilizing an adapted Rotary Embedding and sliding window during fine-tuning, MistralLite is able to **perform significantly better on several long context retrieve and answering tasks**, while keeping the simple model structure of the original model. MistralLite is useful for applications such as long context line and topic retrieval, summarization, question-answering, and etc. MistralLite can be deployed on a single AWS `g5.2x` instance with Sagemaker [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) endpoint, making it suitable for applications that require high performance in resource-constrained environments. You can also serve the MistralLite model directly using TGI docker containers. Also, MistralLite supports other ways of serving like [vLLM](https://github.com/vllm-project/vllm), and you can use MistralLite in Python by using the [HuggingFace transformers](https://huggingface.co/docs/transformers/index) and [FlashAttention-2](https://github.com/Dao-AILab/flash-attention) library.
326
+
327
+ MistralLite is similar to [Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1), and their similarities and differences are summarized below:
328
+ |Model|Fine-tuned on long contexts| Max context length| RotaryEmbedding adaptation| Sliding Window Size|
329
+ |----------|-------------:|------------:|-----------:|-----------:|
330
+ | Mistral-7B-Instruct-v0.1 | up to 8K tokens | 32K | rope_theta = 10000 | 4096 |
331
+ | MistralLite | up to 16K tokens | 32K | **rope_theta = 1000000** | **16384** |
332
+
333
+ ## Motivation of Developing MistralLite
334
+
335
+ Since the release of [Mistral-7B-Instruct-v0.1](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.1), the model became increasingly popular because its strong performance
336
+ on a wide range of benchmarks. But most of the benchmarks are evaluated on `short context`, and not much has been investigated on its performance on long context tasks.
337
+ Then We evaluated `Mistral-7B-Instruct-v0.1` against benchmarks that are specifically designed to assess the capabilities of LLMs in handling longer context.
338
+ Although the performance of the models on long context was fairly competitive on long context less than 4096 tokens,
339
+ there were some limitations on its performance on longer context. Motivated by improving its performance on longer context, we finetuned the Mistral 7B model, and produced `Mistrallite`. The model managed to `significantly boost the performance of long context handling` over Mistral-7B-Instruct-v0.1. The detailed `long context evalutaion results` are as below:
340
+
341
+ 1. [Topic Retrieval](https://lmsys.org/blog/2023-06-29-longchat/)
342
+ |Model Name|Input length| Input length | Input length| Input length| Input length|
343
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|
344
+ | | 2851| 5568 |8313 | 11044 | 13780
345
+ | Mistral-7B-Instruct-v0.1 | 100% | 50% | 2% | 0% | 0% |
346
+ | MistralLite | **100%** | **100%** | **100%** | **100%** | **98%** |
347
+
348
+ 2. [Line Retrieval](https://lmsys.org/blog/2023-06-29-longchat/#longeval-results)
349
+
350
+ |Model Name|Input length| Input length | Input length| Input length| Input length|Input length|
351
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|-----------:|
352
+ | | 3818| 5661 |7505 | 9354 | 11188 | 12657
353
+ | Mistral-7B-Instruct-v0.1 | **98%** | 62% | 42% | 42% | 32% | 30% |
354
+ | MistralLite | **98%** | **92%** | **88%** | **76%** | **70%** | **60%** |
355
+
356
+ 3. [Pass key Retrieval](https://github.com/epfml/landmark-attention/blob/main/llama/run_test.py#L101)
357
+
358
+ |Model Name|Input length| Input length | Input length| Input length|
359
+ |----------|-------------:|-------------:|------------:|-----------:|
360
+ | | 3264| 5396 |8329 | 10197 |
361
+ | Mistral-7B-Instruct-v0.1 | **100%** | 50% | 20% | 30% |
362
+ | MistralLite | **100%** | **100%** | **100%** | **100%** |
363
+
364
+ 4. [Question Answering with Long Input Texts](https://nyu-mll.github.io/quality/)
365
+ |Model Name| Test set Accuracy | Hard subset Accuracy|
366
+ |----------|-------------:|-------------:|
367
+ | Mistral-7B-Instruct-v0.1 | 44.3% | 39.7% |
368
+ | MistralLite | **64.4%** | **56.2%** |
369
+
370
+ ### Example test on long context of 13400 tokens
371
+ - Context is from [Amazon Aurora FAQs](https://aws.amazon.com/rds/aurora/faqs/)
372
+ - Question: *please tell me how does pgvector help with Generative AI and give me some examples.*
373
+ - Answer from MistralLite:
374
+ ```code
375
+ pgvector is an open-source extension for PostgreSQL supported by Amazon Aurora PostgreSQL-Compatible Edition.
376
+
377
+ You can use pgvector to store, search, index, and query billions of embeddings that are generated from machine learning (ML) and artificial intelligence (AI) models in your database, such as those from Amazon Bedrock (limited preview) or Amazon SageMaker. A vector embedding is a numerical representation that represents the semantic meaning of content such as text, images, and video.
378
+
379
+ With pgvector, you can query embeddings in your Aurora PostgreSQL database to perform efficient semantic similarity searches of these data types, represented as vectors, combined with other tabular data in Aurora. This enables the use of generative AI and other AI/ML systems for new types of applications such as personalized recommendations based on similar text descriptions or images, candidate match based on interview notes, customer service next best action recommendations based on successful transcripts or chat session dialogs, and more.
380
+ ```
381
+
382
+ ## Model Details
383
+
384
+ - **Developed by:** [AWS Contributors](https://github.com/orgs/aws-samples/teams/aws-prototype-ml-apac)
385
+ - **Model type:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
386
+ - **Language:** English
387
+ - **Finetuned from weights:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
388
+ - **Finetuned on data:**
389
+ - [SLidingEncoder and Decoder (SLED)](https://huggingface.co/datasets/tau/sled)
390
+ - [(Long) Natural Questions (NQ)](https://huggingface.co/datasets/togethercomputer/Long-Data-Collections#multi-passage-qa-from-natural-questions)
391
+ - [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
392
+ - **Supported Serving Framework:**
393
+ - [Text-Generation-Inference 1.1.0](https://github.com/huggingface/text-generation-inference/tree/v1.1.0)
394
+ - [vLLM](https://github.com/vllm-project/vllm)
395
+ - [HuggingFace transformers](https://huggingface.co/docs/transformers/index)
396
+ - [HuggingFace Text Generation Inference (TGI) container on SageMaker](https://github.com/awslabs/llm-hosting-container)
397
+ - **Model License:** Apache 2.0
398
+ - **Contact:** [GitHub issues](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/issues)
399
+ - **Inference Code** [Github Repo](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/)
400
+
401
+ ## How to Use MistralLite from Python Code (HuggingFace transformers) ##
402
+
403
+ **Important** - For an end-to-end example Jupyter notebook, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/huggingface-transformers/example_usage.ipynb).
404
+
405
+ ### Install the necessary packages
406
+
407
+ Requires: [transformers](https://pypi.org/project/transformers/) 4.34.0 or later, [flash-attn](https://pypi.org/project/flash-attn/) 2.3.1.post1 or later,
408
+ and [accelerate](https://pypi.org/project/accelerate/) 0.23.0 or later.
409
+
410
+ ```shell
411
+ pip install transformers==4.34.0
412
+ pip install flash-attn==2.3.1.post1 --no-build-isolation
413
+ pip install accelerate==0.23.0
414
+ ```
415
+ ### You can then try the following example code
416
+
417
+ ```python
418
+ from transformers import AutoModelForCausalLM, AutoTokenizer
419
+ import transformers
420
+ import torch
421
+
422
+ model_id = "amazon/MistralLite"
423
+
424
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
425
+ model = AutoModelForCausalLM.from_pretrained(model_id,
426
+ torch_dtype=torch.bfloat16,
427
+ use_flash_attention_2=True,
428
+ device_map="auto",)
429
+ pipeline = transformers.pipeline(
430
+ "text-generation",
431
+ model=model,
432
+ tokenizer=tokenizer,
433
+ )
434
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
435
+
436
+ sequences = pipeline(
437
+ prompt,
438
+ max_new_tokens=400,
439
+ do_sample=False,
440
+ return_full_text=False,
441
+ num_return_sequences=1,
442
+ eos_token_id=tokenizer.eos_token_id,
443
+ )
444
+ for seq in sequences:
445
+ print(f"{seq['generated_text']}")
446
+ ```
447
+ **Important** - Use the prompt template below for MistralLite:
448
+ ```
449
+ <|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>
450
+ ```
451
+
452
+ ## How to Serve MistralLite on TGI ##
453
+ **Important:**
454
+ - For an end-to-end example Jupyter notebook using the native TGI container, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/tgi/example_usage.ipynb).
455
+ - If the **input context length is greater than 12K tokens**, it is recommended using a custom TGI container, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/tgi-custom/example_usage.ipynb).
456
+
457
+ ### Start TGI server ###
458
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
459
+
460
+ Example Docker parameters:
461
+
462
+ ```shell
463
+ docker run -d --gpus all --shm-size 1g -p 443:80 -v $(pwd)/models:/data ghcr.io/huggingface/text-generation-inference:1.1.0 \
464
+ --model-id amazon/MistralLite \
465
+ --max-input-length 16000 \
466
+ --max-total-tokens 16384 \
467
+ --max-batch-prefill-tokens 16384 \
468
+ --trust-remote-code
469
+ ```
470
+
471
+ ### Perform Inference ###
472
+ Example Python code for inference with TGI (requires `text_generation` 0.6.1 or later):
473
+
474
+ ```shell
475
+ pip install text_generation==0.6.1
476
+ ```
477
+
478
+ ```python
479
+ from text_generation import Client
480
+
481
+ SERVER_PORT = 443
482
+ SERVER_HOST = "localhost"
483
+ SERVER_URL = f"{SERVER_HOST}:{SERVER_PORT}"
484
+ tgi_client = Client(f"http://{SERVER_URL}", timeout=60)
485
+
486
+ def invoke_tgi(prompt,
487
+ random_seed=1,
488
+ max_new_tokens=400,
489
+ print_stream=True,
490
+ assist_role=True):
491
+ if (assist_role):
492
+ prompt = f"<|prompter|>{prompt}</s><|assistant|>"
493
+ output = ""
494
+ for response in tgi_client.generate_stream(
495
+ prompt,
496
+ do_sample=False,
497
+ max_new_tokens=max_new_tokens,
498
+ return_full_text=False,
499
+ #temperature=None,
500
+ #truncate=None,
501
+ #seed=random_seed,
502
+ #typical_p=0.2,
503
+ ):
504
+ if hasattr(response, "token"):
505
+ if not response.token.special:
506
+ snippet = response.token.text
507
+ output += snippet
508
+ if (print_stream):
509
+ print(snippet, end='', flush=True)
510
+ return output
511
+
512
+ prompt = "What are the main challenges to support a long context for LLM?"
513
+ result = invoke_tgi(prompt)
514
+ ```
515
+
516
+ **Important** - When using MistralLite for inference for the first time, it may require a brief 'warm-up' period that can take 10s of seconds. However, subsequent inferences should be faster and return results in a more timely manner. This warm-up period is normal and should not affect the overall performance of the system once the initialisation period has been completed.
517
+
518
+
519
+ ## How to Deploy MistralLite on Amazon SageMaker ##
520
+ **Important:**
521
+ - For an end-to-end example Jupyter notebook using the SageMaker built-in container, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/sagemaker-tgi/example_usage.ipynb).
522
+ - If the **input context length is greater than 12K tokens**, it is recommended using a custom docker container, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/sagemaker-tgi-custom/example_usage.ipynb).
523
+
524
+ ### Install the necessary packages
525
+
526
+ Requires: [sagemaker](https://pypi.org/project/sagemaker/) 2.192.1 or later.
527
+
528
+ ```shell
529
+ pip install sagemaker==2.192.1
530
+ ```
531
+
532
+ ### Deploy the Model as A SageMaker Endpoint ###
533
+ To deploy MistralLite on a SageMaker endpoint, please follow the example code as below.
534
+ ```python
535
+ import sagemaker
536
+ from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
537
+ import time
538
+
539
+ sagemaker_session = sagemaker.Session()
540
+ region = sagemaker_session.boto_region_name
541
+ role = sagemaker.get_execution_role()
542
+
543
+ image_uri = get_huggingface_llm_image_uri(
544
+ backend="huggingface", # or lmi
545
+ region=region,
546
+ version="1.1.0"
547
+ )
548
+
549
+ model_name = "MistralLite-" + time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())
550
+
551
+ hub = {
552
+ 'HF_MODEL_ID':'amazon/MistralLite',
553
+ 'HF_TASK':'text-generation',
554
+ 'SM_NUM_GPUS':'1',
555
+ "MAX_INPUT_LENGTH": '16000',
556
+ "MAX_TOTAL_TOKENS": '16384',
557
+ "MAX_BATCH_PREFILL_TOKENS": '16384',
558
+ "MAX_BATCH_TOTAL_TOKENS": '16384',
559
+ }
560
+
561
+ model = HuggingFaceModel(
562
+ name=model_name,
563
+ env=hub,
564
+ role=role,
565
+ image_uri=image_uri
566
+ )
567
+ predictor = model.deploy(
568
+ initial_instance_count=1,
569
+ instance_type="ml.g5.2xlarge",
570
+ endpoint_name=model_name,
571
+
572
+ )
573
+ ```
574
+
575
+ ### Perform Inference ###
576
+ To call the endpoint, please follow the example code as below:
577
+
578
+ ```python
579
+ input_data = {
580
+ "inputs": "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
581
+ "parameters": {
582
+ "do_sample": False,
583
+ "max_new_tokens": 400,
584
+ "return_full_text": False,
585
+ #"typical_p": 0.2,
586
+ #"temperature":None,
587
+ #"truncate":None,
588
+ #"seed": 1,
589
+ }
590
+ }
591
+ result = predictor.predict(input_data)[0]["generated_text"]
592
+ print(result)
593
+ ```
594
+ or via [boto3](https://pypi.org/project/boto3/), and the example code is shown as below:
595
+
596
+ ```python
597
+ import boto3
598
+ import json
599
+ def call_endpoint(client, prompt, endpoint_name, paramters):
600
+ client = boto3.client("sagemaker-runtime")
601
+ payload = {"inputs": prompt,
602
+ "parameters": parameters}
603
+ response = client.invoke_endpoint(EndpointName=endpoint_name,
604
+ Body=json.dumps(payload),
605
+ ContentType="application/json")
606
+ output = json.loads(response["Body"].read().decode())
607
+ result = output[0]["generated_text"]
608
+ return result
609
+
610
+ client = boto3.client("sagemaker-runtime")
611
+ parameters = {
612
+ "do_sample": False,
613
+ "max_new_tokens": 400,
614
+ "return_full_text": False,
615
+ #"typical_p": 0.2,
616
+ #"temperature":None,
617
+ #"truncate":None,
618
+ #"seed": 1,
619
+ }
620
+ endpoint_name = predictor.endpoint_name
621
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
622
+ result = call_endpoint(client, prompt, endpoint_name, parameters)
623
+ print(result)
624
+ ```
625
+
626
+
627
+ ## How to Serve MistralLite on vLLM ##
628
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
629
+
630
+ **Important** - For an end-to-end example Jupyter notebook, please refer to [this link](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/vllm/example_usage.ipynb).
631
+
632
+ ### Using vLLM as a server ###
633
+ When using vLLM as a server, pass the --model amazon/MistralLite parameter, for example:
634
+ ```shell
635
+ python3 -m vllm.entrypoints.api_server --model amazon/MistralLite
636
+ ```
637
+
638
+ ### Using vLLM in Python Code ###
639
+ When using vLLM from Python code, Please see the example code as below:
640
+
641
+ ```python
642
+ from vllm import LLM, SamplingParams
643
+
644
+ prompts = [
645
+ "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
646
+ ]
647
+ sampling_params = SamplingParams(temperature=0, max_tokens=100)
648
+
649
+ llm = LLM(model="amazon/MistralLite",)
650
+
651
+ outputs = llm.generate(prompts, sampling_params)
652
+
653
+ # Print the outputs.
654
+ for output in outputs:
655
+ prompt = output.prompt
656
+ generated_text = output.outputs[0].text
657
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
658
+ ```
659
+
660
+ ## Limitations ##
661
+ Before using the MistralLite model, it is important to perform your own independent assessment, and take measures to ensure that your use would comply with your own specific quality control practices and standards, and that your use would comply with the local rules, laws, regulations, licenses and terms that apply to you, and your content.