fix(root): Use a better placement for the "Usage" section. (#4)
Browse files- fix(root): Use a better placement for the "Usage" section. (d8831a4d89f9eec97d2e10090dcd02560313b824)
README.md
CHANGED
@@ -53,6 +53,56 @@ library_name: transformers
|
|
53 |
| **Primary Use Cases** | Our model is designed to accelerate research on language models, for use as a building block for generative AI powered features. It provides uses for general purpose AI systems and applications (primarily in English) which require:<br><br>1. Memory/compute constrained environments.<br>2. Latency bound scenarios.<br>3. Reasoning and logic. |
|
54 |
| **Out-of-Scope Use Cases** | This model is designed and tested for math reasoning only. 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 fairness 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, including the model’s focus on English. Review the Responsible AI Considerations section below for further guidance when choosing a 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. |
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
## Data Overview
|
57 |
|
58 |
### Training Datasets
|
@@ -137,56 +187,6 @@ At the high-level overview of the model quality on representative benchmarks. Fo
|
|
137 |
|
138 |
Overall, Phi-4-reasoning, with only 14B parameters, performs well across a wide range of reasoning tasks, outperforming significantly larger open-weight models such as DeepSeek-R1 distilled 70B model and approaching the performance levels of full DeepSeek R1 model. We also test the models on multiple new reasoning benchmarks for algorithmic problem solving and planning, including 3SAT, TSP, and BA-Calendar. These new tasks are nominally out-of-domain for the models as the training process did not intentionally target these skills, but the models still show strong generalization to these tasks. Furthermore, when evaluating performance against standard general abilities benchmarks such as instruction following or non-reasoning tasks, we find that our new models improve significantly from Phi-4, despite the post-training being focused on reasoning skills in specific domains.
|
139 |
|
140 |
-
## Usage
|
141 |
-
|
142 |
-
### Inference Parameters
|
143 |
-
|
144 |
-
Inference is better with `temperature=0.8`, `top_p=0.95`, and `do_sample=True`. For more complex queries, set the maximum number of tokens to 32k to allow for longer chain-of-thought (CoT).
|
145 |
-
|
146 |
-
### Input Formats
|
147 |
-
|
148 |
-
Given the nature of the training data, always use ChatML template with the following system prompt for inference:
|
149 |
-
|
150 |
-
```bash
|
151 |
-
<|im_start|>system<|im_sep|>
|
152 |
-
Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} <\think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|>
|
153 |
-
<|im_start|>user<|im_sep|>
|
154 |
-
What is the derivative of x^2?<|im_end|>
|
155 |
-
<|im_start|>assistant<|im_sep|>
|
156 |
-
```
|
157 |
-
|
158 |
-
### With `transformers`
|
159 |
-
|
160 |
-
```python
|
161 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
162 |
-
|
163 |
-
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-reasoning")
|
164 |
-
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-reasoning", device_map="auto", torch_dtype="auto")
|
165 |
-
|
166 |
-
messages = [
|
167 |
-
{"role": "system", "content": "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"},
|
168 |
-
{"role": "user", "content": "What is the derivative of x^2?"},
|
169 |
-
]
|
170 |
-
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
171 |
-
|
172 |
-
outputs = model.generate(
|
173 |
-
inputs.to(model.device),
|
174 |
-
max_new_tokens=4096,
|
175 |
-
temperature=0.8,
|
176 |
-
top_p=0.95,
|
177 |
-
do_sample=True,
|
178 |
-
)
|
179 |
-
print(tokenizer.decode(outputs[0]))
|
180 |
-
```
|
181 |
-
|
182 |
-
### With `vllm`
|
183 |
-
|
184 |
-
```bash
|
185 |
-
vllm serve microsoft/Phi-4-reasoning --enable-reasoning --reasoning-parser deepseek_r1
|
186 |
-
```
|
187 |
-
|
188 |
-
*Phi-4-reasoning is also supported out-of-the-box by Ollama, llama.cpp, and any Phi-4 compatible framework.*
|
189 |
-
|
190 |
## Responsible AI Considerations
|
191 |
|
192 |
Like other language models, Phi-4-reasoning can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:
|
|
|
53 |
| **Primary Use Cases** | Our model is designed to accelerate research on language models, for use as a building block for generative AI powered features. It provides uses for general purpose AI systems and applications (primarily in English) which require:<br><br>1. Memory/compute constrained environments.<br>2. Latency bound scenarios.<br>3. Reasoning and logic. |
|
54 |
| **Out-of-Scope Use Cases** | This model is designed and tested for math reasoning only. 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 fairness 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, including the model’s focus on English. Review the Responsible AI Considerations section below for further guidance when choosing a 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. |
|
55 |
|
56 |
+
## Usage
|
57 |
+
|
58 |
+
### Inference Parameters
|
59 |
+
|
60 |
+
Inference is better with `temperature=0.8`, `top_p=0.95`, and `do_sample=True`. For more complex queries, set the maximum number of tokens to 32k to allow for longer chain-of-thought (CoT).
|
61 |
+
|
62 |
+
### Input Formats
|
63 |
+
|
64 |
+
Given the nature of the training data, always use ChatML template with the following system prompt for inference:
|
65 |
+
|
66 |
+
```bash
|
67 |
+
<|im_start|>system<|im_sep|>
|
68 |
+
Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} <\think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:<|im_end|>
|
69 |
+
<|im_start|>user<|im_sep|>
|
70 |
+
What is the derivative of x^2?<|im_end|>
|
71 |
+
<|im_start|>assistant<|im_sep|>
|
72 |
+
```
|
73 |
+
|
74 |
+
### With `transformers`
|
75 |
+
|
76 |
+
```python
|
77 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
78 |
+
|
79 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-reasoning")
|
80 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-reasoning", device_map="auto", torch_dtype="auto")
|
81 |
+
|
82 |
+
messages = [
|
83 |
+
{"role": "system", "content": "You are Phi, a language model trained by Microsoft to help users. Your role as an assistant involves thoroughly exploring questions through a systematic thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution using the specified format: <think> {Thought section} </think> {Solution section}. In the Thought section, detail your reasoning process in steps. Each step should include detailed considerations such as analysing questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The Solution section should be logical, accurate, and concise and detail necessary steps needed to reach the conclusion. Now, try to solve the following question through the above guidelines:"},
|
84 |
+
{"role": "user", "content": "What is the derivative of x^2?"},
|
85 |
+
]
|
86 |
+
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
87 |
+
|
88 |
+
outputs = model.generate(
|
89 |
+
inputs.to(model.device),
|
90 |
+
max_new_tokens=4096,
|
91 |
+
temperature=0.8,
|
92 |
+
top_p=0.95,
|
93 |
+
do_sample=True,
|
94 |
+
)
|
95 |
+
print(tokenizer.decode(outputs[0]))
|
96 |
+
```
|
97 |
+
|
98 |
+
### With `vllm`
|
99 |
+
|
100 |
+
```bash
|
101 |
+
vllm serve microsoft/Phi-4-reasoning --enable-reasoning --reasoning-parser deepseek_r1
|
102 |
+
```
|
103 |
+
|
104 |
+
*Phi-4-reasoning is also supported out-of-the-box by Ollama, llama.cpp, and any Phi-4 compatible framework.*
|
105 |
+
|
106 |
## Data Overview
|
107 |
|
108 |
### Training Datasets
|
|
|
187 |
|
188 |
Overall, Phi-4-reasoning, with only 14B parameters, performs well across a wide range of reasoning tasks, outperforming significantly larger open-weight models such as DeepSeek-R1 distilled 70B model and approaching the performance levels of full DeepSeek R1 model. We also test the models on multiple new reasoning benchmarks for algorithmic problem solving and planning, including 3SAT, TSP, and BA-Calendar. These new tasks are nominally out-of-domain for the models as the training process did not intentionally target these skills, but the models still show strong generalization to these tasks. Furthermore, when evaluating performance against standard general abilities benchmarks such as instruction following or non-reasoning tasks, we find that our new models improve significantly from Phi-4, despite the post-training being focused on reasoning skills in specific domains.
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
## Responsible AI Considerations
|
191 |
|
192 |
Like other language models, Phi-4-reasoning can potentially behave in ways that are unfair, unreliable, or offensive. Some of the limiting behaviors to be aware of include:
|