File size: 7,863 Bytes
fd5bb20
 
 
 
 
 
 
 
 
 
 
bdd2d12
 
 
 
 
 
 
 
 
 
 
 
 
298b333
4882776
 
bdd2d12
 
 
 
 
 
 
708acde
bdd2d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
708acde
bdd2d12
 
 
 
 
 
 
708acde
bdd2d12
 
 
 
 
 
 
 
fd5bb20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd2d12
fd5bb20
bdd2d12
fd5bb20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd2d12
 
 
fd5bb20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bdd2d12
fd5bb20
bdd2d12
fd5bb20
 
 
 
 
bdd2d12
 
 
 
 
298b333
bdd2d12
 
 
c1e1cdc
bdd2d12
 
 
 
 
 
 
 
4882776
bdd2d12
4882776
bdd2d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298b333
 
 
 
 
3223dd8
298b333
33db5cc
708acde
298b333
 
 
 
 
 
 
 
 
 
 
 
 
b50158e
298b333
 
 
708acde
298b333
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
---
library_name: transformers
license: llama3.1
base_model: meta-llama/Llama-3.1-8B
tags:
- generated_from_trainer
datasets:
- trl-lib/tldr
---

[<img src="https://raw.githubusercontent.com/axolotl-ai-cloud/axolotl/main/image/axolotl-badge-web.png" alt="Built with Axolotl" width="200" height="32"/>](https://github.com/axolotl-ai-cloud/axolotl)

# Llama-3.1-8B-tldr

## Model Overview
- **Model Architecture:** LlamaForCausalLM
  - **Input:** Text
  - **Output:** Text
- **Release Date:** 05/29/2025
- **Version:** 1.0
- **Intended Use Cases:** This model is finetuned to summarize text in the style of Reddit posts.
- **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.
- **Model Developers:** Red Hat (Neural Magic)

This model is a fine-tuned version of [meta-llama/Llama-3.1-8B](https://huggingface.co/meta-llama/Llama-3.1-8B) on the [trl-lib/tldr](https://huggingface.co/datasets/trl-lib/tldr) dataset.
This model obtains 0.366 BERTScore on the test set of trl-lib/tldr.


## Deployment

This model can be deployed efficiently using [vLLM](https://docs.vllm.ai/en/latest/), as shown in the example below.

Run the following command to start the vLLM server:
```bash
vllm serve RedHatAI/Llama-3.1-8B-tldr
```

Once your server is started, you can query the model using the OpenAI API:

```python
from openai import OpenAI

openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

post="""
SUBREDDIT: r/AI

TITLE: Training sparse LLMs

POST: Now you can use the llm-compressor integration to axolotl to train sparse LLMs!

It's super easy to use. See the example in https://huggingface.co/RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4.

And there's more. You can run 2:4 sparse models on vLLM and get significant speedupts on Hopper GPUs!
"""

prompt = f"Give a TL;DR of the following Reddit post.\n<|user|>{post}\nTL;DR:\n<|assistant|>\n"

completion = client.completions.create(
  model="RedHatAI/Llama-3.1-8B-tldr",
  prompt=prompt,
  max_tokens=256,
)
print("Completion result:", completion)
```

## Training

<details><summary>See axolotl config</summary>

axolotl version: `0.10.0.dev0`
```yaml
base_model: meta-llama/Llama-3.1-8B

load_in_8bit: false
load_in_4bit: false
strict: false

datasets:
  - path: trl-lib/tldr
    type:
      system_prompt: "Give a TL;DR of the following Reddit post."
      field_system: system
      field_instruction: prompt
      field_output: completion
      format: "<|user|>\n{instruction}\n<|assistant|>\n"
      no_input_format: "<|user|>\n{instruction}\n<|assistant|>\n"
    split: train

sequence_len: 4096
sample_packing: true
pad_to_sequence_len: true
eval_sample_packing: true

torch.compile: true
gradient_accumulation_steps: 1
micro_batch_size: 4
num_epochs: 3
optimizer: adamw_bnb_8bit
lr_scheduler: cosine
learning_rate: 1e-5
max_grad_norm: 1

gradient_checkpointing: true
gradient_checkpointing_kwargs:
  use_reentrant: false

train_on_inputs: false
bf16: auto
fp16:
tf32: false

early_stopping_patience:
resume_from_checkpoint:
logging_steps: 1
flash_attention: true

warmup_ratio: 0.05
evals_per_epoch: 4
val_set_size: 0.05
save_strategy: "best"
save_total_limit: 1
metric_for_best_model: "loss"

debug:
deepspeed:
weight_decay: 0.0
special_tokens:
  pad_token: "<|end_of_text|>"

seed: 0

plugins:
  - axolotl.integrations.liger.LigerPlugin

liger_rope: true
liger_rms_norm: true
liger_glu_activation: true
liger_layer_norm: true
liger_fused_linear_cross_entropy: true
```

</details><br>

## Training

<details><summary>Training hyperparameters</summary>

The following hyperparameters were used during training:
- learning_rate: 1e-05
- train_batch_size: 4
- eval_batch_size: 4
- seed: 0
- distributed_type: multi-GPU
- num_devices: 8
- total_train_batch_size: 32
- total_eval_batch_size: 32
- optimizer: Use adamw_bnb_8bit with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: cosine
- lr_scheduler_warmup_steps: 49
- num_epochs: 3.0

</details><br>

<details><summary>Training results</summary>

| Training Loss | Epoch  | Step | Validation Loss |
|:-------------:|:------:|:----:|:---------------:|
| 2.2572        | 0.0031 | 1    | 2.2288          |
| 1.7865        | 0.2508 | 82   | 1.7680          |
| 1.7257        | 0.5015 | 164  | 1.7567          |
| 1.7343        | 0.7523 | 246  | 1.7489          |
| 1.7688        | 1.0031 | 328  | 1.7441          |
| 1.6822        | 1.2538 | 410  | 1.7493          |
| 1.6085        | 1.5046 | 492  | 1.7480          |
| 1.6627        | 1.7554 | 574  | 1.7444          |
| 1.729         | 2.0061 | 656  | 1.7426          |
| 1.6149        | 2.2569 | 738  | 1.7540          |
| 1.6002        | 2.5076 | 820  | 1.7537          |
| 1.6573        | 2.7584 | 902  | 1.7526          |

</details><br>

<details><summary>Framework versions</summary>

- Transformers 4.51.3
- Pytorch 2.7.0+cu126
- Datasets 3.5.1
- Tokenizers 0.21.1

</details><br>

## Evaluation

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).
One can reproduce these results by using the following command:

```bash
lm_eval --model vllm --model_args "pretrained=RedHatAI/Llama-3.1-8B-tldr,dtype=auto,add_bos_token=True" --batch-size auto --tasks tldr
```

<table>
  <tr>
   <th>Metric
   </th>
   <th>Llama-3.1-8B-Instruct
   </th>
   <th>Llama-3.1-8B-tldr
   </th>
   <th>Sparse-Llama-3.1-8B-tldr-2of4<br>(this model)
   </th>
  </tr>
  <tr>
   <td>BERTScore
   </td>
   <td>-0.230
   </td>
   <td>0.366
   </td>
   <td>0.366
   </td>
  </tr>
  <tr>
   <td>ROUGE-1
   </td>
   <td>0.059
   </td>
   <td>0.362
   </td>
   <td>0.357
   </td>
  </tr>
  <tr>
   <td>ROUGE-2
   </td>
   <td>0.018
   </td>
   <td>0.144
   </td>
   <td>0.141
   </td>
  </tr>
  <tr>
   <td>ROUGE-Lsum
   </td>
   <td>0.051
   </td>
   <td>0.306
   </td>
   <td>0.304
   </td>
  </tr>
</table>

## Inference Performance

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.
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`.

The figure below presents the **mean end-to-end latency per request** across varying request rates.
Results are shown for this model, as well as two variants:
- **Dense-quantized:** [Llama-3.1-8B-tldr-FP8-dynamic](https://huggingface.co/RedHatAI/Llama-3.1-8B-tldr-FP8-dynamic)
- **Sparse-quantized:** [Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic](https://huggingface.co/RedHatAI/Sparse-Llama-3.1-8B-tldr-2of4-FP8-dynamic)

![Latency](./inference_performance/latency.png)


<details><summary><strong>Reproduction instructions</strong></summary>

To replicate the benchmark:

1. Generate a JSON file containing the first 1,000 training samples:
```python
from datasets import load_dataset
ds = load_dataset("trl-lib/tldr", split="train").take(1000)
ds.to_json("tldr_1000.json")
```

2. Start a vLLM server using your target model:
```bash
vllm serve RedHatAI/Llama-3.1-8B-tldr
```

3. Run the benchmark with GuideLLM:
```
GUIDELLM__OPENAI__MAX_OUTPUT_TOKENS=128 guidellm benchmark --target "http://localhost:8000" --rate-type sweep --data tldr_1000.json
```
> 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.

</details>