paradox model
#9
by
BhargavMupparisetty
- opened
- README.md +3 -6
- config.json +6 -0
- configuration_phi4flash.py +11 -5
- data_summary_card.md +0 -149
- modeling_phi4flash.py +9 -9
README.md
CHANGED
|
@@ -21,11 +21,11 @@ Phi-4-mini-flash-reasoning is a lightweight open model built upon synthetic data
|
|
| 21 |
The model belongs to the Phi-4 model family and supports 64K token context length.
|
| 22 |
|
| 23 |
📰 [Phi-4-mini-flash-reasoning Blog](https://azure.microsoft.com/en-us/blog/reasoning-reimagined-introducing-phi-4-mini-flash-reasoning/) <br>
|
| 24 |
-
📖 [Phi-4-mini-flash-reasoning Paper](https://
|
| 25 |
📚 [Training Codebase](https://github.com/microsoft/ArchScale) <br>
|
| 26 |
👩🍳 [Phi Cookbook](https://github.com/microsoft/PhiCookBook) <br>
|
| 27 |
🏡 [Phi Portal](https://azure.microsoft.com/en-us/products/phi) <br>
|
| 28 |
-
🚀 vLLM Inference
|
| 29 |
🖥️ Try It [Azure](https://ai.azure.com/explore/models/Phi-4-mini-flash-reasoning/version/1/registry/azureml-phi-prod) [Nvidia NIM](https://build.nvidia.com/microsoft/phi-4-mini-flash-reasoning)<br>
|
| 30 |
|
| 31 |
|
|
@@ -236,7 +236,4 @@ Benchmark datasets
|
|
| 236 |
We evaluate the model with three of the most popular math benchmarks where the strongest reasoning models are competing together. Specifically:
|
| 237 |
+ Math-500: This benchmark consists of 500 challenging math problems designed to test the model's ability to perform complex mathematical reasoning and problem-solving.
|
| 238 |
+ AIME 2024/AIME 2025: The American Invitational Mathematics Examination (AIME) is a highly regarded math competition that features a series of difficult problems aimed at assessing advanced mathematical skills and logical reasoning. We evaluate the models on the problems from both 2024 and the year 2025 examinations.
|
| 239 |
-
+ GPQA Diamond: The Graduate-Level Google-Proof Q&A (GPQA) Diamond benchmark focuses on evaluating the model's ability to understand and solve a wide range of mathematical questions, including both straightforward calculations and more intricate problem-solving tasks.
|
| 240 |
-
|
| 241 |
-
## Data Summary
|
| 242 |
-
https://huggingface.co/microsoft/Phi-4-mini-flash-reasoning/blob/main/data_summary_card.md
|
|
|
|
| 21 |
The model belongs to the Phi-4 model family and supports 64K token context length.
|
| 22 |
|
| 23 |
📰 [Phi-4-mini-flash-reasoning Blog](https://azure.microsoft.com/en-us/blog/reasoning-reimagined-introducing-phi-4-mini-flash-reasoning/) <br>
|
| 24 |
+
📖 [Phi-4-mini-flash-reasoning Paper](https://aka.ms/flashreasoning-paper) | [HF Paper](https://huggingface.co/papers/2507.06607) <br>
|
| 25 |
📚 [Training Codebase](https://github.com/microsoft/ArchScale) <br>
|
| 26 |
👩🍳 [Phi Cookbook](https://github.com/microsoft/PhiCookBook) <br>
|
| 27 |
🏡 [Phi Portal](https://azure.microsoft.com/en-us/products/phi) <br>
|
| 28 |
+
🚀 [vLLM Inference](https://github.com/vllm-project/vllm/pull/20702) <br>
|
| 29 |
🖥️ Try It [Azure](https://ai.azure.com/explore/models/Phi-4-mini-flash-reasoning/version/1/registry/azureml-phi-prod) [Nvidia NIM](https://build.nvidia.com/microsoft/phi-4-mini-flash-reasoning)<br>
|
| 30 |
|
| 31 |
|
|
|
|
| 236 |
We evaluate the model with three of the most popular math benchmarks where the strongest reasoning models are competing together. Specifically:
|
| 237 |
+ Math-500: This benchmark consists of 500 challenging math problems designed to test the model's ability to perform complex mathematical reasoning and problem-solving.
|
| 238 |
+ AIME 2024/AIME 2025: The American Invitational Mathematics Examination (AIME) is a highly regarded math competition that features a series of difficult problems aimed at assessing advanced mathematical skills and logical reasoning. We evaluate the models on the problems from both 2024 and the year 2025 examinations.
|
| 239 |
+
+ GPQA Diamond: The Graduate-Level Google-Proof Q&A (GPQA) Diamond benchmark focuses on evaluating the model's ability to understand and solve a wide range of mathematical questions, including both straightforward calculations and more intricate problem-solving tasks.
|
|
|
|
|
|
|
|
|
config.json
CHANGED
|
@@ -26,6 +26,12 @@
|
|
| 26 |
"num_key_value_heads": 20,
|
| 27 |
"resid_pdrop": 0.0,
|
| 28 |
"sliding_window": 512,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
"torch_dtype": "bfloat16",
|
| 30 |
"tie_word_embeddings": true,
|
| 31 |
"transformers_version": "4.46.1",
|
|
|
|
| 26 |
"num_key_value_heads": 20,
|
| 27 |
"resid_pdrop": 0.0,
|
| 28 |
"sliding_window": 512,
|
| 29 |
+
"layer_types": [
|
| 30 |
+
"full_attention", "sliding_attention", "full_attention", "sliding_attention", "full_attention", "sliding_attention", "full_attention", "sliding_attention",
|
| 31 |
+
"full_attention", "sliding_attention", "full_attention", "sliding_attention", "full_attention", "sliding_attention", "full_attention", "sliding_attention",
|
| 32 |
+
"full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention",
|
| 33 |
+
"full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention", "full_attention"
|
| 34 |
+
],
|
| 35 |
"torch_dtype": "bfloat16",
|
| 36 |
"tie_word_embeddings": true,
|
| 37 |
"transformers_version": "4.46.1",
|
configuration_phi4flash.py
CHANGED
|
@@ -112,6 +112,7 @@ class Phi4FlashConfig(PretrainedConfig):
|
|
| 112 |
bos_token_id=1,
|
| 113 |
eos_token_id=2,
|
| 114 |
sliding_window=2047,
|
|
|
|
| 115 |
mb_per_layer= 2,
|
| 116 |
mamba_d_state=16,
|
| 117 |
mamba_d_conv=4,
|
|
@@ -141,11 +142,16 @@ class Phi4FlashConfig(PretrainedConfig):
|
|
| 141 |
self.use_cache = use_cache
|
| 142 |
self.rope_theta = rope_theta
|
| 143 |
self.mb_per_layer = mb_per_layer
|
| 144 |
-
self.sliding_window =
|
| 145 |
-
|
| 146 |
-
for layer_idx in range(num_hidden_layers)
|
| 147 |
-
]
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
self.mamba_d_state = mamba_d_state
|
| 150 |
self.mamba_d_conv = mamba_d_conv
|
| 151 |
self.mamba_expand = mamba_expand
|
|
@@ -170,4 +176,4 @@ class Phi4FlashConfig(PretrainedConfig):
|
|
| 170 |
else:
|
| 171 |
layer_block_type = "mamba"
|
| 172 |
layer_block_types.append(layer_block_type)
|
| 173 |
-
return layer_block_types
|
|
|
|
| 112 |
bos_token_id=1,
|
| 113 |
eos_token_id=2,
|
| 114 |
sliding_window=2047,
|
| 115 |
+
layer_types=None,
|
| 116 |
mb_per_layer= 2,
|
| 117 |
mamba_d_state=16,
|
| 118 |
mamba_d_conv=4,
|
|
|
|
| 142 |
self.use_cache = use_cache
|
| 143 |
self.rope_theta = rope_theta
|
| 144 |
self.mb_per_layer = mb_per_layer
|
| 145 |
+
self.sliding_window = sliding_window
|
| 146 |
+
self.layer_types = layer_types
|
|
|
|
|
|
|
| 147 |
|
| 148 |
+
if self.layer_types is None:
|
| 149 |
+
is_sliding = lambda i: i < num_hidden_layers // 2 and i % 2 == 1
|
| 150 |
+
self.layer_types = [
|
| 151 |
+
"sliding_attention" if is_sliding(layer_idx) else "full_attention"
|
| 152 |
+
for layer_idx in range(num_hidden_layers)
|
| 153 |
+
]
|
| 154 |
+
|
| 155 |
self.mamba_d_state = mamba_d_state
|
| 156 |
self.mamba_d_conv = mamba_d_conv
|
| 157 |
self.mamba_expand = mamba_expand
|
|
|
|
| 176 |
else:
|
| 177 |
layer_block_type = "mamba"
|
| 178 |
layer_block_types.append(layer_block_type)
|
| 179 |
+
return layer_block_types
|
data_summary_card.md
DELETED
|
@@ -1,149 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
# Data Summary for microsoft_Phi-4-mini-reasoning, phi-4-mini-instruct, phi-4-mini-flash-reasoning
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
## 1. General information
|
| 12 |
-
|
| 13 |
-
**1.0.1 Version of the Summary:** 1.0
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
**1.0.2 Last update:** 10-Dec-2025
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
## 1.1 Model Developer Identification
|
| 22 |
-
|
| 23 |
-
**1.1.1 Model Developer name and contact details:** Microsoft Corporation at One Microsoft Way, Redmond, WA 98052. Tel: 425-882-8080
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
## 1.2 Model Identification
|
| 28 |
-
|
| 29 |
-
**1.2.1 Versioned model name(s):** Phi-4-mini-reasoning, Phi-4-mini-instruct, Phi-4-mini-flash-reasoning
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
**1.2.2 Model release date:** 29-Apr-2025
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
## 1.3 Overall training data size and characteristics
|
| 38 |
-
|
| 39 |
-
### 1.3.1 Size of dataset and characteristics
|
| 40 |
-
|
| 41 |
-
**1.3.1.A Text training data size:** 1 billion to 10 trillion tokens
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
**1.3.1.B Text training data content:** The training data for Phi-4-mini-reasoning consists exclusively of synthetic mathematical content generated by a stronger and more advanced reasoning model, Deepseek-R1. The objective is to distill knowledge from this model. This synthetic dataset comprises over one million diverse math problems spanning multiple levels of difficulty (from middle school to Ph.D. level). For each problem in the synthetic dataset, eight distinct solutions (rollouts) were sampled, and only those verified as correct were retained.
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
**1.3.1.C Image training data size:** Not applicable. Images are not part of the training data
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
**1.3.1.D Image training data content:** Not applicable
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
**1.3.1.E Audio training data size:** Not applicable. Audio is not part of the training data
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
**1.3.1.F Audio training data content:** Not applicable
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
**1.3.1.G Video training data size:** Not applicable. Videos are not part of the training data
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
**1.3.1.H Video training data content:** Not applicable
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
**1.3.1.I Other training data size:** Not applicable
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
**1.3.1.J Other training data content:** Not applicable
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
**1.3.2 Latest date of data acquisition/collection for model training:** February 2025
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
**1.3.3 Is data collection ongoing to update the model with new data collection after deployment?** No
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
**1.3.4 Date the training dataset was first used to train the model:** February 2025
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
**1.3.5 Rationale or purpose of data selection:** Datasets consist of synthetic mathematical problems and verified solutions generated by a stronger reasoning model to distill high-quality reasoning patterns and improve math problem-solving performance across difficulty levels
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
## 2. List of data sources
|
| 98 |
-
|
| 99 |
-
### 2.1 Publicly available datasets
|
| 100 |
-
|
| 101 |
-
**2.1.1 Have you used publicly available datasets to train the model?** Yes
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
## 2.2 Private non-publicly available datasets obtained from third parties
|
| 106 |
-
|
| 107 |
-
### 2.2.1 Datasets commercially licensed by rights holders or their representatives
|
| 108 |
-
|
| 109 |
-
**2.2.1.A Have you concluded transactional commercial licensing agreement(s) with rights holder(s) or with their representatives?** Not applicable
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
### 2.2.2 Private datasets obtained from other third-parties
|
| 114 |
-
|
| 115 |
-
**2.2.2.A Have you obtained private datasets from third parties that are not licensed as described in Section 2.2.1, such as data obtained from providers of private databases, or data intermediaries?** No
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
## 2.3 Personal Information
|
| 120 |
-
|
| 121 |
-
**2.3.1 Was personal data used to train the model?** Microsoft follows all relevant laws and regulations pertaining to personal information
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
## 2.4 Synthetic data
|
| 126 |
-
|
| 127 |
-
**2.4.1 Was any synthetic AI-generated data used to train the model?** Yes
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
## 3. Data processing aspects
|
| 132 |
-
|
| 133 |
-
### 3.1 Respect of reservation of rights from text and data mining exception or limitation
|
| 134 |
-
|
| 135 |
-
**3.1.1 Does this dataset include any data protected by copyright, trademark, or patent?** Microsoft follows all required regulations and laws for processing data protected by copyright, trademark, or patent
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
## 3.2 Other information
|
| 140 |
-
|
| 141 |
-
**3.2.1 Does the dataset include information about consumer groups without revealing individual consumer identities?** Microsoft follows all required regulations and laws for protecting consumer identities
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
**3.2.2 Was the dataset cleaned or modified before model training?** Yes
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modeling_phi4flash.py
CHANGED
|
@@ -129,7 +129,7 @@ def _get_cache(
|
|
| 129 |
cache_to_check = self._cache.self_attention_cache if requires_cross_attention_cache else self._cache
|
| 130 |
|
| 131 |
if cache_implementation == "sliding_window":
|
| 132 |
-
max_cache_len = min(self.config.sliding_window
|
| 133 |
|
| 134 |
need_new_cache = (
|
| 135 |
not hasattr(self, "_cache")
|
|
@@ -243,7 +243,7 @@ class SambaYCache(Cache):
|
|
| 243 |
sliding_cache_shape = (
|
| 244 |
self.max_batch_size,
|
| 245 |
self.num_key_value_heads,
|
| 246 |
-
min(config.sliding_window
|
| 247 |
self.head_dim,
|
| 248 |
)
|
| 249 |
conv_cache_shape = (self.max_batch_size, intermediate_size, conv_kernel_size)
|
|
@@ -573,7 +573,7 @@ class SambaYFlashAttention2(SambaYAttention):
|
|
| 573 |
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 574 |
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 575 |
|
| 576 |
-
use_sliding_windows = self.config.sliding_window is not None and self.config.
|
| 577 |
|
| 578 |
if past_key_value is not None:
|
| 579 |
|
|
@@ -710,8 +710,8 @@ class SambaYFlashAttention2(SambaYAttention):
|
|
| 710 |
softmax_scale=softmax_scale,
|
| 711 |
causal=causal,
|
| 712 |
window_size=(
|
| 713 |
-
self.config.sliding_window
|
| 714 |
-
self.config.sliding_window
|
| 715 |
),
|
| 716 |
)
|
| 717 |
|
|
@@ -735,8 +735,8 @@ class SambaYFlashAttention2(SambaYAttention):
|
|
| 735 |
softmax_scale=softmax_scale,
|
| 736 |
causal=causal,
|
| 737 |
window_size=(
|
| 738 |
-
self.config.sliding_window
|
| 739 |
-
self.config.sliding_window
|
| 740 |
),
|
| 741 |
)
|
| 742 |
|
|
@@ -1085,9 +1085,9 @@ class SambaYDecoderLayer(nn.Module):
|
|
| 1085 |
residual = residual.to(torch.float32)
|
| 1086 |
self_attn_weights = None
|
| 1087 |
else:
|
| 1088 |
-
if self.config.sliding_window is not None and self.config.
|
| 1089 |
if past_key_value is not None and cache_position[0] > 0: # when decoding
|
| 1090 |
-
attention_mask = attention_mask[:, -self.config.sliding_window
|
| 1091 |
#hidden_states = self.input_layernorm2(hidden_states.to(dtype=self.input_layernorm2.weight.dtype))
|
| 1092 |
# Self Attention
|
| 1093 |
attn_outputs, self_attn_weights, yoco_key_values = self.attn(
|
|
|
|
| 129 |
cache_to_check = self._cache.self_attention_cache if requires_cross_attention_cache else self._cache
|
| 130 |
|
| 131 |
if cache_implementation == "sliding_window":
|
| 132 |
+
max_cache_len = min(self.config.sliding_window, max_cache_len)
|
| 133 |
|
| 134 |
need_new_cache = (
|
| 135 |
not hasattr(self, "_cache")
|
|
|
|
| 243 |
sliding_cache_shape = (
|
| 244 |
self.max_batch_size,
|
| 245 |
self.num_key_value_heads,
|
| 246 |
+
min(config.sliding_window, max_cache_len),
|
| 247 |
self.head_dim,
|
| 248 |
)
|
| 249 |
conv_cache_shape = (self.max_batch_size, intermediate_size, conv_kernel_size)
|
|
|
|
| 573 |
key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 574 |
value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
|
| 575 |
|
| 576 |
+
use_sliding_windows = self.config.sliding_window is not None and self.config.layer_types[self.layer_idx] == "sliding_attention"
|
| 577 |
|
| 578 |
if past_key_value is not None:
|
| 579 |
|
|
|
|
| 710 |
softmax_scale=softmax_scale,
|
| 711 |
causal=causal,
|
| 712 |
window_size=(
|
| 713 |
+
self.config.sliding_window -1,
|
| 714 |
+
self.config.sliding_window -1,
|
| 715 |
),
|
| 716 |
)
|
| 717 |
|
|
|
|
| 735 |
softmax_scale=softmax_scale,
|
| 736 |
causal=causal,
|
| 737 |
window_size=(
|
| 738 |
+
self.config.sliding_window -1,
|
| 739 |
+
self.config.sliding_window -1,
|
| 740 |
),
|
| 741 |
)
|
| 742 |
|
|
|
|
| 1085 |
residual = residual.to(torch.float32)
|
| 1086 |
self_attn_weights = None
|
| 1087 |
else:
|
| 1088 |
+
if self.config.sliding_window is not None and self.config.layer_types[self.layer_idx] == "sliding_attention" and attention_mask is not None: # efficient SDPA and no padding
|
| 1089 |
if past_key_value is not None and cache_position[0] > 0: # when decoding
|
| 1090 |
+
attention_mask = attention_mask[:, -self.config.sliding_window:]
|
| 1091 |
#hidden_states = self.input_layernorm2(hidden_states.to(dtype=self.input_layernorm2.weight.dtype))
|
| 1092 |
# Self Attention
|
| 1093 |
attn_outputs, self_attn_weights, yoco_key_values = self.attn(
|