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