TheBloke commited on
Commit
9f53440
1 Parent(s): aef81f1

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +679 -0
README.md ADDED
@@ -0,0 +1,679 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 - GPTQ
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 GPTQ model files for [Amazon Web Services's MistralLite 7B](https://huggingface.co/amazon/MistralLite).
40
+
41
+ Multiple GPTQ parameter permutations are provided; see Provided Files below for details of the options provided, their parameters, and the software used to create them.
42
+
43
+ <!-- description end -->
44
+ <!-- repositories-available start -->
45
+ ## Repositories available
46
+
47
+ * [AWQ model(s) for GPU inference.](https://huggingface.co/TheBloke/MistralLite-7B-AWQ)
48
+ * [GPTQ models for GPU inference, with multiple quantisation parameter options.](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ)
49
+ * [2, 3, 4, 5, 6 and 8-bit GGUF models for CPU+GPU inference](https://huggingface.co/TheBloke/MistralLite-7B-GGUF)
50
+ * [Amazon Web Services's original unquantised fp16 model in pytorch format, for GPU inference and for further conversions](https://huggingface.co/amazon/MistralLite)
51
+ <!-- repositories-available end -->
52
+
53
+ <!-- prompt-template start -->
54
+ ## Prompt template: Amazon
55
+
56
+ ```
57
+ <|prompter|>{prompt}</s><|assistant|>
58
+
59
+ ```
60
+
61
+ <!-- prompt-template end -->
62
+
63
+
64
+ <!-- README_GPTQ.md-provided-files start -->
65
+ ## Provided files, and GPTQ parameters
66
+
67
+ Multiple quantisation parameters are provided, to allow you to choose the best one for your hardware and requirements.
68
+
69
+ Each separate quant is in a different branch. See below for instructions on fetching from different branches.
70
+
71
+ Most GPTQ files are made with AutoGPTQ. Mistral models are currently made with Transformers.
72
+
73
+ <details>
74
+ <summary>Explanation of GPTQ parameters</summary>
75
+
76
+ - Bits: The bit size of the quantised model.
77
+ - GS: GPTQ group size. Higher numbers use less VRAM, but have lower quantisation accuracy. "None" is the lowest possible value.
78
+ - Act Order: True or False. Also known as `desc_act`. True results in better quantisation accuracy. Some GPTQ clients have had issues with models that use Act Order plus Group Size, but this is generally resolved now.
79
+ - Damp %: A GPTQ parameter that affects how samples are processed for quantisation. 0.01 is default, but 0.1 results in slightly better accuracy.
80
+ - GPTQ dataset: The calibration dataset used during quantisation. Using a dataset more appropriate to the model's training can improve quantisation accuracy. Note that the GPTQ calibration dataset is not the same as the dataset used to train the model - please refer to the original model repo for details of the training dataset(s).
81
+ - Sequence Length: The length of the dataset sequences used for quantisation. Ideally this is the same as the model sequence length. For some very long sequence models (16+K), a lower sequence length may have to be used. Note that a lower sequence length does not limit the sequence length of the quantised model. It only impacts the quantisation accuracy on longer inference sequences.
82
+ - ExLlama Compatibility: Whether this file can be loaded with ExLlama, which currently only supports Llama models in 4-bit.
83
+
84
+ </details>
85
+
86
+ | Branch | Bits | GS | Act Order | Damp % | GPTQ Dataset | Seq Len | Size | ExLlama | Desc |
87
+ | ------ | ---- | -- | --------- | ------ | ------------ | ------- | ---- | ------- | ---- |
88
+ | [main](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/main) | 4 | 128 | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 4.16 GB | Yes | 4-bit, with Act Order and group size 128g. Uses even less VRAM than 64g, but with slightly lower accuracy. |
89
+ | [gptq-4bit-32g-actorder_True](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/gptq-4bit-32g-actorder_True) | 4 | 32 | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 4.57 GB | Yes | 4-bit, with Act Order and group size 32g. Gives highest possible inference quality, with maximum VRAM usage. |
90
+ | [gptq-8bit--1g-actorder_True](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/gptq-8bit--1g-actorder_True) | 8 | None | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 7.52 GB | No | 8-bit, with Act Order. No group size, to lower VRAM requirements. |
91
+ | [gptq-8bit-128g-actorder_True](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/gptq-8bit-128g-actorder_True) | 8 | 128 | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 7.68 GB | No | 8-bit, with group size 128g for higher inference quality and with Act Order for even higher accuracy. |
92
+ | [gptq-8bit-32g-actorder_True](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/gptq-8bit-32g-actorder_True) | 8 | 32 | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 8.17 GB | No | 8-bit, with group size 32g and Act Order for maximum inference quality. |
93
+ | [gptq-4bit-64g-actorder_True](https://huggingface.co/TheBloke/MistralLite-7B-GPTQ/tree/gptq-4bit-64g-actorder_True) | 4 | 64 | Yes | 0.1 | [wikitext](https://huggingface.co/datasets/wikitext/viewer/wikitext-2-v1/test) | 4096 | 4.30 GB | Yes | 4-bit, with Act Order and group size 64g. Uses less VRAM than 32g, but with slightly lower accuracy. |
94
+
95
+ <!-- README_GPTQ.md-provided-files end -->
96
+
97
+ <!-- README_GPTQ.md-download-from-branches start -->
98
+ ## How to download, including from branches
99
+
100
+ ### In text-generation-webui
101
+
102
+ To download from the `main` branch, enter `TheBloke/MistralLite-7B-GPTQ` in the "Download model" box.
103
+
104
+ To download from another branch, add `:branchname` to the end of the download name, eg `TheBloke/MistralLite-7B-GPTQ:gptq-4bit-32g-actorder_True`
105
+
106
+ ### From the command line
107
+
108
+ I recommend using the `huggingface-hub` Python library:
109
+
110
+ ```shell
111
+ pip3 install huggingface-hub
112
+ ```
113
+
114
+ To download the `main` branch to a folder called `MistralLite-7B-GPTQ`:
115
+
116
+ ```shell
117
+ mkdir MistralLite-7B-GPTQ
118
+ huggingface-cli download TheBloke/MistralLite-7B-GPTQ --local-dir MistralLite-7B-GPTQ --local-dir-use-symlinks False
119
+ ```
120
+
121
+ To download from a different branch, add the `--revision` parameter:
122
+
123
+ ```shell
124
+ mkdir MistralLite-7B-GPTQ
125
+ huggingface-cli download TheBloke/MistralLite-7B-GPTQ --revision gptq-4bit-32g-actorder_True --local-dir MistralLite-7B-GPTQ --local-dir-use-symlinks False
126
+ ```
127
+
128
+ <details>
129
+ <summary>More advanced huggingface-cli download usage</summary>
130
+
131
+ If you remove the `--local-dir-use-symlinks False` parameter, the files will instead be stored in the central Huggingface cache directory (default location on Linux is: `~/.cache/huggingface`), and symlinks will be added to the specified `--local-dir`, pointing to their real location in the cache. This allows for interrupted downloads to be resumed, and allows you to quickly clone the repo to multiple places on disk without triggering a download again. The downside, and the reason why I don't list that as the default option, is that the files are then hidden away in a cache folder and it's harder to know where your disk space is being used, and to clear it up if/when you want to remove a download model.
132
+
133
+ The cache location can be changed with the `HF_HOME` environment variable, and/or the `--cache-dir` parameter to `huggingface-cli`.
134
+
135
+ For more documentation on downloading with `huggingface-cli`, please see: [HF -> Hub Python Library -> Download files -> Download from the CLI](https://huggingface.co/docs/huggingface_hub/guides/download#download-from-the-cli).
136
+
137
+ To accelerate downloads on fast connections (1Gbit/s or higher), install `hf_transfer`:
138
+
139
+ ```shell
140
+ pip3 install hf_transfer
141
+ ```
142
+
143
+ And set environment variable `HF_HUB_ENABLE_HF_TRANSFER` to `1`:
144
+
145
+ ```shell
146
+ mkdir MistralLite-7B-GPTQ
147
+ HF_HUB_ENABLE_HF_TRANSFER=1 huggingface-cli download TheBloke/MistralLite-7B-GPTQ --local-dir MistralLite-7B-GPTQ --local-dir-use-symlinks False
148
+ ```
149
+
150
+ Windows Command Line users: You can set the environment variable by running `set HF_HUB_ENABLE_HF_TRANSFER=1` before the download command.
151
+ </details>
152
+
153
+ ### With `git` (**not** recommended)
154
+
155
+ To clone a specific branch with `git`, use a command like this:
156
+
157
+ ```shell
158
+ git clone --single-branch --branch gptq-4bit-32g-actorder_True https://huggingface.co/TheBloke/MistralLite-7B-GPTQ
159
+ ```
160
+
161
+ Note that using Git with HF repos is strongly discouraged. It will be much slower than using `huggingface-hub`, and will use twice as much disk space as it has to store the model files twice (it stores every byte both in the intended target folder, and again in the `.git` folder as a blob.)
162
+
163
+ <!-- README_GPTQ.md-download-from-branches end -->
164
+ <!-- README_GPTQ.md-text-generation-webui start -->
165
+ ## How to easily download and use this model in [text-generation-webui](https://github.com/oobabooga/text-generation-webui)
166
+
167
+ Please make sure you're using the latest version of [text-generation-webui](https://github.com/oobabooga/text-generation-webui).
168
+
169
+ 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.
170
+
171
+ 1. Click the **Model tab**.
172
+ 2. Under **Download custom model or LoRA**, enter `TheBloke/MistralLite-7B-GPTQ`.
173
+
174
+ - To download from a specific branch, enter for example `TheBloke/MistralLite-7B-GPTQ:gptq-4bit-32g-actorder_True`
175
+ - see Provided Files above for the list of branches for each option.
176
+
177
+ 3. Click **Download**.
178
+ 4. The model will start downloading. Once it's finished it will say "Done".
179
+ 5. In the top left, click the refresh icon next to **Model**.
180
+ 6. In the **Model** dropdown, choose the model you just downloaded: `MistralLite-7B-GPTQ`
181
+ 7. The model will automatically load, and is now ready for use!
182
+ 8. 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.
183
+
184
+ - Note that you do not need to and should not set manual GPTQ parameters any more. These are set automatically from the file `quantize_config.json`.
185
+
186
+ 9. Once you're ready, click the **Text Generation** tab and enter a prompt to get started!
187
+
188
+ <!-- README_GPTQ.md-text-generation-webui end -->
189
+
190
+ <!-- README_GPTQ.md-use-from-tgi start -->
191
+ ## Serving this model from Text Generation Inference (TGI)
192
+
193
+ It's recommended to use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
194
+
195
+ Example Docker parameters:
196
+
197
+ ```shell
198
+ --model-id TheBloke/MistralLite-7B-GPTQ --port 3000 --quantize gptq --max-input-length 3696 --max-total-tokens 4096 --max-batch-prefill-tokens 4096
199
+ ```
200
+
201
+ Example Python code for interfacing with TGI (requires huggingface-hub 0.17.0 or later):
202
+
203
+ ```shell
204
+ pip3 install huggingface-hub
205
+ ```
206
+
207
+ ```python
208
+ from huggingface_hub import InferenceClient
209
+
210
+ endpoint_url = "https://your-endpoint-url-here"
211
+
212
+ prompt = "Tell me about AI"
213
+ prompt_template=f'''<|prompter|>{prompt}</s><|assistant|>
214
+ '''
215
+
216
+ client = InferenceClient(endpoint_url)
217
+ response = client.text_generation(prompt,
218
+ max_new_tokens=128,
219
+ do_sample=True,
220
+ temperature=0.7,
221
+ top_p=0.95,
222
+ top_k=40,
223
+ repetition_penalty=1.1)
224
+
225
+ print(f"Model output: {response}")
226
+ ```
227
+ <!-- README_GPTQ.md-use-from-tgi end -->
228
+ <!-- README_GPTQ.md-use-from-python start -->
229
+ ## How to use this GPTQ model from Python code
230
+
231
+ ### Install the necessary packages
232
+
233
+ Requires: Transformers 4.33.0 or later, Optimum 1.12.0 or later, and AutoGPTQ 0.4.2 or later.
234
+
235
+ ```shell
236
+ pip3 install transformers optimum
237
+ pip3 install auto-gptq --extra-index-url https://huggingface.github.io/autogptq-index/whl/cu118/ # Use cu117 if on CUDA 11.7
238
+ ```
239
+
240
+ If you have problems installing AutoGPTQ using the pre-built wheels, install it from source instead:
241
+
242
+ ```shell
243
+ pip3 uninstall -y auto-gptq
244
+ git clone https://github.com/PanQiWei/AutoGPTQ
245
+ cd AutoGPTQ
246
+ git checkout v0.4.2
247
+ pip3 install .
248
+ ```
249
+
250
+ ### You can then use the following code
251
+
252
+ ```python
253
+ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
254
+
255
+ model_name_or_path = "TheBloke/MistralLite-7B-GPTQ"
256
+ # To use a different branch, change revision
257
+ # For example: revision="gptq-4bit-32g-actorder_True"
258
+ model = AutoModelForCausalLM.from_pretrained(model_name_or_path,
259
+ device_map="auto",
260
+ trust_remote_code=False,
261
+ revision="main")
262
+
263
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
264
+
265
+ prompt = "Tell me about AI"
266
+ prompt_template=f'''<|prompter|>{prompt}</s><|assistant|>
267
+ '''
268
+
269
+ print("\n\n*** Generate:")
270
+
271
+ input_ids = tokenizer(prompt_template, return_tensors='pt').input_ids.cuda()
272
+ output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)
273
+ print(tokenizer.decode(output[0]))
274
+
275
+ # Inference can also be done using transformers' pipeline
276
+
277
+ print("*** Pipeline:")
278
+ pipe = pipeline(
279
+ "text-generation",
280
+ model=model,
281
+ tokenizer=tokenizer,
282
+ max_new_tokens=512,
283
+ do_sample=True,
284
+ temperature=0.7,
285
+ top_p=0.95,
286
+ top_k=40,
287
+ repetition_penalty=1.1
288
+ )
289
+
290
+ print(pipe(prompt_template)[0]['generated_text'])
291
+ ```
292
+ <!-- README_GPTQ.md-use-from-python end -->
293
+
294
+ <!-- README_GPTQ.md-compatibility start -->
295
+ ## Compatibility
296
+
297
+ The files provided are tested to work with AutoGPTQ, both via Transformers and using AutoGPTQ directly. They should also work with [Occ4m's GPTQ-for-LLaMa fork](https://github.com/0cc4m/KoboldAI).
298
+
299
+ [ExLlama](https://github.com/turboderp/exllama) is compatible with Llama and Mistral models in 4-bit. Please see the Provided Files table above for per-file compatibility.
300
+
301
+ [Huggingface Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference) is compatible with all GPTQ models.
302
+ <!-- README_GPTQ.md-compatibility end -->
303
+
304
+ <!-- footer start -->
305
+ <!-- 200823 -->
306
+ ## Discord
307
+
308
+ For further support, and discussions on these models and AI in general, join us at:
309
+
310
+ [TheBloke AI's Discord server](https://discord.gg/theblokeai)
311
+
312
+ ## Thanks, and how to contribute
313
+
314
+ Thanks to the [chirper.ai](https://chirper.ai) team!
315
+
316
+ Thanks to Clay from [gpus.llm-utils.org](llm-utils)!
317
+
318
+ 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.
319
+
320
+ 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.
321
+
322
+ Donaters will get priority support on any and all AI/LLM/model questions and requests, access to a private Discord room, plus other benefits.
323
+
324
+ * Patreon: https://patreon.com/TheBlokeAI
325
+ * Ko-Fi: https://ko-fi.com/TheBlokeAI
326
+
327
+ **Special thanks to**: Aemon Algiz.
328
+
329
+ **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
330
+
331
+
332
+ Thank you to all my generous patrons and donaters!
333
+
334
+ And thank you again to a16z for their generous grant.
335
+
336
+ <!-- footer end -->
337
+
338
+ # Original model card: Amazon Web Services's MistralLite 7B
339
+
340
+
341
+ # MistralLite Model
342
+
343
+ 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.
344
+
345
+ 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:
346
+ |Model|Fine-tuned on long contexts| Max context length| RotaryEmbedding adaptation| Sliding Window Size|
347
+ |----------|-------------:|------------:|-----------:|-----------:|
348
+ | Mistral-7B-Instruct-v0.1 | up to 8K tokens | 32K | rope_theta = 10000 | 4096 |
349
+ | MistralLite | up to 16K tokens | 32K | **rope_theta = 1000000** | **16384** |
350
+
351
+ ## Motivation of Developing MistralLite
352
+
353
+ 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
354
+ 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.
355
+ Then We evaluated `Mistral-7B-Instruct-v0.1` against benchmarks that are specifically designed to assess the capabilities of LLMs in handling longer context.
356
+ Although the performance of the models on long context was fairly competitive on long context less than 4096 tokens,
357
+ 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:
358
+
359
+ 1. [Topic Retrieval](https://lmsys.org/blog/2023-06-29-longchat/)
360
+ |Model Name|Input length| Input length | Input length| Input length| Input length|
361
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|
362
+ | | 2851| 5568 |8313 | 11044 | 13780
363
+ | Mistral-7B-Instruct-v0.1 | 100% | 50% | 2% | 0% | 0% |
364
+ | MistralLite | **100%** | **100%** | **100%** | **100%** | **98%** |
365
+
366
+ 2. [Line Retrieval](https://lmsys.org/blog/2023-06-29-longchat/#longeval-results)
367
+
368
+ |Model Name|Input length| Input length | Input length| Input length| Input length|Input length|
369
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|-----------:|
370
+ | | 3818| 5661 |7505 | 9354 | 11188 | 12657
371
+ | Mistral-7B-Instruct-v0.1 | **98%** | 62% | 42% | 42% | 32% | 30% |
372
+ | MistralLite | **98%** | **92%** | **88%** | **76%** | **70%** | **60%** |
373
+
374
+ 3. [Pass key Retrieval](https://github.com/epfml/landmark-attention/blob/main/llama/run_test.py#L101)
375
+
376
+ |Model Name|Input length| Input length | Input length| Input length|
377
+ |----------|-------------:|-------------:|------------:|-----------:|
378
+ | | 3264| 5396 |8329 | 10197 |
379
+ | Mistral-7B-Instruct-v0.1 | **100%** | 50% | 20% | 30% |
380
+ | MistralLite | **100%** | **100%** | **100%** | **100%** |
381
+
382
+ 4. [Question Answering with Long Input Texts](https://nyu-mll.github.io/quality/)
383
+ |Model Name| Test set Accuracy | Hard subset Accuracy|
384
+ |----------|-------------:|-------------:|
385
+ | Mistral-7B-Instruct-v0.1 | 44.3% | 39.7% |
386
+ | MistralLite | **64.4%** | **56.2%** |
387
+
388
+ ### Example test on long context of 13400 tokens
389
+ - Context is from [Amazon Aurora FAQs](https://aws.amazon.com/rds/aurora/faqs/)
390
+ - Question: *please tell me how does pgvector help with Generative AI and give me some examples.*
391
+ - Answer from MistralLite:
392
+ ```code
393
+ pgvector is an open-source extension for PostgreSQL supported by Amazon Aurora PostgreSQL-Compatible Edition.
394
+
395
+ 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.
396
+
397
+ 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.
398
+ ```
399
+
400
+ ## Model Details
401
+
402
+ - **Developed by:** [AWS Contributors](https://github.com/orgs/aws-samples/teams/aws-prototype-ml-apac)
403
+ - **Model type:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
404
+ - **Language:** English
405
+ - **Finetuned from weights:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
406
+ - **Finetuned on data:**
407
+ - [SLidingEncoder and Decoder (SLED)](https://huggingface.co/datasets/tau/sled)
408
+ - [(Long) Natural Questions (NQ)](https://huggingface.co/datasets/togethercomputer/Long-Data-Collections#multi-passage-qa-from-natural-questions)
409
+ - [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
410
+ - **Supported Serving Framework:**
411
+ - [Text-Generation-Inference 1.1.0](https://github.com/huggingface/text-generation-inference/tree/v1.1.0)
412
+ - [vLLM](https://github.com/vllm-project/vllm)
413
+ - [HuggingFace transformers](https://huggingface.co/docs/transformers/index)
414
+ - [HuggingFace Text Generation Inference (TGI) container on SageMaker](https://github.com/awslabs/llm-hosting-container)
415
+ - **Model License:** Apache 2.0
416
+ - **Contact:** [GitHub issues](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/issues)
417
+ - **Inference Code** [Github Repo](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/)
418
+
419
+ ## How to Use MistralLite from Python Code (HuggingFace transformers) ##
420
+
421
+ **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).
422
+
423
+ ### Install the necessary packages
424
+
425
+ 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,
426
+ and [accelerate](https://pypi.org/project/accelerate/) 0.23.0 or later.
427
+
428
+ ```shell
429
+ pip install transformers==4.34.0
430
+ pip install flash-attn==2.3.1.post1 --no-build-isolation
431
+ pip install accelerate==0.23.0
432
+ ```
433
+ ### You can then try the following example code
434
+
435
+ ```python
436
+ from transformers import AutoModelForCausalLM, AutoTokenizer
437
+ import transformers
438
+ import torch
439
+
440
+ model_id = "amazon/MistralLite"
441
+
442
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
443
+ model = AutoModelForCausalLM.from_pretrained(model_id,
444
+ torch_dtype=torch.bfloat16,
445
+ use_flash_attention_2=True,
446
+ device_map="auto",)
447
+ pipeline = transformers.pipeline(
448
+ "text-generation",
449
+ model=model,
450
+ tokenizer=tokenizer,
451
+ )
452
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
453
+
454
+ sequences = pipeline(
455
+ prompt,
456
+ max_new_tokens=400,
457
+ do_sample=False,
458
+ return_full_text=False,
459
+ num_return_sequences=1,
460
+ eos_token_id=tokenizer.eos_token_id,
461
+ )
462
+ for seq in sequences:
463
+ print(f"{seq['generated_text']}")
464
+ ```
465
+ **Important** - Use the prompt template below for MistralLite:
466
+ ```
467
+ <|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>
468
+ ```
469
+
470
+ ## How to Serve MistralLite on TGI ##
471
+ **Important:**
472
+ - 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).
473
+ - 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).
474
+
475
+ ### Start TGI server ###
476
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
477
+
478
+ Example Docker parameters:
479
+
480
+ ```shell
481
+ docker run -d --gpus all --shm-size 1g -p 443:80 -v $(pwd)/models:/data ghcr.io/huggingface/text-generation-inference:1.1.0 \
482
+ --model-id amazon/MistralLite \
483
+ --max-input-length 16000 \
484
+ --max-total-tokens 16384 \
485
+ --max-batch-prefill-tokens 16384 \
486
+ --trust-remote-code
487
+ ```
488
+
489
+ ### Perform Inference ###
490
+ Example Python code for inference with TGI (requires `text_generation` 0.6.1 or later):
491
+
492
+ ```shell
493
+ pip install text_generation==0.6.1
494
+ ```
495
+
496
+ ```python
497
+ from text_generation import Client
498
+
499
+ SERVER_PORT = 443
500
+ SERVER_HOST = "localhost"
501
+ SERVER_URL = f"{SERVER_HOST}:{SERVER_PORT}"
502
+ tgi_client = Client(f"http://{SERVER_URL}", timeout=60)
503
+
504
+ def invoke_tgi(prompt,
505
+ random_seed=1,
506
+ max_new_tokens=400,
507
+ print_stream=True,
508
+ assist_role=True):
509
+ if (assist_role):
510
+ prompt = f"<|prompter|>{prompt}</s><|assistant|>"
511
+ output = ""
512
+ for response in tgi_client.generate_stream(
513
+ prompt,
514
+ do_sample=False,
515
+ max_new_tokens=max_new_tokens,
516
+ return_full_text=False,
517
+ #temperature=None,
518
+ #truncate=None,
519
+ #seed=random_seed,
520
+ #typical_p=0.2,
521
+ ):
522
+ if hasattr(response, "token"):
523
+ if not response.token.special:
524
+ snippet = response.token.text
525
+ output += snippet
526
+ if (print_stream):
527
+ print(snippet, end='', flush=True)
528
+ return output
529
+
530
+ prompt = "What are the main challenges to support a long context for LLM?"
531
+ result = invoke_tgi(prompt)
532
+ ```
533
+
534
+ **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.
535
+
536
+
537
+ ## How to Deploy MistralLite on Amazon SageMaker ##
538
+ **Important:**
539
+ - 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).
540
+ - 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).
541
+
542
+ ### Install the necessary packages
543
+
544
+ Requires: [sagemaker](https://pypi.org/project/sagemaker/) 2.192.1 or later.
545
+
546
+ ```shell
547
+ pip install sagemaker==2.192.1
548
+ ```
549
+
550
+ ### Deploy the Model as A SageMaker Endpoint ###
551
+ To deploy MistralLite on a SageMaker endpoint, please follow the example code as below.
552
+ ```python
553
+ import sagemaker
554
+ from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
555
+ import time
556
+
557
+ sagemaker_session = sagemaker.Session()
558
+ region = sagemaker_session.boto_region_name
559
+ role = sagemaker.get_execution_role()
560
+
561
+ image_uri = get_huggingface_llm_image_uri(
562
+ backend="huggingface", # or lmi
563
+ region=region,
564
+ version="1.1.0"
565
+ )
566
+
567
+ model_name = "MistralLite-" + time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())
568
+
569
+ hub = {
570
+ 'HF_MODEL_ID':'amazon/MistralLite',
571
+ 'HF_TASK':'text-generation',
572
+ 'SM_NUM_GPUS':'1',
573
+ "MAX_INPUT_LENGTH": '16000',
574
+ "MAX_TOTAL_TOKENS": '16384',
575
+ "MAX_BATCH_PREFILL_TOKENS": '16384',
576
+ "MAX_BATCH_TOTAL_TOKENS": '16384',
577
+ }
578
+
579
+ model = HuggingFaceModel(
580
+ name=model_name,
581
+ env=hub,
582
+ role=role,
583
+ image_uri=image_uri
584
+ )
585
+ predictor = model.deploy(
586
+ initial_instance_count=1,
587
+ instance_type="ml.g5.2xlarge",
588
+ endpoint_name=model_name,
589
+
590
+ )
591
+ ```
592
+
593
+ ### Perform Inference ###
594
+ To call the endpoint, please follow the example code as below:
595
+
596
+ ```python
597
+ input_data = {
598
+ "inputs": "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
599
+ "parameters": {
600
+ "do_sample": False,
601
+ "max_new_tokens": 400,
602
+ "return_full_text": False,
603
+ #"typical_p": 0.2,
604
+ #"temperature":None,
605
+ #"truncate":None,
606
+ #"seed": 1,
607
+ }
608
+ }
609
+ result = predictor.predict(input_data)[0]["generated_text"]
610
+ print(result)
611
+ ```
612
+ or via [boto3](https://pypi.org/project/boto3/), and the example code is shown as below:
613
+
614
+ ```python
615
+ import boto3
616
+ import json
617
+ def call_endpoint(client, prompt, endpoint_name, paramters):
618
+ client = boto3.client("sagemaker-runtime")
619
+ payload = {"inputs": prompt,
620
+ "parameters": parameters}
621
+ response = client.invoke_endpoint(EndpointName=endpoint_name,
622
+ Body=json.dumps(payload),
623
+ ContentType="application/json")
624
+ output = json.loads(response["Body"].read().decode())
625
+ result = output[0]["generated_text"]
626
+ return result
627
+
628
+ client = boto3.client("sagemaker-runtime")
629
+ parameters = {
630
+ "do_sample": False,
631
+ "max_new_tokens": 400,
632
+ "return_full_text": False,
633
+ #"typical_p": 0.2,
634
+ #"temperature":None,
635
+ #"truncate":None,
636
+ #"seed": 1,
637
+ }
638
+ endpoint_name = predictor.endpoint_name
639
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
640
+ result = call_endpoint(client, prompt, endpoint_name, parameters)
641
+ print(result)
642
+ ```
643
+
644
+
645
+ ## How to Serve MistralLite on vLLM ##
646
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
647
+
648
+ **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).
649
+
650
+ ### Using vLLM as a server ###
651
+ When using vLLM as a server, pass the --model amazon/MistralLite parameter, for example:
652
+ ```shell
653
+ python3 -m vllm.entrypoints.api_server --model amazon/MistralLite
654
+ ```
655
+
656
+ ### Using vLLM in Python Code ###
657
+ When using vLLM from Python code, Please see the example code as below:
658
+
659
+ ```python
660
+ from vllm import LLM, SamplingParams
661
+
662
+ prompts = [
663
+ "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
664
+ ]
665
+ sampling_params = SamplingParams(temperature=0, max_tokens=100)
666
+
667
+ llm = LLM(model="amazon/MistralLite",)
668
+
669
+ outputs = llm.generate(prompts, sampling_params)
670
+
671
+ # Print the outputs.
672
+ for output in outputs:
673
+ prompt = output.prompt
674
+ generated_text = output.outputs[0].text
675
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
676
+ ```
677
+
678
+ ## Limitations ##
679
+ 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.