GGUF
aashish1904 commited on
Commit
fef9a1a
·
verified ·
1 Parent(s): dd2f19a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +375 -0
README.md ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ license: apache-2.0
5
+ inference: false
6
+
7
+ ---
8
+
9
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
10
+
11
+
12
+ # QuantFactory/MistralLite-GGUF
13
+ This is quantized version of [amazon/MistralLite](https://huggingface.co/amazon/MistralLite) created using llama.cpp
14
+
15
+ # Original Model Card
16
+
17
+
18
+ # MistralLite Model
19
+
20
+ 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.
21
+
22
+ 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:
23
+ |Model|Fine-tuned on long contexts| Max context length| RotaryEmbedding adaptation| Sliding Window Size|
24
+ |----------|-------------:|------------:|-----------:|-----------:|
25
+ | Mistral-7B-Instruct-v0.1 | up to 8K tokens | 32K | rope_theta = 10000 | 4096 |
26
+ | MistralLite | up to 16K tokens | 32K | **rope_theta = 1000000** | **16384** |
27
+
28
+ **Important - Use the prompt template below for MistralLite:**
29
+
30
+ ```<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>```
31
+
32
+ ## Motivation of Developing MistralLite
33
+
34
+ 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
35
+ 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.
36
+ Then We evaluated `Mistral-7B-Instruct-v0.1` against benchmarks that are specifically designed to assess the capabilities of LLMs in handling longer context.
37
+ Although the performance of the models on long context was fairly competitive on long context less than 4096 tokens,
38
+ 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:
39
+
40
+ 1. [Topic Retrieval](https://lmsys.org/blog/2023-06-29-longchat/)
41
+
42
+ |Model Name|Input length| Input length | Input length| Input length| Input length|
43
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|
44
+ | | 2851| 5568 |8313 | 11044 | 13780 |
45
+ | Mistral-7B-Instruct-v0.1 | 100% | 50% | 2% | 0% | 0% |
46
+ | MistralLite | **100%** | **100%** | **100%** | **100%** | **98%** |
47
+
48
+ 2. [Line Retrieval](https://lmsys.org/blog/2023-06-29-longchat/#longeval-results)
49
+
50
+ |Model Name|Input length| Input length | Input length| Input length| Input length|Input length|
51
+ |----------|-------------:|-------------:|------------:|-----------:|-----------:|-----------:|
52
+ | | 3818| 5661 |7505 | 9354 | 11188 | 12657
53
+ | Mistral-7B-Instruct-v0.1 | **98%** | 62% | 42% | 42% | 32% | 30% |
54
+ | MistralLite | **98%** | **92%** | **88%** | **76%** | **70%** | **60%** |
55
+
56
+ 3. [Pass key Retrieval](https://github.com/epfml/landmark-attention/blob/main/llama/run_test.py#L101)
57
+
58
+ |Model Name|Input length| Input length | Input length| Input length|
59
+ |----------|-------------:|-------------:|------------:|-----------:|
60
+ | | 3264| 5396 |8329 | 10197 |
61
+ | Mistral-7B-Instruct-v0.1 | **100%** | 50% | 20% | 30% |
62
+ | MistralLite | **100%** | **100%** | **100%** | **100%** |
63
+
64
+ 4. [Question Answering with Long Input Texts](https://nyu-mll.github.io/quality/)
65
+ |Model Name| Test set Accuracy | Hard subset Accuracy|
66
+ |----------|-------------:|-------------:|
67
+ | Mistral-7B-Instruct-v0.1 | 44.3% | 39.7% |
68
+ | MistralLite | **64.4%** | **56.2%** |
69
+
70
+ ### Example test on long context of 13400 tokens
71
+ - Context is from [Amazon Aurora FAQs](https://aws.amazon.com/rds/aurora/faqs/)
72
+ - Question: *please tell me how does pgvector help with Generative AI and give me some examples.*
73
+ - Answer from MistralLite:
74
+ ```code
75
+ pgvector is an open-source extension for PostgreSQL supported by Amazon Aurora PostgreSQL-Compatible Edition.
76
+
77
+ 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.
78
+
79
+ 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.
80
+ ```
81
+
82
+ ## Model Details
83
+
84
+ - **Developed by:** [AWS Contributors](https://github.com/orgs/aws-samples/teams/aws-prototype-ml-apac)
85
+ - **Model type:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
86
+ - **Language:** English
87
+ - **Finetuned from weights:** [Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1)
88
+ - **Finetuned on data:**
89
+ - [SLidingEncoder and Decoder (SLED)](https://huggingface.co/datasets/tau/sled)
90
+ - [(Long) Natural Questions (NQ)](https://huggingface.co/datasets/togethercomputer/Long-Data-Collections#multi-passage-qa-from-natural-questions)
91
+ - [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
92
+ - **Supported Serving Framework:**
93
+ - [Text-Generation-Inference 1.1.0](https://github.com/huggingface/text-generation-inference/tree/v1.1.0)
94
+ - [vLLM](https://github.com/vllm-project/vllm)
95
+ - [HuggingFace transformers](https://huggingface.co/docs/transformers/index)
96
+ - [HuggingFace Text Generation Inference (TGI) container on SageMaker](https://github.com/awslabs/llm-hosting-container)
97
+ - **Model License:** Apache 2.0
98
+ - **Contact:** [GitHub issues](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/issues)
99
+ - **Inference Code** [Github Repo](https://github.com/awslabs/extending-the-context-length-of-open-source-llms/blob/main/MistralLite/)
100
+
101
+ ## MistralLite LM-Eval Results
102
+
103
+ ### Methodology
104
+
105
+ - Please see https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard
106
+ - revision=4ececff
107
+ - Note: we used --model hf-causal-experimental instead of --model hf-causal
108
+
109
+ ### Results
110
+
111
+ |Average|hellaswag| arc_challenge|truthful_qa (mc2)| MMLU (acc)|
112
+ |----------|-------------:|------------:|-----------:|-----------:|
113
+ | 0.57221 | 0.81617 | 0.58874 | 0.38275 | 0.5012 |
114
+
115
+ ## How to Use MistralLite from Python Code (HuggingFace transformers) ##
116
+
117
+ **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).
118
+
119
+ ### Install the necessary packages
120
+
121
+ 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,
122
+ and [accelerate](https://pypi.org/project/accelerate/) 0.23.0 or later.
123
+
124
+ ```shell
125
+ pip install transformers==4.34.0
126
+ pip install flash-attn==2.3.1.post1 --no-build-isolation
127
+ pip install accelerate==0.23.0
128
+ ```
129
+ ### You can then try the following example code
130
+
131
+ ```python
132
+ from transformers import AutoModelForCausalLM, AutoTokenizer
133
+ import transformers
134
+ import torch
135
+
136
+ model_id = "amazon/MistralLite"
137
+
138
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
139
+ model = AutoModelForCausalLM.from_pretrained(model_id,
140
+ torch_dtype=torch.bfloat16,
141
+ use_flash_attention_2=True,
142
+ device_map="auto",)
143
+ pipeline = transformers.pipeline(
144
+ "text-generation",
145
+ model=model,
146
+ tokenizer=tokenizer,
147
+ )
148
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
149
+
150
+ sequences = pipeline(
151
+ prompt,
152
+ max_new_tokens=400,
153
+ do_sample=False,
154
+ return_full_text=False,
155
+ num_return_sequences=1,
156
+ eos_token_id=tokenizer.eos_token_id,
157
+ )
158
+ for seq in sequences:
159
+ print(f"{seq['generated_text']}")
160
+ ```
161
+ **Important** - Use the prompt template below for MistralLite:
162
+ ```
163
+ <|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>
164
+ ```
165
+
166
+ ## How to Serve MistralLite on TGI ##
167
+ **Important:**
168
+ - 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).
169
+ - 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).
170
+
171
+ ### Start TGI server ###
172
+ Use TGI version 1.1.0 or later. The official Docker container is: `ghcr.io/huggingface/text-generation-inference:1.1.0`
173
+
174
+ Example Docker parameters:
175
+
176
+ ```shell
177
+ docker run -d --gpus all --shm-size 1g -p 443:80 -v $(pwd)/models:/data ghcr.io/huggingface/text-generation-inference:1.1.0 \
178
+ --model-id amazon/MistralLite \
179
+ --max-input-length 16000 \
180
+ --max-total-tokens 16384 \
181
+ --max-batch-prefill-tokens 16384 \
182
+ --trust-remote-code
183
+ ```
184
+
185
+ ### Perform Inference ###
186
+ Example Python code for inference with TGI (requires `text_generation` 0.6.1 or later):
187
+
188
+ ```shell
189
+ pip install text_generation==0.6.1
190
+ ```
191
+
192
+ ```python
193
+ from text_generation import Client
194
+
195
+ SERVER_PORT = 443
196
+ SERVER_HOST = "localhost"
197
+ SERVER_URL = f"{SERVER_HOST}:{SERVER_PORT}"
198
+ tgi_client = Client(f"http://{SERVER_URL}", timeout=60)
199
+
200
+ def invoke_tgi(prompt,
201
+ random_seed=1,
202
+ max_new_tokens=400,
203
+ print_stream=True,
204
+ assist_role=True):
205
+ if (assist_role):
206
+ prompt = f"<|prompter|>{prompt}</s><|assistant|>"
207
+ output = ""
208
+ for response in tgi_client.generate_stream(
209
+ prompt,
210
+ do_sample=False,
211
+ max_new_tokens=max_new_tokens,
212
+ return_full_text=False,
213
+ #temperature=None,
214
+ #truncate=None,
215
+ #seed=random_seed,
216
+ #typical_p=0.2,
217
+ ):
218
+ if hasattr(response, "token"):
219
+ if not response.token.special:
220
+ snippet = response.token.text
221
+ output += snippet
222
+ if (print_stream):
223
+ print(snippet, end='', flush=True)
224
+ return output
225
+
226
+ prompt = "What are the main challenges to support a long context for LLM?"
227
+ result = invoke_tgi(prompt)
228
+ ```
229
+
230
+ **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.
231
+
232
+
233
+ ## How to Deploy MistralLite on Amazon SageMaker ##
234
+ **Important:**
235
+ - 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).
236
+ - 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).
237
+
238
+ ### Install the necessary packages
239
+
240
+ Requires: [sagemaker](https://pypi.org/project/sagemaker/) 2.192.1 or later.
241
+
242
+ ```shell
243
+ pip install sagemaker==2.192.1
244
+ ```
245
+
246
+ ### Deploy the Model as A SageMaker Endpoint ###
247
+ To deploy MistralLite on a SageMaker endpoint, please follow the example code as below.
248
+ ```python
249
+ import sagemaker
250
+ from sagemaker.huggingface import HuggingFaceModel, get_huggingface_llm_image_uri
251
+ import time
252
+
253
+ sagemaker_session = sagemaker.Session()
254
+ region = sagemaker_session.boto_region_name
255
+ role = sagemaker.get_execution_role()
256
+
257
+ image_uri = get_huggingface_llm_image_uri(
258
+ backend="huggingface", # or lmi
259
+ region=region,
260
+ version="1.1.0"
261
+ )
262
+
263
+ model_name = "MistralLite-" + time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime())
264
+
265
+ hub = {
266
+ 'HF_MODEL_ID':'amazon/MistralLite',
267
+ 'HF_TASK':'text-generation',
268
+ 'SM_NUM_GPUS':'1',
269
+ "MAX_INPUT_LENGTH": '16000',
270
+ "MAX_TOTAL_TOKENS": '16384',
271
+ "MAX_BATCH_PREFILL_TOKENS": '16384',
272
+ "MAX_BATCH_TOTAL_TOKENS": '16384',
273
+ }
274
+
275
+ model = HuggingFaceModel(
276
+ name=model_name,
277
+ env=hub,
278
+ role=role,
279
+ image_uri=image_uri
280
+ )
281
+ predictor = model.deploy(
282
+ initial_instance_count=1,
283
+ instance_type="ml.g5.2xlarge",
284
+ endpoint_name=model_name,
285
+
286
+ )
287
+ ```
288
+
289
+ ### Perform Inference ###
290
+ To call the endpoint, please follow the example code as below:
291
+
292
+ ```python
293
+ input_data = {
294
+ "inputs": "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
295
+ "parameters": {
296
+ "do_sample": False,
297
+ "max_new_tokens": 400,
298
+ "return_full_text": False,
299
+ #"typical_p": 0.2,
300
+ #"temperature":None,
301
+ #"truncate":None,
302
+ #"seed": 1,
303
+ }
304
+ }
305
+ result = predictor.predict(input_data)[0]["generated_text"]
306
+ print(result)
307
+ ```
308
+ or via [boto3](https://pypi.org/project/boto3/), and the example code is shown as below:
309
+
310
+ ```python
311
+ import boto3
312
+ import json
313
+ def call_endpoint(client, prompt, endpoint_name, paramters):
314
+ client = boto3.client("sagemaker-runtime")
315
+ payload = {"inputs": prompt,
316
+ "parameters": parameters}
317
+ response = client.invoke_endpoint(EndpointName=endpoint_name,
318
+ Body=json.dumps(payload),
319
+ ContentType="application/json")
320
+ output = json.loads(response["Body"].read().decode())
321
+ result = output[0]["generated_text"]
322
+ return result
323
+
324
+ client = boto3.client("sagemaker-runtime")
325
+ parameters = {
326
+ "do_sample": False,
327
+ "max_new_tokens": 400,
328
+ "return_full_text": False,
329
+ #"typical_p": 0.2,
330
+ #"temperature":None,
331
+ #"truncate":None,
332
+ #"seed": 1,
333
+ }
334
+ endpoint_name = predictor.endpoint_name
335
+ prompt = "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>"
336
+ result = call_endpoint(client, prompt, endpoint_name, parameters)
337
+ print(result)
338
+ ```
339
+
340
+
341
+ ## How to Serve MistralLite on vLLM ##
342
+ Documentation on installing and using vLLM [can be found here](https://vllm.readthedocs.io/en/latest/).
343
+
344
+ **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).
345
+
346
+ ### Using vLLM as a server ###
347
+ When using vLLM as a server, pass the --model amazon/MistralLite parameter, for example:
348
+ ```shell
349
+ python3 -m vllm.entrypoints.api_server --model amazon/MistralLite
350
+ ```
351
+
352
+ ### Using vLLM in Python Code ###
353
+ When using vLLM from Python code, Please see the example code as below:
354
+
355
+ ```python
356
+ from vllm import LLM, SamplingParams
357
+
358
+ prompts = [
359
+ "<|prompter|>What are the main challenges to support a long context for LLM?</s><|assistant|>",
360
+ ]
361
+ sampling_params = SamplingParams(temperature=0, max_tokens=100)
362
+
363
+ llm = LLM(model="amazon/MistralLite",)
364
+
365
+ outputs = llm.generate(prompts, sampling_params)
366
+
367
+ # Print the outputs.
368
+ for output in outputs:
369
+ prompt = output.prompt
370
+ generated_text = output.outputs[0].text
371
+ print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
372
+ ```
373
+
374
+ ## Limitations ##
375
+ 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.