Downloads · 30 days
7.6K
5% of all-time downloads
mozilla-ai/Phi-3-medium-128k-instruct-llamafile
Phi-3-medium-128k-instruct-llamafile is a machine learning model from mozilla-ai. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This is a large language model that was released by Microsoft on May 21st, 2024. It has an outstanding context size, which makes it good for summarizing and extracting information from large bodies of text. It's also…
Downloads · 30 days
7.6K
5% of all-time downloads
All-time downloads
163K
Public
Repo size
878 GB
Likes
6
Public
Click a slice to open those files.
.llamafile181 GB · 100%
From the Hugging Face model README
This is a large language model that was released by Microsoft on May 21st, 2024. It has an outstanding context size, which makes it good for summarizing and extracting information from large bodies of text. It's also been fine-tuned to follow your instructions.
Mozilla has packaged the Phi-3 model into executable weights that we call llamafiles. This gives you the easiest fastest way to use the model on Linux, MacOS, Windows, FreeBSD, OpenBSD and NetBSD systems you control on both AMD64 and ARM64.
Running the following on a desktop OS will launch a tab in your web browser with both a chatbot interface and a completion interface.
wget https://huggingface.co/Mozilla/Phi-3-medium-128k-instruct-llamafile/resolve/main/Phi-3-medium-128k-instruct.Q6_K.llamafile
chmod +x Phi-3-medium-128k-instruct.Q6_K.llamafile
./Phi-3-medium-128k-instruct.Q6_K.llamafile
You then need to fill out the text fields in the web GUI with the prompt text below, in order for the chatbot to work correctly.
This model has a max context window size of 128k tokens. By default, a
context window size of 512 tokens is used. You can configure llamafile
to use the maxmimum context size with the -c 0 flag. Please note a
context size of 128k will require allocating many gigabytes of RAM.
On GPUs with sufficient RAM, the -ngl 999 flag may be passed to use
the system's NVIDIA or AMD GPU(s). On Windows, only the graphics card
driver needs to be installed. If the prebuilt DSOs should fail, the CUDA
or ROCm SDKs may need to be installed, in which case llamafile builds a
native module just for your system.
For further information, please see the llamafile README.
Having trouble? See the "Gotchas" section of the README.
Prompt template (note: microsoft specifies no system prompt):
{{history}}<|assistant|>
History template:
<|user|>
{{message}}<|end|>
Command template:
./Phi-3-medium-128k-instruct.Q6_K.llamafile -e -p '<|user|>\nQuestion <|end|>\n<|assistant|>'
We tested these llamafiles for CPU inference with prompts as large as 86k tokens on Threadripper and got good results.
llamafile is a new format introduced by Mozilla Ocho on Nov 20th 2023. It uses Cosmopolitan Libc to turn LLM weights into runnable llama.cpp binaries that run on the stock installs of six OSes for both ARM64 and AMD64.
The Phi-3-Medium-128K-Instruct is a 14B parameters, lightweight, state-of-the-art open model trained with the Phi-3 datasets that includes both synthetic data and the filtered publicly available websites data with a focus on high-quality and reasoning dense properties. The model belongs to the Phi-3 family with the Medium version in two variants 4k and 128K which is the context length (in tokens) that it can support.
The model has underwent a post-training process that incorporates both supervised fine-tuning and direct preference optimization for the instruction following and safety measures. When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3-Medium-128K-Instruct showcased a robust and state-of-the-art performance among models of the same-size and next-size-up.
Resources and Technical Documentation:
| Short Context | Long Context | |
|---|---|---|
| Mini | 4K [HF] ; [ONNX] ; [GGUF] | 128K [HF] ; [ONNX] |
| Small | 8K [HF] ; [ONNX] | 128K [HF] ; [ONNX] |
| Medium | 4K [HF] ; [ONNX] | 128K [HF] ; [ONNX] |
| Vision | 128K [HF] ; [ONNX] |
Primary use cases
The model is intended for broad commercial and research use in English. The model provides uses for general purpose AI systems and applications which require :
Our model is designed to accelerate research on language and multimodal models, for use as a building block for generative AI powered features.
Use case considerations
Our models are not specifically designed or evaluated for all downstream purposes. Developers should consider common limitations of language models as they select use cases, and evaluate and mitigate for accuracy, safety, and fariness before using within a specific downstream use case, particularly for high risk scenarios. Developers should be aware of and adhere to applicable laws or regulations (including privacy, trade compliance laws, etc.) that are relevant to their use case.
Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
Phi-3-Medium-128k-Instruct has been integrated in the development version (4.40.2) of transformers. Until the official version is released through pip, ensure that you are doing one of the following:
When loading the model, ensure that trust_remote_code=True is passed as an argument of the from_pretrained() function.
Update your local transformers to the development version: pip uninstall -y transformers && pip install git+https://github.com/huggingface/transformers. The previous command is an alternative to cloning and installing from the source.
The current transformers version can be verified with: pip list | grep transformers.
Phi-3-Medium-128k-Instruct is also available in Azure AI Studio.
Phi-3-Medium-128k-Instruct supports a vocabulary size of up to 32064 tokens. The tokenizer files already provide placeholder tokens that can be used for downstream fine-tuning, but they can also be extended up to the model's vocabulary size.
Given the nature of the training data, the Phi-3-Medium-128k-Instruct model is best suited for prompts using the chat format as follows. You can provide the prompt as a question with a generic template as follow:
<|user|>\nQuestion <|end|>\n<|assistant|>
For example:
<|user|>
How to explain Internet for a medieval knight?<|end|>
<|assistant|>
where the model generates the text after <|assistant|> . In case of few-shots prompt, the prompt can be formatted as the following:
<|user|>
I am going to Paris, what should I see?<|end|>
<|assistant|>
Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\nThese are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world."<|end|>
<|user|>
What is so great about #1?<|end|>
<|assistant|>
This code snippets show how to get quickly started with running the model on a GPU:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
torch.random.manual_seed(0)
model_id = "microsoft/Phi-3-medium-128k-instruct"
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "user", "content": "Can you provide ways to eat combinations of bananas and dragonfruits?"},
{"role": "assistant", "content": "Sure! Here are some ways to eat bananas and dragonfruits together: 1. Banana and dragonfruit smoothie: Blend bananas and dragonfruits together with some milk and honey. 2. Banana and dragonfruit salad: Mix sliced bananas and dragonfruits together with some lemon juice and honey."},
{"role": "user", "content": "What about solving an 2x + 3 = 7 equation?"},
]
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 500,
"return_full_text": False,
"temperature": 0.0,
"do_sample": False,
}
output = pipe(messages, **generation_args)
print(output[0]['generated_text'])
Some applications/frameworks might not include a BOS token (<s>) at the start of the conversation. Please ensure that it is included since it provides more reliable results.
Like other language models, the Phi series models can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:
Developers should apply responsible AI best practices and are responsible for ensuring that a specific use case complies with relevant laws and regulations (e.g. privacy, trade, etc.). Important areas for consideration include:
Our training data includes a wide variety of sources, totaling 4.8 trillion tokens (including 10% multilingual), and is a combination of
We are focusing on the quality of data that could potentially improve the reasoning ability for the model, and we filter the publicly available documents to contain the correct level of knowledge. As an example, the result of a game in premier league in a particular day might be good training data for frontier models, but we need to remove such information to leave more model capacity for reasoning for the small size models. More details about data can be found in the Phi-3 Technical Report.
We report the results for Phi-3-Medium-128k-Instruct on standard open-source benchmarks measuring the model's reasoning ability (both common sense reasoning and logical reasoning). We compare to Mixtral-8x22b, Gemini-Pro, Command R+ 104B, Llama-3-70B-Instruct, GPT-3.5-Turbo-1106, and GPT-4-Turbo-1106(Chat).
All the reported numbers are produced with the exact same pipeline to ensure that the numbers are comparable. These numbers might differ from other published numbers due to slightly different choices in the evaluation.
As is now standard, we use few-shot prompts to evaluate the models, at temperature 0. The prompts and number of shots are part of a Microsoft internal tool to evaluate language models, and in particular we did no optimization to the pipeline for Phi-3. More specifically, we do not change prompts, pick different few-shot examples, change prompt format, or do any other form of optimization for the model.
The number of k–shot examples is listed per-benchmark.
| Benchmark | Phi-3-Medium-128k-Instruct<br>14b | Command R+<br>104B | Mixtral<br>8x22B | Llama-3-70B-Instruct | GPT3.5-Turbo<br>version 1106 | Gemini<br>Pro | GPT-4-Turbo<br>version 1106 (Chat) |
|---|---|---|---|---|---|---|---|
| AGI Eval<br>5-shot | 49.7 | 50.1 | 54.0 | 56.9 | 48.4 | 49.0 | 59.6 |
| MMLU<br>5-shot | 76.6 | 73.8 | 76.2 | 80.2 | 71.4 | 66.7 | 84.0 |
| BigBench Hard<br>3-shot | 77.9 | 74.1 | 81.8 | 80.4 | 68.3 | 75.6 | 87.7 |
| ANLI<br>7-shot | 57.3 | 63.4 | 65.2 | 68.3 | 58.1 | 64.2 | 71.7 |
| HellaSwag<br>5-shot | 81.6 | 78.0 | 79.0 | 82.6 | 78.8 | 76.2 | 88.3 |
| ARC Challenge<br>10-shot | 91.0 | 86.9 | 91.3 | 93.0 | 87.4 | 88.3 | 95.6 |
| ARC Easy<br>10-shot | 97.6 | 95.7 | 96.9 | 98.2 | 96.3 | 96.1 | 98.8 |
| BoolQ<br>2-shot | 86.5 | 86.1 | 82.7 | 89.1 | 79.1 | 86.4 | 91.3 |
| CommonsenseQA<br>10-shot | 82.2 | 82.0 | 82.0 | 84.4 | 79.6 | 81.8 | 86.7 |
| MedQA<br>2-shot | 67.6 | 59.2 | 67.9 | 78.5 | 63.4 | 58.2 | 83.7 |
| OpenBookQA<br>10-shot | 87.2 | 86.8 | 88.6 | 91.8 | 86.0 | 86.4 | 93.4 |
| PIQA<br>5-shot | 87.8 | 86.4 | 85.0 | 85.3 | 86.6 | 86.2 | 90.1 |
| Social IQA<br>5-shot | 79.0 | 75.3 | 78.2 | 81.1 | 68.3 | 75.4 | 81.7 |
| TruthfulQA (MC2)<br>10-shot | 74.3 | 57.8 | 67.4 | 81.9 | 67.7 | 72.6 | 85.2 |
| WinoGrande<br>5-shot | 78.9 | 77.0 | 75.3 | 83.3 | 68.8 | 72.2 | 86.7 |
| TriviaQA<br>5-shot | 73.9 | 82.8 | 84.5 | 78.5 | 85.8 | 80.2 | 73.3 |
| GSM8K Chain of Thought<br>8-shot | 87.5 | 78.3 | 83.8 | 93.5 | 78.1 | 80.4 | 94.2 |
| HumanEval<br>0-shot | 58.5 | 61.6 | 39.6 | 78.7 | 62.2 | 64.4 | 79.9 |
| MBPP<br>3-shot | 73.8 | 68.9 | 70.7 | 81.3 | 77.8 | 73.2 | 86.7 |
| Average | 77.3 | 75.0 | 76.3 | 82.5 | 74.3 | 75.4 | 85.2 |
We take a closer look at different categories across 80 public benchmark datasets at the table below:
| Benchmark | Phi-3-Medium-128k-Instruct<br>14b | Command R+<br>104B | Mixtral<br>8x22B | Llama-3-70B-Instruct | GPT3.5-Turbo<br>version 1106 | Gemini<br>Pro | GPT-4-Turbo<br>version 1106 (Chat) |
|---|---|---|---|---|---|---|---|
| Popular aggregated benchmark | 72.3 | 69.9 | 73.4 | 76.3 | 67.0 | 67.5 | 80.5 |
| Reasoning | 83.2 | 79.3 | 81.5 | 86.7 | 78.3 | 80.4 | 89.3 |
| Language understanding | 75.3 | 75.7 | 78.7 | 77.9 | 70.4 | 75.3 | 81.6 |
| Code generation | 64.2 | 68.6 | 60.0 | 69.3 | 70.4 | 66.7 | 76.1 |
| Math | 52.9 | 45.3 | 52.5 | 59.7 | 52.8 | 50.9 | 67.1 |
| Factual knowledge | 47.5 | 60.3 | 60.6 | 52.4 | 63.4 | 54.6 | 45.9 |
| Multilingual | 62.2 | 67.8 | 69.8 | 62.0 | 67.0 | 73.4 | 78.2 |
| Robustness | 70.2 | 57.9 | 65.5 | 78.7 | 69.3 | 69.7 | 84.6 |
Note that by default, the Phi-3-Medium model uses flash attention, which requires certain types of GPU hardware to run. We have tested on the following GPU types:
If you want to run the model on:
ONNX runtime ecosystem now supports Phi3 Medium models across platforms and hardware.
Optimized phi-3 models are also published here in ONNX format, to run with ONNX Runtime on CPU and GPU across devices, including server platforms, Windows, Linux and Mac desktops, and mobile CPUs, with the precision best suited to each of these targets. DirectML GPU acceleration is supported for Windows desktops GPUs (AMD, Intel, and NVIDIA).
Along with DML, ONNX Runtime provides cross platform support for Phi3 Medium across a range of devices CPU, GPU, and mobile.
Here are some of the optimized configurations we have added:
The model is licensed under the MIT license.
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.