gugarosa commited on
Commit
ca30dd4
1 Parent(s): 98e33aa

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -30
README.md CHANGED
@@ -2,34 +2,27 @@
2
  inference: false
3
  license: other
4
  license_name: microsoft-research-license
5
- license_link: https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx
6
  language:
7
  - en
8
  pipeline_tag: text-generation
 
 
 
9
  ---
10
 
11
  ## Model Summary
12
 
13
- Phi-2 is a Transformer with **2.7 billion** parameters. It was trained using the same data sources as [phi-1.5](https://huggingface.co/microsoft/phi-1.5), augmented with a new data source that consists of various NLP synthetic texts and filtered websites (for safety and educational value). When assessed against benchmarks testing common sense, language understanding, and logical reasoning, phi-2 showcased a nearly state-of-the-art performance among models with less than 13 billion parameters.
14
 
15
  Our model hasn't been fine-tuned through reinforcement learning from human feedback. The intention behind crafting this open-source model is to provide the research community with a non-restricted small model to explore vital safety challenges, such as reducing toxicity, understanding societal biases, enhancing controllability, and more.
16
 
17
 
18
  ## Intended Uses
19
 
20
- Below are example codes to load phi-2, we support two modes of execution for the model:
21
- 1. loading in fp-16 format with flash-attention support:
22
- ```python
23
- model = AutoModelForCausalLM.from_pretrained('microsoft/phi-2', torch_dtype='auto', flash_attn=True, flash_rotary=True, fused_dense=True, trust_remote_code=True)
24
- ```
25
- 2. loading in fp-16 without flash-attention
26
- ```python
27
- model = AutoModelForCausalLM.from_pretrained('microsoft/phi-2', torch_dtype='auto', trust_remote_code=True)
28
- ```
29
 
30
- Phi-2 is intended for research purposes only. Given the nature of the training data, the phi-2 model is best suited for prompts using the QA format, the chat format, and the code format.
31
-
32
- #### QA format:
33
 
34
  You can provide the prompt as a standalone question as follows:
35
 
@@ -44,7 +37,8 @@ Output: Mathematics is like a lighthouse. Just as a lighthouse guides ships safe
44
  ```
45
  where the model generates the text after "Output:".
46
 
47
- #### Chat format:
 
48
  ```markdown
49
  Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
50
  Bob: Well, have you tried creating a study schedule and sticking to it?
@@ -55,7 +49,8 @@ Alice: ...
55
 
56
  where the model generates the text after the first "Bob:".
57
 
58
- #### Code format:
 
59
  ```python
60
  def print_prime(n):
61
  """
@@ -74,34 +69,52 @@ def print_prime(n):
74
  ```
75
  where the model generates the text after the comments.
76
 
77
-
78
- **Out of scope**
 
 
79
 
80
- * The phi-2 model is intended for research purposes. The model-generated text/code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing these models in their applications.
81
 
82
- * Direct adoption for production tasks is out of the scope of this research project. As a result, the phi-2 model has not been tested to ensure that it performs adequately for any production-level application. Please refer to the limitation sections of this document for more details.
 
 
83
 
 
84
 
85
- ## Limitations of phi-2
 
86
 
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
 
89
  * Generate Inaccurate Code and Facts: The model may produce incorrect code snippets and statements. Users should treat these outputs as suggestions or starting points, not as definitive or accurate solutions.
90
 
91
- * Limited Scope for code: Majority of phi-2 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.
92
 
93
  * Unreliable Responses to Instruction: The model has not undergone instruction fine-tuning. As a result, it may struggle or fail to adhere to intricate or nuanced instructions provided by users.
94
 
95
  * Language Limitations: The model is primarily designed to understand standard English. Informal English, slang, or any other languages might pose challenges to its comprehension, leading to potential misinterpretations or errors in response.
96
 
97
- * Potential Societal Biases: phi-2 is not entirely free from societal biases despite efforts in assuring trainig data safety. There's a possibility it may generate content that mirrors these societal biases, particularly if prompted or instructed to do so. We urge users to be aware of this and to exercise caution and critical thinking when interpreting model outputs.
98
 
99
  * Toxicity: Despite being trained with carefully selected data, the model can still produce harmful content if explicitly prompted or instructed to do so. We chose to release the model for research purposes only -- We hope to help the open-source community develop the most effective ways to reduce the toxicity of a model directly after pretraining.
100
 
101
  * Verbosity: Phi-2 being a base model often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily textbooks, which results in textbook-like responses.
102
 
103
-
104
-
105
  ## Training
106
 
107
  ### Model
@@ -118,19 +131,17 @@ where the model generates the text after the comments.
118
 
119
  * Training time: 14 days
120
 
121
-
122
-
123
  ### Software
124
 
125
  * [PyTorch](https://github.com/pytorch/pytorch)
126
 
127
  * [DeepSpeed](https://github.com/microsoft/DeepSpeed)
128
 
129
- * [flash-attention](https://github.com/HazyResearch/flash-attention) > 2.0.0
130
 
131
  ### License
132
 
133
- The model is licensed under the [microsoft-research-license](https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx).
134
 
135
  ## Trademarks
136
 
 
2
  inference: false
3
  license: other
4
  license_name: microsoft-research-license
5
+ license_link: https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE
6
  language:
7
  - en
8
  pipeline_tag: text-generation
9
+ tags:
10
+ - nlp
11
+ - code
12
  ---
13
 
14
  ## Model Summary
15
 
16
+ Phi-2 is a Transformer with **2.7 billion** parameters. It was trained using the same data sources as [Phi-1.5](https://huggingface.co/microsoft/phi-1.5), augmented with a new data source that consists of various NLP synthetic texts and filtered websites (for safety and educational value). When assessed against benchmarks testing common sense, language understanding, and logical reasoning, Phi-2 showcased a nearly state-of-the-art performance among models with less than 13 billion parameters.
17
 
18
  Our model hasn't been fine-tuned through reinforcement learning from human feedback. The intention behind crafting this open-source model is to provide the research community with a non-restricted small model to explore vital safety challenges, such as reducing toxicity, understanding societal biases, enhancing controllability, and more.
19
 
20
 
21
  ## Intended Uses
22
 
23
+ Phi-2 is intended for research purposes only. Given the nature of the training data, the Phi-2 model is best suited for prompts using the QA format, the chat format, and the code format.
 
 
 
 
 
 
 
 
24
 
25
+ ### QA Format:
 
 
26
 
27
  You can provide the prompt as a standalone question as follows:
28
 
 
37
  ```
38
  where the model generates the text after "Output:".
39
 
40
+ ### Chat Format:
41
+
42
  ```markdown
43
  Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
44
  Bob: Well, have you tried creating a study schedule and sticking to it?
 
49
 
50
  where the model generates the text after the first "Bob:".
51
 
52
+ ### Code Format:
53
+
54
  ```python
55
  def print_prime(n):
56
  """
 
69
  ```
70
  where the model generates the text after the comments.
71
 
72
+ **Notes**
73
+ * Phi-2 is intended for research purposes. The model-generated text/code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing these models in their applications.
74
+ * Direct adoption for production tasks is out of the scope of this research project. As a result, the Phi-2 model has not been tested to ensure that it performs adequately for any production-level application. Please refer to the limitation sections of this document for more details.
75
+ * If you are using `transformers>=4.36.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
76
 
77
+ ## Sample Code
78
 
79
+ ```python
80
+ import torch
81
+ from transformers import AutoModelForCausalLM, AutoTokenizer
82
 
83
+ torch.set_default_device("cuda")
84
 
85
+ model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
86
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
87
 
88
+ inputs = tokenizer('''```python
89
+ def print_prime(n):
90
+ """
91
+ Print all primes between 1 and n
92
+ """''', return_tensors="pt", return_attention_mask=False)
93
+
94
+ outputs = model.generate(**inputs, max_length=200)
95
+ text = tokenizer.batch_decode(outputs)[0]
96
+ print(text)
97
+ ```
98
+
99
+ **Remark.** In the generation function, our model currently does not support beam search (`num_beams > 1`).
100
+ Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings.
101
+
102
+ ## Limitations of Phi-2
103
 
104
  * Generate Inaccurate Code and Facts: The model may produce incorrect code snippets and statements. Users should treat these outputs as suggestions or starting points, not as definitive or accurate solutions.
105
 
106
+ * Limited Scope for code: Majority of Phi-2 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.
107
 
108
  * Unreliable Responses to Instruction: The model has not undergone instruction fine-tuning. As a result, it may struggle or fail to adhere to intricate or nuanced instructions provided by users.
109
 
110
  * Language Limitations: The model is primarily designed to understand standard English. Informal English, slang, or any other languages might pose challenges to its comprehension, leading to potential misinterpretations or errors in response.
111
 
112
+ * Potential Societal Biases: Phi-2 is not entirely free from societal biases despite efforts in assuring trainig data safety. There's a possibility it may generate content that mirrors these societal biases, particularly if prompted or instructed to do so. We urge users to be aware of this and to exercise caution and critical thinking when interpreting model outputs.
113
 
114
  * Toxicity: Despite being trained with carefully selected data, the model can still produce harmful content if explicitly prompted or instructed to do so. We chose to release the model for research purposes only -- We hope to help the open-source community develop the most effective ways to reduce the toxicity of a model directly after pretraining.
115
 
116
  * Verbosity: Phi-2 being a base model often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily textbooks, which results in textbook-like responses.
117
 
 
 
118
  ## Training
119
 
120
  ### Model
 
131
 
132
  * Training time: 14 days
133
 
 
 
134
  ### Software
135
 
136
  * [PyTorch](https://github.com/pytorch/pytorch)
137
 
138
  * [DeepSpeed](https://github.com/microsoft/DeepSpeed)
139
 
140
+ * [Flash-Attention](https://github.com/HazyResearch/flash-attention)
141
 
142
  ### License
143
 
144
+ The model is licensed under the [microsoft-research-license](https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE).
145
 
146
  ## Trademarks
147