fix(root): Updates readme.
Browse files
README.md
CHANGED
@@ -12,8 +12,8 @@ tags:
|
|
12 |
|
13 |
## Model Summary
|
14 |
|
15 |
-
Phi-3 Mini-4K-Instruct is a 3.8B parameters, lightweight, state-of-the-art open model built upon datasets used for Phi-2 - synthetic data and filtered websites - with a focus on very high-quality, reasoning dense data.
|
16 |
-
|
17 |
The model underwent a rigorous enhancement process, incorporating both supervised fine-tuning and direct preference optimization to ensure precise instruction adherence and robust safety measures.
|
18 |
When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3 Mini-4K-Instruct showcased a robust and state-of-the-art performance among models with less than 13 billion parameters.
|
19 |
|
@@ -22,14 +22,15 @@ Resources and Technical Documentation:
|
|
22 |
+ [Phi-3 Microsoft Blog](https://aka.ms/phi3blog-april)
|
23 |
+ [Phi-3 Technical Report](https://aka.ms/phi3-tech-report)
|
24 |
+ [Phi-3 on Azure AI Studio](https://aka.ms/phi3-azure-ai)
|
25 |
-
+ Phi-3 GGUF: [4K](https://aka.ms/
|
26 |
-
+ Phi-3 ONNX: [4K](https://aka.ms/
|
27 |
|
28 |
## Intended Uses
|
29 |
|
30 |
**Primary use cases**
|
31 |
|
32 |
-
The model is intended for commercial and research use in English. The model provides uses for applications which require
|
|
|
33 |
1) Memory/compute constrained environments
|
34 |
2) Latency bound scenarios
|
35 |
3) Strong reasoning (especially math and logic)
|
@@ -38,8 +39,8 @@ Our model is designed to accelerate research on language and multimodal models,
|
|
38 |
|
39 |
**Use case considerations**
|
40 |
|
41 |
-
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.
|
42 |
-
|
43 |
Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
|
44 |
|
45 |
## How to Use
|
@@ -54,7 +55,7 @@ The current `transformers` version can be verified with: `pip list | grep transf
|
|
54 |
|
55 |
### Chat Format:
|
56 |
|
57 |
-
Given the nature of the training data, the Phi-3-
|
58 |
|
59 |
```markdown
|
60 |
<|system|>
|
@@ -66,7 +67,7 @@ How to explain Internet for a medieval knight?
|
|
66 |
<|assistant|>
|
67 |
```
|
68 |
|
69 |
-
where the model generates the text after
|
70 |
|
71 |
```markdown
|
72 |
<|system|>
|
@@ -92,19 +93,14 @@ import torch
|
|
92 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
93 |
|
94 |
torch.random.manual_seed(0)
|
95 |
-
token = "your huggingface token here"
|
96 |
-
|
97 |
-
model_id = "microsoft/Phi-3-mini-4k-instruct"
|
98 |
|
99 |
model = AutoModelForCausalLM.from_pretrained(
|
100 |
-
|
101 |
device_map="cuda",
|
102 |
torch_dtype="auto",
|
103 |
trust_remote_code=True,
|
104 |
-
token=token
|
105 |
)
|
106 |
-
|
107 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, token=token)
|
108 |
|
109 |
messages = [
|
110 |
{"role": "system", "content": "You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user."},
|
@@ -132,21 +128,24 @@ output = pipe(messages, **generation_args)
|
|
132 |
print(output[0]['generated_text'])
|
133 |
```
|
134 |
|
135 |
-
Note that by default the model use flash attention which requires certain types of GPU to run. If you want to run the model on
|
|
|
136 |
+ V100 or earlier generation GPUs: call `AutoModelForCausalLM.from_pretrained()` with `attn_implementation="eager"`
|
137 |
-
+ CPU: use the **GGUF** quantized models [4K](https://aka.ms/
|
138 |
-
+ Optimized inference: use the **ONNX** models [4K](https://aka.ms/
|
139 |
|
140 |
## Responsible AI Considerations
|
141 |
|
142 |
-
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:
|
|
|
143 |
+ Quality of Service: the Phi models are trained primarily on English text. Languages other than English will experience worse performance. English language varieties with less representation in the training data might experience worse performance than standard American English.
|
144 |
+ Representation of Harms & Perpetuation of Stereotypes: These models can over- or under-represent groups of people, erase representation of some groups, or reinforce demeaning or negative stereotypes. Despite safety post-training, these limitations may still be present due to differing levels of representation of different groups or prevalence of examples of negative stereotypes in training data that reflect real-world patterns and societal biases.
|
145 |
+ Inappropriate or Offensive Content: these models may produce other types of inappropriate or offensive content, which may make it inappropriate to deploy for sensitive contexts without additional mitigations that are specific to the use case.
|
146 |
+ Information Reliability: Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
|
147 |
+ Limited Scope for Code: Majority of Phi-3 training data is based in Python and use common packages such as "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages or scripts in other languages, we strongly recommend users manually verify all API uses.
|
148 |
|
149 |
-
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:
|
|
|
150 |
+ Allocation: Models may not be suitable for scenarios that could have consequential impact on legal status or the allocation of resources or life opportunities (ex: housing, employment, credit, etc.) without further assessments and additional debiasing techniques.
|
151 |
+ High-Risk Scenarios: Developers should assess suitability of using models in high-risk scenarios where unfair, unreliable or offensive outputs might be extremely costly or lead to harm. This includes providing advice in sensitive or expert domains where accuracy and reliability are critical (ex: legal or health advice). Additional safeguards should be implemented at the application level according to the deployment context.
|
152 |
+ Misinformation: Models may produce inaccurate information. Developers should follow transparency best practices and inform end-users they are interacting with an AI system. At the application level, developers can build feedback mechanisms and pipelines to ground responses in use-case specific, contextual information, a technique known as Retrieval Augmented Generation (RAG).
|
@@ -158,7 +157,7 @@ Developers should apply responsible AI best practices and are responsible for en
|
|
158 |
|
159 |
### Model
|
160 |
|
161 |
-
* Architecture: Phi-3 Mini has 3.8B parameters and is a dense decoder-only Transformer model. The model is fine-tuned with Supervised fine-tuning (SFT) and Direct Preference Optimization (DPO) to ensure alignment with human preferences and safety guidlines.
|
162 |
* Inputs: Text. It is best suited for prompts using chat format.
|
163 |
* Context length: 4K tokens
|
164 |
* GPUs: 512 H100-80G
|
@@ -182,11 +181,13 @@ A basic example of multi-GPUs supervised fine-tuning (SFT) with TRL and Accelera
|
|
182 |
## Benchmarks
|
183 |
|
184 |
We report the results for Phi-3-Mini-4K-Instruct on standard open-source benchmarks measuring the model's reasoning ability (both common sense reasoning and logical reasoning). We compare to Phi-2, Mistral-7b-v0.1, Mixtral-8x7b, Gemma 7B, Llama-3-8B-Instruct, and GPT-3.5.
|
185 |
-
|
186 |
-
These numbers might differ from other published numbers due to slightly different choices in the evaluation.
|
|
|
187 |
As is now standard, we use few-shot prompts to evaluate the models, at temperature 0.
|
188 |
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.
|
189 |
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.
|
|
|
190 |
The number of k–shot examples is listed per-benchmark.
|
191 |
|
192 |
| | Phi-3-Mini-4K-In<br>3.8b | Phi-3-Small<br>7b (preview) | Phi-3-Medium<br>14b (preview) | Phi-2<br>2.7b | Mistral<br>7b | Gemma<br>7b | Llama-3-In<br>8b | Mixtral<br>8x7b | GPT-3.5<br>version 1106 |
|
@@ -220,10 +221,13 @@ The number of k–shot examples is listed per-benchmark.
|
|
220 |
|
221 |
## Cross Platform Support
|
222 |
|
223 |
-
ONNX runtime ecosystem now supports Phi3 mini models across platforms and hardware.
|
224 |
-
|
225 |
-
|
|
|
|
|
226 |
Here are some of the optimized configurations we have added:
|
|
|
227 |
1. ONNX models for int4 DML: Quantized to int4 via AWQ
|
228 |
2. ONNX model for fp16 CUDA
|
229 |
3. ONNX model for int4 CUDA: Quantized to int4 via RTN
|
@@ -231,7 +235,7 @@ Here are some of the optimized configurations we have added:
|
|
231 |
|
232 |
## License
|
233 |
|
234 |
-
The model is licensed under the [MIT license](https://huggingface.co/microsoft/
|
235 |
|
236 |
## Trademarks
|
237 |
|
|
|
12 |
|
13 |
## Model Summary
|
14 |
|
15 |
+
Phi-3 Mini-4K-Instruct is a 3.8B parameters, lightweight, state-of-the-art open model built upon datasets used for Phi-2 - synthetic data and filtered websites - with a focus on very high-quality, reasoning dense data. The model belongs to the Phi-3 model family, and the Mini version comes in two variants [4K](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) and [128K](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) which is the context length (in tokens) it can support.
|
16 |
+
|
17 |
The model underwent a rigorous enhancement process, incorporating both supervised fine-tuning and direct preference optimization to ensure precise instruction adherence and robust safety measures.
|
18 |
When assessed against benchmarks testing common sense, language understanding, math, code, long context and logical reasoning, Phi-3 Mini-4K-Instruct showcased a robust and state-of-the-art performance among models with less than 13 billion parameters.
|
19 |
|
|
|
22 |
+ [Phi-3 Microsoft Blog](https://aka.ms/phi3blog-april)
|
23 |
+ [Phi-3 Technical Report](https://aka.ms/phi3-tech-report)
|
24 |
+ [Phi-3 on Azure AI Studio](https://aka.ms/phi3-azure-ai)
|
25 |
+
+ Phi-3 GGUF: [4K](https://aka.ms/Phi3-mini-4k-instruct-gguf)
|
26 |
+
+ Phi-3 ONNX: [4K](https://aka.ms/Phi3-mini-4k-instruct-onnx)
|
27 |
|
28 |
## Intended Uses
|
29 |
|
30 |
**Primary use cases**
|
31 |
|
32 |
+
The model is intended for commercial and research use in English. The model provides uses for applications which require:
|
33 |
+
|
34 |
1) Memory/compute constrained environments
|
35 |
2) Latency bound scenarios
|
36 |
3) Strong reasoning (especially math and logic)
|
|
|
39 |
|
40 |
**Use case considerations**
|
41 |
|
42 |
+
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.
|
43 |
+
|
44 |
Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
|
45 |
|
46 |
## How to Use
|
|
|
55 |
|
56 |
### Chat Format:
|
57 |
|
58 |
+
Given the nature of the training data, the Phi-3 Mini-4K-Instruct model is best suited for prompts using the chat format as follows. You can provide the prompt as a question:
|
59 |
|
60 |
```markdown
|
61 |
<|system|>
|
|
|
67 |
<|assistant|>
|
68 |
```
|
69 |
|
70 |
+
where the model generates the text after `<|assistant|>` . In case of few-shots prompt, the prompt can be formatted as the following:
|
71 |
|
72 |
```markdown
|
73 |
<|system|>
|
|
|
93 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
94 |
|
95 |
torch.random.manual_seed(0)
|
|
|
|
|
|
|
96 |
|
97 |
model = AutoModelForCausalLM.from_pretrained(
|
98 |
+
"microsoft/Phi-3-mini-4k-instruct",
|
99 |
device_map="cuda",
|
100 |
torch_dtype="auto",
|
101 |
trust_remote_code=True,
|
|
|
102 |
)
|
103 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-3-mini-4k-instruct")
|
|
|
104 |
|
105 |
messages = [
|
106 |
{"role": "system", "content": "You are a helpful digital assistant. Please provide safe, ethical and accurate information to the user."},
|
|
|
128 |
print(output[0]['generated_text'])
|
129 |
```
|
130 |
|
131 |
+
Note that by default the model use flash attention which requires certain types of GPU to run. If you want to run the model on:
|
132 |
+
|
133 |
+ V100 or earlier generation GPUs: call `AutoModelForCausalLM.from_pretrained()` with `attn_implementation="eager"`
|
134 |
+
+ CPU: use the **GGUF** quantized models [4K](https://aka.ms/Phi3-mini-4k-instruct-gguf)
|
135 |
+
+ Optimized inference: use the **ONNX** models [4K](https://aka.ms/Phi3-mini-4k-instruct-onnx)
|
136 |
|
137 |
## Responsible AI Considerations
|
138 |
|
139 |
+
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:
|
140 |
+
|
141 |
+ Quality of Service: the Phi models are trained primarily on English text. Languages other than English will experience worse performance. English language varieties with less representation in the training data might experience worse performance than standard American English.
|
142 |
+ Representation of Harms & Perpetuation of Stereotypes: These models can over- or under-represent groups of people, erase representation of some groups, or reinforce demeaning or negative stereotypes. Despite safety post-training, these limitations may still be present due to differing levels of representation of different groups or prevalence of examples of negative stereotypes in training data that reflect real-world patterns and societal biases.
|
143 |
+ Inappropriate or Offensive Content: these models may produce other types of inappropriate or offensive content, which may make it inappropriate to deploy for sensitive contexts without additional mitigations that are specific to the use case.
|
144 |
+ Information Reliability: Language models can generate nonsensical content or fabricate content that might sound reasonable but is inaccurate or outdated.
|
145 |
+ Limited Scope for Code: Majority of Phi-3 training data is based in Python and use common packages such as "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages or scripts in other languages, we strongly recommend users manually verify all API uses.
|
146 |
|
147 |
+
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:
|
148 |
+
|
149 |
+ Allocation: Models may not be suitable for scenarios that could have consequential impact on legal status or the allocation of resources or life opportunities (ex: housing, employment, credit, etc.) without further assessments and additional debiasing techniques.
|
150 |
+ High-Risk Scenarios: Developers should assess suitability of using models in high-risk scenarios where unfair, unreliable or offensive outputs might be extremely costly or lead to harm. This includes providing advice in sensitive or expert domains where accuracy and reliability are critical (ex: legal or health advice). Additional safeguards should be implemented at the application level according to the deployment context.
|
151 |
+ Misinformation: Models may produce inaccurate information. Developers should follow transparency best practices and inform end-users they are interacting with an AI system. At the application level, developers can build feedback mechanisms and pipelines to ground responses in use-case specific, contextual information, a technique known as Retrieval Augmented Generation (RAG).
|
|
|
157 |
|
158 |
### Model
|
159 |
|
160 |
+
* Architecture: Phi-3 Mini-4K-Instruct has 3.8B parameters and is a dense decoder-only Transformer model. The model is fine-tuned with Supervised fine-tuning (SFT) and Direct Preference Optimization (DPO) to ensure alignment with human preferences and safety guidlines.
|
161 |
* Inputs: Text. It is best suited for prompts using chat format.
|
162 |
* Context length: 4K tokens
|
163 |
* GPUs: 512 H100-80G
|
|
|
181 |
## Benchmarks
|
182 |
|
183 |
We report the results for Phi-3-Mini-4K-Instruct on standard open-source benchmarks measuring the model's reasoning ability (both common sense reasoning and logical reasoning). We compare to Phi-2, Mistral-7b-v0.1, Mixtral-8x7b, Gemma 7B, Llama-3-8B-Instruct, and GPT-3.5.
|
184 |
+
|
185 |
+
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.
|
186 |
+
|
187 |
As is now standard, we use few-shot prompts to evaluate the models, at temperature 0.
|
188 |
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.
|
189 |
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.
|
190 |
+
|
191 |
The number of k–shot examples is listed per-benchmark.
|
192 |
|
193 |
| | Phi-3-Mini-4K-In<br>3.8b | Phi-3-Small<br>7b (preview) | Phi-3-Medium<br>14b (preview) | Phi-2<br>2.7b | Mistral<br>7b | Gemma<br>7b | Llama-3-In<br>8b | Mixtral<br>8x7b | GPT-3.5<br>version 1106 |
|
|
|
221 |
|
222 |
## Cross Platform Support
|
223 |
|
224 |
+
ONNX runtime ecosystem now supports Phi3 mini models across platforms and hardware. You can find the optimized ONNX models [here](https://aka.ms/Phi3-ONNX-HF).
|
225 |
+
|
226 |
+
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 support lets developers bring hardware acceleration to Windows devices at scale across AMD, Intel, and NVIDIA GPUs.
|
227 |
+
Along with DirectML, ONNX Runtime provides cross platform support for Phi-3 across a range of devices CPU, GPU, and mobile.
|
228 |
+
|
229 |
Here are some of the optimized configurations we have added:
|
230 |
+
|
231 |
1. ONNX models for int4 DML: Quantized to int4 via AWQ
|
232 |
2. ONNX model for fp16 CUDA
|
233 |
3. ONNX model for int4 CUDA: Quantized to int4 via RTN
|
|
|
235 |
|
236 |
## License
|
237 |
|
238 |
+
The model is licensed under the [MIT license](https://huggingface.co/microsoft/Phi-3-mini-4k/resolve/main/LICENSE).
|
239 |
|
240 |
## Trademarks
|
241 |
|