Views
No views yet
MegaBeam-Mistral-7B-512k is a Large-Context LLM that supports 524,288 tokens in its context. MegaBeam-Mistral-7B-512k was trained on Mistral-7B Instruct-v0.2, and can be deployed using various serving frameworks like vLLM and Amazon SageMaker's DJL endpoint.MegaBeam-Mistral-7B-512k on three long-context benchmarks. For each benchmark, we deployed the MegaBeam-Mistral-7B-512k model with vLLM (v0.5.1) on an EC2 instance and obtained LLM responses through the OpenAI API provided by vLLM.MegaBeam-Mistral-7B-512k scored 100% on this NIAH benchmark as shown in this plot.
MegaBeam-Mistral-7B-512k scored an average of 88.70 across different context lengths as shown in this table (adapted from the RULER project).| Models | 4K | 8K | 16K | 32K | 64K | 128K | Avg. |
|---|---|---|---|---|---|---|---|
| MegaBeam-Mistral-7B-512k | 93.3 | 91.8 | 91.5 | 88.9 | 83.7 | 82.8 | 88.7 |
| Gemini-1.5-pro | 96.7 | 95.8 | 96 | 95.9 | 95.9 | 94.4 | 95.8 |
| GPT-4-1106-preview | 96.6 | 96.3 | 95.2 | 93.2 | 87 | 81.2 | 91.6 |
| Llama3.1 (70B) | 96.5 | 95.8 | 95.4 | 94.8 | 88.4 | 66.6 | 89.6 |
| Qwen2 (72B) | 96.9 | 96.1 | 94.9 | 94.1 | 79.8 | 53.7 | 85.9 |
| Command-R-plus (104B) | 95.6 | 95.2 | 94.2 | 92 | 84.3 | 63.1 | 87.4 |
| GLM4 (9B) | 94.7 | 92.8 | 92.1 | 89.9 | 86.7 | 83.1 | 89.9 |
| Llama3.1 (8B) | 95.5 | 93.8 | 91.6 | 87.4 | 84.7 | 77.0 | 88.3 |
| Command-R (35B) | 93.8 | 93.3 | 92.4 | 89.5 | 84.9 | 76 | 88.3 |
| GradientAI/Llama3 (70B) | 95.1 | 94.4 | 90.8 | 85.4 | 82.9 | 72.1 | 86.5 |
| Mixtral-8x22B (39B/141B) | 95.6 | 94.9 | 93.4 | 90.9 | 84.7 | 31.7 | 81.9 |
| Yi (34B) | 93.3 | 92.2 | 91.3 | 87.5 | 83.2 | 77.3 | 87.5 |
| Phi3-medium (14B) | 93.3 | 93.2 | 91.1 | 86.8 | 78.6 | 46.1 | 81.5 |
| Mixtral-8x7B (12.9B/46.7B) | 94.9 | 92.1 | 92.5 | 85.9 | 72.4 | 44.5 | 80.4 |
| GradientAI/Llama3 (8B) | 92.8 | 90.3 | 85.7 | 79.9 | 76.3 | 69.5 | 82.4 |
| FILM-7B (7B) | 92.8 | 88.2 | 88.1 | 86.9 | 70.1 | 27.1 | 75.5 |
| Mistral-7B-instruct-v0.2 (7B) | 93.6 | 91.2 | 87.2 | 75.4 | 49 | 13.8 | 68.4 |
| Mistral-Nemo | 87.8 | 87.2 | 87.7 | 69.0 | 46.8 | 19.0 | 66.2 |
| GLM3 (6B) | 87.8 | 83.4 | 78.6 | 69.9 | 56 | 42 | 69.6 |
| LWM (7B) | 82.3 | 78.4 | 73.7 | 69.1 | 68.1 | 65 | 72.8 |
| Task | Category | 4096 | 8192 | 16384 | 32768 | 65536 | 131072 |
|---|---|---|---|---|---|---|---|
| niah_single_1 | Retrieval | 100 | 100 | 100 | 100 | 100 | 100 |
| niah_single_2 | Retrieval | 98.6 | 97.8 | 98.8 | 98.2 | 99.4 | 99.6 |
| niah_single_3 | Retrieval | 100 | 100 | 100 | 99.8 | 100 | 99.8 |
| niah_multikey_1 | Retrieval | 98.8 | 99.6 | 99.2 | 99 | 99.6 | 99.6 |
| niah_multikey_2 | Retrieval | 100 | 100 | 100 | 99.8 | 99.4 | 98.6 |
| niah_multikey_3 | Retrieval | 99.8 | 99.4 | 99.8 | 100 | 98.6 | 97.8 |
| niah_multivalue | Retrieval | 97.1 | 93.8 | 91.85 | 83.5 | 80.3 | 71.45 |
| niah_multiquery | Retrieval | 99.95 | 99.9 | 99.85 | 99.3 | 99.55 | 99.3 |
| vt | Multi-hop Tracing | 99.2 | 97.88 | 96.44 | 96.12 | 91.6 | 89.08 |
| cwe | Aggregation | 98.2 | 90.62 | 75.6 | 52.72 | 5.9 | 0.94 |
| fwe | Aggregation | 81.47 | 80.07 | 95.87 | 96.33 | 83.73 | 96.87 |
| qa_1 | Q & A | 85.6 | 82 | 80.6 | 83 | 80.6 | 77.4 |
| qa_2 | Q & A | 53.8 | 52 | 51.6 | 48.4 | 49.2 | 45.8 |
| average | ALL | 93.3 | 91.8 | 91.5 | 88.9 | 83.7 | 82.8 |
| Total Average | 88.7 |
MegaBeam-Mistral-7B-512k's result in this table.| Task Name | MegaBeam-Mistral -7B-512k | GPT-4-1106 -preview | YaRN-Mistral -7B | Kimi-Chat | Claude 2 | Yi-34B -200K |
|---|---|---|---|---|---|---|
| PassKey | 100% | 100% | 92.71% | 98.14% | 97.80% | 100.00% |
| Retrv.Num | 99.49% | 100% | 56.61% | 95.42% | 98.14% | 100.00% |
| Retrv.KV | 24.20% | 89.00% | < 5% | 53.60% | 65.40% | < 5% |
| En.Sum | 34.66% | 14.73% | 9.09% | 17.93% | 14.45% | < 5% |
| En.QA | 20.32% | 22.22% | 9.55% | 16.52% | 11.97% | 12.17% |
| En.MC | 61.57% | 67.25% | 27.95% | 72.49% | 62.88% | 38.43% |
| En.Dia | 10.50% | 8.50% | 7.50% | 11.50% | 46.50% | < 5% |
| Zh.QA | 19.54% | 25.96% | 14.43% | 17.93% | 9.64% | 13.61% |
| Code.Debug | 26.14% | 39.59% | < 5% | 18.02% | < 5% | < 5% |
| Code.Run | 2% | 23.25% | < 5% | < 5% | < 5% | < 5% |
| Math.Calc | 0% | < 5% | < 5% | < 5% | < 5% | < 5% |
| Math.Find | 20% | 60.00% | 17.14% | 12.57% | 32.29% | 25.71% |
| Average | 34.87% | 46.08% | 20.41% | 34.93% | 37.21% | 25.41% |
MegaBeam-Mistral-7B-512k's long context capability by processing a large file that includes hundreds of files from a single Git repository. This can be useful for onboarding new developers.
g5.48xlarge instance, install vLLM as per vLLM docs.pip install vllm==0.5.11VLLM_ENGINE_ITERATION_TIMEOUT_S=3600 python3 -m vllm.entrypoints.openai.api_server \
2 --model aws-prototyping/MegaBeam-Mistral-7B-512k \
3 --tensor-parallel-size 8 \
4 --revision g5-48xg5-48x, config.json has been updated to set max_position_embeddings to 288,800, fitting the model's KV cache on a single g5.48xlarge instance with 8 A10 GPUs (24GB RAM per GPU).p4d.24xlarge), simply remove the revision argument in order to support the full sequence length of 524,288 tokens:1VLLM_ENGINE_ITERATION_TIMEOUT_S=3600 python3 -m vllm.entrypoints.openai.api_server \
2 --model aws-prototyping/MegaBeam-Mistral-7B-512k \
3 --tensor-parallel-size 8 \1from openai import OpenAI
2
3# Modify OpenAI's API key and API base to use vLLM's API server.
4openai_api_key = "EMPTY"
5openai_api_base = "http://localhost:8000/v1"
6
7client = OpenAI(
8 # defaults to os.environ.get("OPENAI_API_KEY")
9 api_key=openai_api_key,
10 base_url=openai_api_base,
11)
12
13models = client.models.list()
14model = models.data[0].id
15
16chat_completion = client.chat.completions.create(
17 messages = [
18 {"role": "user", "content": "What is your favourite condiment?"}, # insert your long context here
19 {"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!"},
20 {"role": "user", "content": "Do you have mayonnaise recipes?"} # insert your long context here
21 ],
22 model=model,
23)
24
25print("Chat completion results:")
26print(chat_completion)1import sagemaker
2from sagemaker import Model, image_uris, serializers, deserializers
3
4sagemaker_session = sagemaker.Session()
5region = sagemaker_session.boto_region_name
6role = sagemaker.get_execution_role()
7
8%%writefile serving.properties
9engine=Python
10option.model_id=aws-prototyping/MegaBeam-Mistral-7B-512k
11option.revision=g5-48x
12option.dtype=bf16
13option.task=text-generation
14option.rolling_batch=vllm
15option.tensor_parallel_degree=8
16option.device_map=auto
17
18%%sh
19mkdir mymodel
20mv serving.properties mymodel/
21tar czvf mymodel.tar.gz mymodel/
22rm -rf mymodel
23
24image_uri = image_uris.retrieve(
25 framework="djl-deepspeed",
26 region=region,
27 version="0.27.0"
28)
29
30s3_code_prefix = "megaBeam-mistral-7b-512k/code"
31bucket = sagemaker_session.default_bucket() # bucket to house artifacts
32code_artifact = sagemaker_session.upload_data("mymodel.tar.gz", bucket, s3_code_prefix)
33print(f"S3 Code or Model tar ball uploaded to --- > {code_artifact}")
34model = Model(image_uri=image_uri, model_data=code_artifact, role=role)
35
36instance_type = "ml.g5.48xlarge"
37endpoint_name = sagemaker.utils.name_from_base("megaBeam-mistral-7b-512k")
38model.deploy(initial_instance_count=1,
39 instance_type=instance_type,
40 endpoint_name=endpoint_name
41 )
42
43# our requests and responses will be in json format so we specify the serializer and the deserializer
44predictor = sagemaker.Predictor(
45 endpoint_name=endpoint_name,
46 sagemaker_session=sagemaker_session,
47 serializer=serializers.JSONSerializer(),
48)
49
50# test the endpoint
51input_str = """<s>[INST] What is your favourite condiment? [/INST]
52Well, 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> "
53[INST] Do you have mayonnaise recipes? [/INST]"""
54predictor.predict(
55 {"inputs": input_str, "parameters": {"max_new_tokens": 75}}
56)
571import boto3
2import json
3
4def call_endpoint(text:str, endpoint_name:str):
5 client = boto3.client("sagemaker-runtime")
6
7 parameters = {
8 "max_new_tokens": 450,
9 "do_sample": True,
10 "temperature": 0.7,
11 }
12
13 payload = {"inputs": text, "parameters": parameters}
14
15 response = client.invoke_endpoint(
16 EndpointName=endpoint_name, Body=json.dumps(payload), ContentType="application/json"
17 )
18
19 output = json.loads(response["Body"].read().decode())
20
21 result = output["generated_text"]
22 return result
23
24# please insert your long prompt/document content here
25prompt = """<s>[INST] What are the main challenges to support long contexts for a Large Language Model? [/INST]"""
26
27#print(prompt)
28endpoint_name = "megaBeam-mistral-7b-512k-2024-05-13-14-23-41-219" # please use a valid endpoint name
29result = call_endpoint(prompt, endpoint_name)
30print(result)