xceptor commited on
Commit
46a0f9c
1 Parent(s): 534b334

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +165 -3
README.md CHANGED
@@ -1,3 +1,165 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ inference: false
4
+ ---
5
+
6
+ # MegaBeam-Mistral-7B-300k Model
7
+
8
+ MegaBeam-Mistral-7B-300k is a fine-tuned [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) language model that supports input contexts up to 320k tokens. MegaBeam-Mistral-7B-300k can be deployed on a single AWS `g5.48xlarge` instance using serving frameworks such as [vLLM](https://github.com/vllm-project/vllm), Sagemaker [DJL](https://docs.aws.amazon.com/sagemaker/latest/dg/deploy-models-frameworks-djl-serving.html) endpoint, and others. Similarities and differences beween MegaBeam-Mistral-7B-300k and [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) are summarized below:
9
+
10
+
11
+ |Model|Max context length| rope_theta| prompt template|
12
+ |----------|-------------:|------------:|------------:|
13
+ | [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2) | 32K | 1e6 | [instruction format](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2#instruction-format)|
14
+ | MegaBeam-Mistral-7B-300k | 320K | 25e6 | AS ABOVE|
15
+
16
+ ## Evaluations
17
+
18
+ **[InfiniteBench: Extending Long Context Evaluation Beyond 100K Tokens](https://github.com/OpenBMB/InfiniteBench)**
19
+
20
+ _InfiniteBench is a cutting-edge benchmark tailored for evaluating the capabilities of language models to process, understand, and reason over super long contexts (100k+ tokens)_. We therefore evaluated MegaBeam-Mistral-7B-300k, [Mistral-7B-Instruct-v0.2](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2), [Llama-3-8B-Instruct-262k](https://huggingface.co/gradientai/Llama-3-8B-Instruct-262k), and [Llama3-70B-1M](https://huggingface.co/gradientai/Llama-3-70B-Instruct-Gradient-1048k) on InfiniteBench. The InfiniteBench authors also evaluated SOTA proprietary and open-source LLMs on InfiniteBench. We thus combined both results in the table below.
21
+
22
+ | Task Name | MegaBeam-Mistral-7B-300k | Mistral-7B-Instruct-v0.2 | Llama-3-8B-Instruct-262k | Llama3-70B-1M | GPT-4-1106-preview | YaRN-Mistral-7B | Kimi-Chat | Claude 2 | Yi-6B-200K | Yi-34B-200K | Chatglm3-6B-128K |
23
+ | ---------------- | ---------------- | ---------------- | ---------------- | ---------------- | ------ | --------------- | --------- | -------- | -----------| -----------| -----------|
24
+ | Retrieve.PassKey | 100% | 75.76% | 98.30% | 81.35% | 100% | 92.71% | 98.14% | 97.80% | 100.00% | 100.00% | 92.20% |
25
+ | Retrieve.Number | 96.10% | 25.25% | 97.79% | 97.62% | 100% | 56.61% | 95.42% | 98.14% | 94.92% | 100.00% | 80.68% |
26
+ | Retrieve.KV | 0% | 0% | 3.40% | 3% | 89.00% | < 5% | 53.60% | 65.40% | < 5% | < 5% | < 5% |
27
+ | En.Sum | 29.39% | 22.13% | 16.40% | 20.72% | 14.73% | 9.09% | 17.93% | 14.45% | < 5% | < 5% |< 5% |
28
+ | En.QA | 14.93% | 4.93% | 13.20% | 16.52% | 22.22% | 9.55% | 16.52% | 11.97% | 9.20% | 12.17% |< 5% |
29
+ | En.MC | 51.52% | 7.80% | 50.65% | 62% | 67.25% | 27.95% | 72.49% | 62.88% | 36.68% |38.43% |10.48% |
30
+ | En.Dia | 9.50% | 3.50% | 1% | 12.50% | 8.50% | 7.50% | 11.50% | 46.50% | < 5% |< 5% |< 5% |
31
+ | Zh.QA | 10.71% | 3.43% | 19.02% | 26% | 25.96% | 14.43% | 17.93% | 9.64% | 15.07% |13.61% |< 5% |
32
+ | Code.Debug | 27.41% | 11.60% | 22.08% | 23.85% | 39.59% | < 5% | 18.02% | < 5% | < 5% |< 5% |< 5% |
33
+ | Code.Run | 1.75% | 0.25% | 0% | 0% | 23.25% | < 5% | < 5% | < 5% | < 5% |< 5% |< 5% |
34
+ | Math.Calc | 0% | 0% | 0% | 0% | < 5% | < 5% | < 5% | < 5% | < 5% |< 5% |< 5% |
35
+ | Math.Find | 24.28% | 26.28% | 15.40% | 30% | 60.00% | 17.14% | 12.57% | 32.29% | < 5% |25.71% |7.71% |
36
+ | **Average** | 30.70% | 15.08% | 28.10% | 31.13% | 46.08% | 20.41% | 34.93% | 37.21% | 22.78% |25.41% |17.59% |
37
+
38
+ The 12 evaluation tasks are summarized below (as per [InfiniteBench]((https://github.com/OpenBMB/InfiniteBench)))
39
+ | Task Name | Context | # Examples | Avg Input Tokens | Avg Output Tokens | Description |
40
+ | -------------------- | ------------- | ---------- | ---------------- | ----------------- | ------------------------------------------------------------------------------------------- |
41
+ | En.Sum | Fake Book | 103 | 171.5k | 1.1k | Summarization of a fake book created with core entity substitution. |
42
+ | En.QA | Fake Book | 351 | 192.6k | 4.8 | Free-form question answering based on the fake book. |
43
+ | En.MC | Fake Book | 229 | 184.4k | 5.3 | Multiple choice questions derived from the fake book. |
44
+ | En.Dia | Script | 200 | 103.6k | 3.4 | Identification of talkers in partially anonymized scripts. |
45
+ | Zh.QA | New Book | 175 | 2068.6k | 6.3 | Question answering on a set of newly collected books. |
46
+ | Code.Debug | Code Document | 394 | 114.7k | 4.8 | Finding which function in a code repo contains an crashing error (in multiple choice form). |
47
+ | Code.Run | Synthetic | 400 | 75.2k | 1.3 | Simulating execution of multiple simple, synthetic functions. |
48
+ | Math.Calc | Synthetic | 50 | 43.9k | 43.9k | Calculations involving super-long arithmetic equations. |
49
+ | Math.Find | Synthetic | 350 | 87.9k | 1.3 | Finding special integers in a lengthy list. |
50
+ | Retrieve.PassKey | Synthetic | 590 | 122.4k | 2.0 | Retrieving hidden keys in a noisy long context. |
51
+ | Retrieve.Number | Synthetic | 590 | 122.4k | 4.0 | Locating repeated hidden numbers in a noisy long context. |
52
+ | Retrieve.KV | Synthetic | 500 | 89.9k | 22.7 | Finding the corresponding value from a dictionary and a key. |
53
+
54
+
55
+ ## Serve MegaBeam-Mistral-7B-300k on EC2 instances ##
56
+ On an AWS `g5.48xlarge` instance, upgrade vLLM to the latest version as per [documentation on vLLM](https://vllm.readthedocs.io/en/latest/).
57
+
58
+ ### Start the server
59
+ ```shell
60
+ python3 -m vllm.entrypoints.openai.api_server --model amazon/MegaBeam-Mistral-7B-300k --tensor-parallel-size 8
61
+ ```
62
+ **Important Note** - We have set the `max_position_embeddings` in the [`config.json`](config.json) to 288,800 in order to fit model's KV-cache on a single `g5.48xlarge` instance, which has 8 x A10 GPUs (24GB RAM per GPU).
63
+
64
+ On an instance with larger GPU RAM (e.g. `p4d.24xlarge`), feel free to increase the value of the `max_position_embeddings`(e.g. to 350K), which the model should be able to process.
65
+
66
+ ### Run the client
67
+ ```python
68
+ from openai import OpenAI
69
+
70
+ # Modify OpenAI's API key and API base to use vLLM's API server.
71
+ openai_api_key = "EMPTY"
72
+ openai_api_base = "http://localhost:8000/v1"
73
+
74
+ client = OpenAI(
75
+ # defaults to os.environ.get("OPENAI_API_KEY")
76
+ api_key=openai_api_key,
77
+ base_url=openai_api_base,
78
+ )
79
+
80
+ models = client.models.list()
81
+ model = models.data[0].id
82
+
83
+ chat_completion = client.chat.completions.create(
84
+ messages = [
85
+ {"role": "user", "content": "What is your favourite condiment?"}, # insert your long context here
86
+ {"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!"},
87
+ {"role": "user", "content": "Do you have mayonnaise recipes?"} # insert your long context here
88
+ ],
89
+ model=model,
90
+ )
91
+
92
+ print("Chat completion results:")
93
+ print(chat_completion)
94
+ ```
95
+
96
+ ### Deploy the model on a SageMaker Endpoint ###
97
+ To deploy MegaBeam-Mistral-7B-300k on a SageMaker endpoint, please follow this [SageMaker DJL deployment guide](https://docs.djl.ai/docs/demos/aws/sagemaker/large-model-inference/sample-llm/vllm_deploy_mistral_7b.html).
98
+
99
+ Run the following Python code in a SageMaker notebook (with each block running in a separate cell)
100
+
101
+ ```python
102
+ import sagemaker
103
+ from sagemaker import Model, image_uris, serializers, deserializers
104
+
105
+ sagemaker_session = sagemaker.Session()
106
+ region = sagemaker_session.boto_region_name
107
+ role = sagemaker.get_execution_role()
108
+
109
+ %%writefile serving.properties
110
+ engine=Python
111
+ option.model_id=amazon/MegaBeam-Mistral-7B-300k
112
+ option.dtype=bf16
113
+ option.task=text-generation
114
+ option.rolling_batch=vllm
115
+ option.tensor_parallel_degree=8
116
+ option.device_map=auto
117
+
118
+ %%sh
119
+ mkdir mymodel
120
+ mv serving.properties mymodel/
121
+ tar czvf mymodel.tar.gz mymodel/
122
+ rm -rf mymodel
123
+
124
+ image_uri = image_uris.retrieve(
125
+ framework="djl-deepspeed",
126
+ region=region,
127
+ version="0.27.0"
128
+ )
129
+
130
+ s3_code_prefix = "megaBeam-mistral-7b-300k/code"
131
+ bucket = sagemaker_session.default_bucket() # bucket to house artifacts
132
+ code_artifact = sagemaker_session.upload_data("mymodel.tar.gz", bucket, s3_code_prefix)
133
+ print(f"S3 Code or Model tar ball uploaded to --- &gt; {code_artifact}")
134
+ model = Model(image_uri=image_uri, model_data=code_artifact, role=role)
135
+
136
+ instance_type = "ml.g5.48xlarge"
137
+ endpoint_name = sagemaker.utils.name_from_base("megaBeam-mistral-7b-300k")
138
+ model.deploy(initial_instance_count=1,
139
+ instance_type=instance_type,
140
+ endpoint_name=endpoint_name
141
+ )
142
+
143
+ # our requests and responses will be in json format so we specify the serializer and the deserializer
144
+ predictor = sagemaker.Predictor(
145
+ endpoint_name=endpoint_name,
146
+ sagemaker_session=sagemaker_session,
147
+ serializer=serializers.JSONSerializer(),
148
+ )
149
+
150
+ # test the endpoint
151
+ input_str = """<s>[INST] What is your favourite condiment? [/INST]
152
+ Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavour to whatever I'm cooking up in the kitchen!</s> "
153
+ [INST] Do you have mayonnaise recipes? [/INST]"""
154
+ predictor.predict(
155
+ {"inputs": input_str, "parameters": {"max_new_tokens": 75}}
156
+ )
157
+
158
+ ```
159
+
160
+
161
+ ## Limitations ##
162
+ Before using the MegaBeam-Mistral-7B-300k 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.
163
+
164
+ ## The AWS Contributors ##
165
+ Chen Wu, Yin Song, Verdi March, Eden Duthie