alexmarques commited on
Commit
da16282
·
verified ·
1 Parent(s): ded1434

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +208 -0
README.md ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: llama3.1
4
+ base_model: RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4
5
+ datasets:
6
+ - trl-lib/tldr
7
+ ---
8
+
9
+ # Llama-3.1-8B-tldr-FP8-dynamic
10
+
11
+ ## Model Overview
12
+ - **Model Architecture:** LlamaForCausalLM
13
+ - **Input:** Text
14
+ - **Output:** Text
15
+ - **Model Optimizations:**
16
+ - **Sparsity:** 2:4
17
+ - **Weight quantization:** FP8
18
+ - **Activation quantization:** FP8
19
+ - **Release Date:** 06/04/2025
20
+ - **Version:** 1.0
21
+ - **Intended Use Cases:** This model is finetuned to summarize text in the style of Reddit posts.
22
+ - **Out-of-scope:** Use in any manner that violates applicable laws or regulations (including trade compliance laws). Use in any other way that is prohibited by the Acceptable Use Policy and Llama 3.1 Community License.
23
+ - **Model Developers:** Red Hat (Neural Magic)
24
+
25
+ This model is a quantized version of [RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4](https://huggingface.co/RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4), which is fine-tuned on the [trl-lib/tldr](https://huggingface.co/datasets/trl-lib/tldr) dataset.
26
+ This sparse model recovers 100% of the BERTScore (0.366) obtained by the dense model [RedHatAI/Llama-3.1-8B-tldr](https://huggingface.co/RedHatAI/Llama-3.1-8B-tldr).
27
+
28
+
29
+ ## Deployment
30
+
31
+ This model can be deployed efficiently using [vLLM](https://docs.vllm.ai/en/latest/), as shown in the example below.
32
+
33
+ Run the following command to start the vLLM server:
34
+ ```bash
35
+ vllm serve RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic
36
+ ```
37
+
38
+ Once your server is started, you can query the model using the OpenAI API:
39
+
40
+ ```python
41
+ from openai import OpenAI
42
+
43
+ # Modify OpenAI's API key and API base to use vLLM's API server.
44
+ openai_api_key = "EMPTY"
45
+ openai_api_base = "http://localhost:8000/v1"
46
+ client = OpenAI(
47
+ api_key=openai_api_key,
48
+ base_url=openai_api_base,
49
+ )
50
+
51
+ post="""
52
+ SUBREDDIT: r/AI
53
+
54
+ TITLE: Training sparse LLMs
55
+
56
+ POST: Now you can use the llm-compressor integration to axolotl to train sparse LLMs!
57
+
58
+ It's super easy to use. See the example in https://huggingface.co/RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4.
59
+
60
+ And there's more. You can run 2:4 sparse models on vLLM and get significant speedupts on Hopper GPUs!
61
+ """
62
+
63
+ prompt = f"Give a TL;DR of the following Reddit post.\n<|user|>{post}\nTL;DR:\n<|assistant|>\n"
64
+
65
+ completion = client.completions.create(
66
+ model="RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic",
67
+ prompt=prompt,
68
+ max_tokens=256,
69
+ )
70
+ print("Completion result:", completion)
71
+ ```
72
+
73
+ ## Quantization
74
+
75
+ <details><summary>Quantization details</summary>
76
+
77
+ This model was created by applying [llm-compressor](https://github.com/vllm-project/llm-compressor), as presented in the code snipet below.
78
+
79
+ ```python
80
+ from transformers import AutoTokenizer, AutoModelForCausalLM
81
+ from llmcompressor.transformers import oneshot
82
+ from llmcompressor.modifiers.quantization import QuantizationModifier
83
+
84
+ recipe = QuantizationModifier(targets="Linear", scheme="FP8_DYNAMIC", ignore=["lm_head"])
85
+
86
+ model_stub = "RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4"
87
+ model_name = model_stub.split("/")[-1]
88
+
89
+ model = AutoModelForCausalLM.from_pretrained(
90
+ model_stub, torch_dtype="auto", device_map="auto"
91
+ )
92
+
93
+ output_dir = f"./{model_name}-FP8-dynamic"
94
+
95
+ oneshot(
96
+ model=model,
97
+ recipe=recipe,
98
+ output_dir=output_dir,
99
+ tokenizer=AutoTokenizer.from_pretrained(model_stub),
100
+ )
101
+
102
+ model.save_pretrained(output_dir, save_compressed=True, skip_sparsity_compression_stats=False)
103
+ tokenizer.save_pretrained(output_dir)
104
+ ```
105
+ </details>
106
+
107
+
108
+ ## Evaluation
109
+
110
+ The model was evaluated on the test split of [trl-lib/tldr](https://huggingface.co/datasets/trl-lib/tldr) using the Neural Magic fork of [lm-evaluation-harness](https://github.com/neuralmagic/lm-evaluation-harness/tree/tldr) (tldr branch).
111
+ One can reproduce these results by using the following command:
112
+
113
+ ```bash
114
+ lm_eval --model vllm --model_args "pretrained=RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic,dtype=auto,add_bos_token" --batch-size auto --tasks tldr
115
+ ```
116
+
117
+ <table>
118
+ <tr>
119
+ <th>Metric
120
+ </th>
121
+ <th>Llama-3.1-8B-Instruct
122
+ </th>
123
+ <th>Llama-3.1-8B-tldr
124
+ </th>
125
+ <th>Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic<br>(this model)
126
+ </th>
127
+ </tr>
128
+ <tr>
129
+ <td>BERTScore
130
+ </td>
131
+ <td>-0.230
132
+ </td>
133
+ <td>0.366
134
+ </td>
135
+ <td>0.366
136
+ </td>
137
+ </tr>
138
+ <tr>
139
+ <td>ROUGE-1
140
+ </td>
141
+ <td>0.059
142
+ </td>
143
+ <td>0.362
144
+ </td>
145
+ <td>0.354
146
+ </td>
147
+ </tr>
148
+ <tr>
149
+ <td>ROUGE-2
150
+ </td>
151
+ <td>0.018
152
+ </td>
153
+ <td>0.144
154
+ </td>
155
+ <td>0.140
156
+ </td>
157
+ </tr>
158
+ <tr>
159
+ <td>ROUGE-Lsum
160
+ </td>
161
+ <td>0.051
162
+ </td>
163
+ <td>0.306
164
+ </td>
165
+ <td>0.302
166
+ </td>
167
+ </tr>
168
+ </table>
169
+
170
+ ## Inference Performance
171
+
172
+ We evaluated the inference performance of this model using the first 1,000 samples from the training set of the [trl-lib/tldr](https://huggingface.co/datasets/trl-lib/tldr) dataset.
173
+ Benchmarking was conducted with [vLLM](https://docs.vllm.ai/en/latest/) version `0.9.0.1` and [GuideLLM](https://github.com/neuralmagic/guidellm) version `0.2.1`.
174
+
175
+ The figure below presents the **mean end-to-end latency per request** across varying request rates.
176
+ Results are shown for this model, as well as two variants:
177
+ - **Dense:** [Llama-3.1-8B-tldr](https://huggingface.co/RedHatAI/Llama-3.1-8B-tldr)
178
+ - **Dense-quantized:** [Llama-3.1-8B-tldr-FP8-dynamic](https://huggingface.co/RedHatAI/Llama-3.1-8B-tldr-FP8-dynamic)
179
+
180
+ ![Latency](./inference_performance/latency.png)
181
+
182
+
183
+ <details><summary><strong>Reproduction instructions</strong></summary>
184
+
185
+ To replicate the benchmark:
186
+
187
+ 1. Generate a JSON file containing the first 1,000 training samples:
188
+ ```python
189
+ from datasets import load_dataset
190
+ ds = load_dataset("trl-lib/tldr", split="train").take(1000)
191
+ ds.to_json("tldr_1000.json")
192
+ ```
193
+
194
+ 2. Start a vLLM server using your target model:
195
+ ```bash
196
+ vllm serve RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic
197
+ ```
198
+
199
+ 3. Run the benchmark with GuideLLM:
200
+ ```
201
+ GUIDELLM__OPENAI__MAX_OUTPUT_TOKENS=128 guidellm benchmark --target "http://localhost:8000" --rate-type sweep --data tldr_1000.json
202
+ ```
203
+ > The average output length is approximately 30 tokens per sample. We capped the generation at 128 tokens to reduce performance skew from rare, unusually verbose completions.
204
+
205
+ </details>
206
+
207
+
208
+