Files changed (1) hide show
  1. README.md +225 -0
README.md ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ license_link: https://huggingface.co/microsoft/phi-4/resolve/main/LICENSE
4
+ language:
5
+ - en
6
+ pipeline_tag: text-generation
7
+ base_model: microsoft/phi-4
8
+ tags:
9
+ - phi
10
+ - nlp
11
+ - math
12
+ - code
13
+ - chat
14
+ - conversational
15
+ - neuralmagic
16
+ - redhat
17
+ - llmcompressor
18
+ - quantized
19
+ - int4
20
+ ---
21
+
22
+ # phi-4-FP8-dynamic
23
+
24
+ ## Model Overview
25
+ - **Model Architecture:** Phi3ForCausalLM
26
+ - **Input:** Text
27
+ - **Output:** Text
28
+ - **Model Optimizations:**
29
+ - **Activation quantization:** FP8
30
+ - **Weight quantization:** FP8
31
+ - **Intended Use Cases:** This 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:
32
+ 1. Memory/compute constrained environments.
33
+ 2. Latency bound scenarios.
34
+ 3. Reasoning and logic.
35
+ - **Out-of-scope:** This model is not specifically designed or evaluated for all downstream purposes, thus:
36
+ 1. 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.
37
+ 2. 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.
38
+ 3. Nothing contained in this Model Card should be interpreted as or deemed a restriction or modification to the license the model is released under.
39
+ - **Release Date:** 03/03/2025
40
+ - **Version:** 1.0
41
+ - **Model Developers:** RedHat (Neural Magic)
42
+
43
+
44
+ ### Model Optimizations
45
+
46
+ This model was obtained by quantizing activations and weights of [phi-4](https://huggingface.co/microsoft/phi-4) to FP8 data type.
47
+ This optimization reduces the number of bits per parameter from 16 to 8, reducing the disk size and GPU memory requirements by approximately 50%.
48
+
49
+ Only weights and activations of the linear operators within transformers blocks are quantized.
50
+ Symmetric per-tensor quantization is applied.
51
+ Activations are quantized with per-token dynamic scales.
52
+ Compressed model generated with the [llm-compressor](https://github.com/vllm-project/llm-compressor) library.
53
+
54
+
55
+ ## Deployment
56
+
57
+ This model can be deployed efficiently using the [vLLM](https://docs.vllm.ai/en/latest/) backend, as shown in the example below.
58
+
59
+ ```python
60
+ from vllm import LLM, SamplingParams
61
+ from transformers import AutoTokenizer
62
+
63
+ model_id = "neuralmagic-ent/phi-4-FP8-dynamic"
64
+ number_gpus = 1
65
+
66
+ sampling_params = SamplingParams(temperature=0.7, top_p=0.8, max_tokens=256)
67
+
68
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
69
+
70
+ prompt = "Give me a short introduction to large language model."
71
+
72
+ llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
73
+
74
+ outputs = llm.generate(prompt, sampling_params)
75
+
76
+ generated_text = outputs[0].outputs[0].text
77
+ print(generated_text)
78
+ ```
79
+
80
+ vLLM aslo supports OpenAI-compatible serving. See the [documentation](https://docs.vllm.ai/en/latest/) for more details.
81
+
82
+ ## Creation
83
+
84
+ <details>
85
+ <summary>Creation details</summary>
86
+ This model was created with [llm-compressor](https://github.com/vllm-project/llm-compressor) by running the code snippet below.
87
+
88
+
89
+ ```python
90
+ from transformers import AutoModelForCausalLM, AutoTokenizer
91
+ from llmcompressor.modifiers.quantization import Quantization
92
+ from llmcompressor.transformers import oneshot
93
+
94
+ # Load model
95
+ model_stub = "microsoft/phi-4"
96
+ model_name = model_stub.split("/")[-1]
97
+
98
+
99
+ model = AutoModelForCausalLM.from_pretrained(
100
+ model_stub,
101
+ device_map="auto",
102
+ torch_dtype="auto",
103
+ )
104
+
105
+ # Configure the quantization algorithm and scheme
106
+ recipe = QuantizationModifier(
107
+ targets="Linear",
108
+ scheme="FP8_dynamic",
109
+ ignore=["lm_head"],
110
+ dampening_frac=0.01,
111
+ )
112
+
113
+ # Apply quantization
114
+ oneshot(
115
+ model=model,
116
+ recipe=recipe,
117
+ )
118
+
119
+ # Save to disk in compressed-tensors format
120
+ save_path = model_name + "-FP8-dynamic"
121
+ model.save_pretrained(save_path)
122
+ tokenizer.save_pretrained(save_path)
123
+ print(f"Model and tokenizer saved to: {save_path}")
124
+ ```
125
+ </details>
126
+
127
+
128
+
129
+ ## Evaluation
130
+
131
+ The model was evaluated on the OpenLLM leaderboard tasks (version 1) with the [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) and the [vLLM](https://docs.vllm.ai/en/stable/) engine, using the following command:
132
+ ```
133
+ lm_eval \
134
+ --model vllm \
135
+ --model_args pretrained="neuralmagic-ent/phi-4-FP8-dynamic",dtype=auto,gpu_memory_utilization=0.6,max_model_len=4096,enable_chunk_prefill=True,tensor_parallel_size=1 \
136
+ --tasks openllm \
137
+ --batch_size auto
138
+ ```
139
+
140
+ ### Accuracy
141
+
142
+ #### Open LLM Leaderboard evaluation scores
143
+ <table>
144
+ <tr>
145
+ <td><strong>Benchmark</strong>
146
+ </td>
147
+ <td><strong>phi-4</strong>
148
+ </td>
149
+ <td><strong>phi-4-FP8-dynamic<br>(this model)</strong>
150
+ </td>
151
+ <td><strong>Recovery</strong>
152
+ </td>
153
+ </tr>
154
+ <tr>
155
+ <td>MMLU (5-shot)
156
+ </td>
157
+ <td>80.30
158
+ </td>
159
+ <td>80.30
160
+ </td>
161
+ <td>100.0%
162
+ </td>
163
+ </tr>
164
+ <tr>
165
+ <td>ARC Challenge (25-shot)
166
+ </td>
167
+ <td>64.42
168
+ </td>
169
+ <td>64.25
170
+ </td>
171
+ <td>99.7%
172
+ </td>
173
+ </tr>
174
+ <tr>
175
+ <td>GSM-8K (5-shot, strict-match)
176
+ </td>
177
+ <td>90.07
178
+ </td>
179
+ <td>90.67
180
+ </td>
181
+ <td>100.7%
182
+ </td>
183
+ </tr>
184
+ <tr>
185
+ <td>Hellaswag (10-shot)
186
+ </td>
187
+ <td>84.37
188
+ </td>
189
+ <td>84.19
190
+ </td>
191
+ <td>99.8%
192
+ </td>
193
+ </tr>
194
+ <tr>
195
+ <td>Winogrande (5-shot)
196
+ </td>
197
+ <td>80.58
198
+ </td>
199
+ <td>79.87
200
+ </td>
201
+ <td>99.1%
202
+ </td>
203
+ </tr>
204
+ <tr>
205
+ <td>TruthfulQA (0-shot, mc2)
206
+ </td>
207
+ <td>59.37
208
+ </td>
209
+ <td>59.54
210
+ </td>
211
+ <td>100.3%
212
+ </td>
213
+ </tr>
214
+ <tr>
215
+ <td><strong>Average</strong>
216
+ </td>
217
+ <td><strong>76.52</strong>
218
+ </td>
219
+ <td><strong>76.47</strong>
220
+ </td>
221
+ <td><strong>99.9%</strong>
222
+ </td>
223
+ </tr>
224
+ </table>
225
+