alexmarques commited on
Commit
4df0b9c
·
verified ·
1 Parent(s): 9891725

Create README.md

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