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