eliebak HF staff commited on
Commit
dfc017e
1 Parent(s): a587c08

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +226 -89
README.md CHANGED
@@ -1,92 +1,229 @@
1
  ---
2
- base_model: loubnabnl/smollm2-1.7B-8k-mix7-ep2-v2
3
- tags:
4
- - alignment-handbook
5
- - trl
6
- - dpo
7
- - generated_from_trainer
8
- - trl
9
- - dpo
10
- - generated_from_trainer
11
- datasets:
12
- - HuggingFaceH4/ultrafeedback_binarized
13
- model-index:
14
- - name: smollm2-1.7B-8k-mix7-ep2-v2-dpo-ultraf-ep3
15
- results: []
16
  ---
17
 
18
- <!-- This model card has been generated automatically according to the information the Trainer had access to. You
19
- should probably proofread and complete it, then remove this comment. -->
20
-
21
- [<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="200" height="32"/>](https://wandb.ai/loubnabnl/huggingface/runs/n6jjrqmx)
22
- # smollm2-1.7B-8k-mix7-ep2-v2-dpo-ultraf-ep3
23
-
24
- This model is a fine-tuned version of [loubnabnl/smollm2-1.7B-8k-mix7-ep2-v2](https://huggingface.co/loubnabnl/smollm2-1.7B-8k-mix7-ep2-v2) on the HuggingFaceH4/ultrafeedback_binarized dataset.
25
- It achieves the following results on the evaluation set:
26
- - Loss: 0.5878
27
- - Rewards/chosen: 0.0167
28
- - Rewards/rejected: -0.5739
29
- - Rewards/accuracies: 0.6746
30
- - Rewards/margins: 0.5907
31
- - Logps/rejected: -275.4315
32
- - Logps/chosen: -310.2510
33
- - Logits/rejected: -0.3685
34
- - Logits/chosen: -0.3410
35
-
36
- ## Model description
37
-
38
- More information needed
39
-
40
- ## Intended uses & limitations
41
-
42
- More information needed
43
-
44
- ## Training and evaluation data
45
-
46
- More information needed
47
-
48
- ## Training procedure
49
-
50
- ### Training hyperparameters
51
-
52
- The following hyperparameters were used during training:
53
- - learning_rate: 1e-06
54
- - train_batch_size: 2
55
- - eval_batch_size: 4
56
- - seed: 42
57
- - distributed_type: multi-GPU
58
- - num_devices: 8
59
- - gradient_accumulation_steps: 8
60
- - total_train_batch_size: 128
61
- - total_eval_batch_size: 32
62
- - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
63
- - lr_scheduler_type: cosine
64
- - lr_scheduler_warmup_ratio: 0.1
65
- - num_epochs: 3
66
-
67
- ### Training results
68
-
69
- | Training Loss | Epoch | Step | Validation Loss | Rewards/chosen | Rewards/rejected | Rewards/accuracies | Rewards/margins | Logps/rejected | Logps/chosen | Logits/rejected | Logits/chosen |
70
- |:-------------:|:------:|:----:|:---------------:|:--------------:|:----------------:|:------------------:|:---------------:|:--------------:|:------------:|:---------------:|:-------------:|
71
- | 0.6787 | 0.2094 | 100 | 0.6967 | 0.0159 | -0.0702 | 0.5516 | 0.0861 | -274.4240 | -310.2527 | -0.3377 | -0.3141 |
72
- | 0.645 | 0.4187 | 200 | 0.6491 | -0.0498 | -0.3020 | 0.6032 | 0.2523 | -274.8876 | -310.3840 | -0.3463 | -0.3229 |
73
- | 0.6161 | 0.6281 | 300 | 0.6316 | -0.0637 | -0.4218 | 0.6825 | 0.3581 | -275.1272 | -310.4119 | -0.3552 | -0.3317 |
74
- | 0.5964 | 0.8375 | 400 | 0.6100 | -0.0166 | -0.4381 | 0.6587 | 0.4215 | -275.1597 | -310.3176 | -0.3545 | -0.3291 |
75
- | 0.5394 | 1.0468 | 500 | 0.6066 | -0.0098 | -0.4749 | 0.7103 | 0.4651 | -275.2332 | -310.3040 | -0.3576 | -0.3320 |
76
- | 0.5099 | 1.2562 | 600 | 0.6007 | -0.0192 | -0.5329 | 0.6786 | 0.5137 | -275.3493 | -310.3229 | -0.3635 | -0.3380 |
77
- | 0.5056 | 1.4656 | 700 | 0.5876 | -0.0630 | -0.5941 | 0.6905 | 0.5311 | -275.4717 | -310.4104 | -0.3672 | -0.3407 |
78
- | 0.4936 | 1.6750 | 800 | 0.5994 | -0.0296 | -0.5590 | 0.6746 | 0.5294 | -275.4016 | -310.3437 | -0.3658 | -0.3384 |
79
- | 0.4904 | 1.8843 | 900 | 0.5989 | -0.0581 | -0.6149 | 0.6944 | 0.5568 | -275.5134 | -310.4006 | -0.3705 | -0.3443 |
80
- | 0.4622 | 2.0937 | 1000 | 0.5939 | -0.0662 | -0.6068 | 0.6944 | 0.5405 | -275.4971 | -310.4169 | -0.3724 | -0.3450 |
81
- | 0.4458 | 2.3031 | 1100 | 0.5923 | -0.0536 | -0.6393 | 0.6944 | 0.5857 | -275.5622 | -310.3918 | -0.3728 | -0.3450 |
82
- | 0.4462 | 2.5124 | 1200 | 0.5894 | -0.0486 | -0.6300 | 0.7024 | 0.5814 | -275.5435 | -310.3816 | -0.3710 | -0.3432 |
83
- | 0.4312 | 2.7218 | 1300 | 0.5861 | -0.0751 | -0.6393 | 0.6667 | 0.5642 | -275.5621 | -310.4347 | -0.3724 | -0.3442 |
84
- | 0.4454 | 2.9312 | 1400 | 0.5942 | -0.0056 | -0.5970 | 0.6944 | 0.5914 | -275.4775 | -310.2956 | -0.3681 | -0.3401 |
85
-
86
-
87
- ### Framework versions
88
-
89
- - Transformers 4.42.3
90
- - Pytorch 2.1.2
91
- - Datasets 2.20.0
92
- - Tokenizers 0.19.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ language:
5
+ - en
 
 
 
 
 
 
 
 
 
 
6
  ---
7
 
8
+
9
+ # SmolLM2
10
+
11
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61c141342aac764ce1654e43/7IzejwZJ62MfRwvDYvQXY.png)
12
+
13
+ ## Table of Contents
14
+
15
+ 1. [Model Summary](#model-summary)
16
+ 2. [Evaluation](#evaluation)
17
+ 3. [Examples](#examples)
18
+ 4. [Limitations](#limitations)
19
+ 5. [Training](#training)
20
+ 6. [License](#license)
21
+ 7. [Citation](#citation)
22
+
23
+ ## Model Summary
24
+
25
+ SmolLM2 is a family of compact language models available in three size: 135M, 360M, and 1.7B parameters. They are capable of solving a wide range of tasks while being lightweight enough to run on-device.
26
+
27
+ The 1.7B variant demonstrates significant advances over its predecessor SmolLM1-1.7B, particularly in instruction following, knowledge, reasoning, and mathematics. It was trained on 11 trillion tokens using a diverse dataset combination: FineWeb-Edu, DCLM, The Stack, along with new mathematics and coding datasets that we curated and will release soon. We developed the instruct version through supervised fine-tuning (SFT) using a combination of public datasets and our own curated datasets. We then applied Direct Preference Optimization (DPO) using [UltraFeedback](https://huggingface.co/datasets/HuggingFaceH4/ultrafeedback_binarized).
28
+
29
+ The instruct model additionally supports tasks such as text rewriting, summarization and function calling thanks to datasets developed by [Argilla](https://huggingface.co/argilla) such as [Synth-APIGen-v0.1](https://huggingface.co/datasets/argilla/Synth-APIGen-v0.1).
30
+
31
+ ### How to use
32
+
33
+ ### Transformers
34
+ ```bash
35
+ pip install transformers
36
+ ```
37
+
38
+ ```python
39
+ from transformers import AutoModelForCausalLM, AutoTokenizer
40
+ checkpoint = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
41
+
42
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
43
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
44
+ # for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
45
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
46
+
47
+ messages = [{"role": "user", "content": "What is the capital of France."}]
48
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
49
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
50
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
51
+ print(tokenizer.decode(outputs[0]))
52
+ ```
53
+
54
+
55
+ ### Chat in TRL
56
+ You can also use the TRL CLI to chat with the model from the terminal:
57
+ ```bash
58
+ pip install trl
59
+ trl chat --model_name_or_path HuggingFaceTB/SmolLM2-1.7B-Instruct --device cpu
60
+ ```
61
+
62
+ ## Evaluation
63
+
64
+ In this section, we report the evaluation results of SmolLM2. All evaluations are zero-shot unless stated otherwise, and we use [lighteval](https://github.com/huggingface/lighteval) to run them.
65
+
66
+ ## Base Pre-Trained Model
67
+
68
+ | Metric | SmolLM2-1.7B | Llama-1B | Qwen2.5-1.5B | SmolLM1-1.7B |
69
+ |------------------|--------------|-------------|---------------|--------------|
70
+ | HellaSwag | **68.7** | 61.2 | 66.4 | 62.9 |
71
+ | ARC (Average) | **60.5** | 49.2 | 58.5 | 59.9 |
72
+ | PIQA | **77.6** | 74.8 | 76.1 | 76.0 |
73
+ | MMLU-Pro (MCF) | **19.4** | 11.7 | 13.7 | 10.8 |
74
+ | CommonsenseQA | **43.6** | 41.2 | 34.1 | 38.0 |
75
+ | TriviaQA | **36.7** | 28.1 | 20.9 | 22.5 |
76
+ | Winogrande | **59.4** | 57.8 | 59.3 | 54.7 |
77
+ | OpenBookQA | 42.2 | 38.4 | 40.0 | **42.4** |
78
+ | GSM8K (5-shot) | 31.0 | 7.2 | **61.3** | 5.5 |
79
+
80
+ ## Instruction Model
81
+
82
+ | Metric | SmolLM2-1.7B-Instruct | Llama-1B-Instruct | Qwen2.5-1.5B-Instruct | SmolLM1-1.7B-Instruct |
83
+ |:-----------------------------|:---------------------:|:-----------------:|:----------------------:|:----------------------:|
84
+ | IFEval (Average prompt/inst) | **56.7** | 53.5 | 47.4 | 23.1 |
85
+ | MT-Bench | 6.13 | 5.48 | **6.52** | 4.33 |
86
+ | OpenRewrite-Eval (micro_avg RougeL) | 44.9 | 39.2 | **46.9** | NaN |
87
+ | HellaSwag | **66.1** | 56.1 | 60.9 | 55.5 |
88
+ | ARC (Average) | **51.7** | 41.6 | 46.2 | 43.7 |
89
+ | PIQA | **74.4** | 72.3 | 73.2 | 71.6 |
90
+ | MMLU-Pro (MCF) | 19.3 | 12.7 | **24.2** | 11.7 |
91
+ | BBH (3-shot) | 32.2 | 27.6 | **35.3** | 25.7 |
92
+ | GSM8K (5-shot) | **48.2** | 26.8 | 42.8 | 4.62 |
93
+
94
+
95
+ ## Examples
96
+ Below are some system and instruct prompts that work well for special tasks
97
+
98
+ ### Text rewriting
99
+
100
+ ```python
101
+ system_prompt_rewrite = "You are an AI writing assistant. Your task is to rewrite the user's email to make it more professional and approachable while maintaining its main points and key message. Do not return any text other than the rewritten message."
102
+ user_prompt_rewrite = "Rewrite the message below to make it more friendly and approachable while maintaining its main points and key message. Do not add any new information or return any text other than the rewritten message\nThe message:"
103
+ messages = [{"role": "system", "content": system_prompt_rewrite}, {"role": "user", "content":f"{user_prompt_rewrite} The CI is failing after your last commit!}"]
104
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
105
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
106
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
107
+ print(tokenizer.decode(outputs[0]))
108
+ ```
109
+ ```
110
+ Hey there! I noticed that the CI isn't passing after your latest commit. Could you take a look and let me know what's going on? Thanks so much for your help!
111
+ ```
112
+
113
+ ### Summarization
114
+
115
+ ```python
116
+ system_prompt_summarize = "Provide a concise, objective summary of the input text in up to three sentences, focusing on key actions and intentions without using second or third person pronouns."
117
+ messages = [{"role": "system", "content": system_prompt_rewrite}, {"role": "user", "content": INSERT_LONG_EMAIL]
118
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
119
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
120
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
121
+ print(tokenizer.decode(outputs[0]))
122
+ ```
123
+
124
+ ### Function calling
125
+
126
+ SmolLM2-1.7B-Instruct can handle function calling, it scores 27% on the [BFCL Leaderboard](https://gorilla.cs.berkeley.edu/blogs/8_berkeley_function_calling_leaderboard.html). Here's how you can leverage it:
127
+
128
+ ```python
129
+ import json
130
+ import re
131
+ from typing import Optional
132
+
133
+ from jinja2 import Template
134
+ import torch
135
+ from transformers import AutoModelForCausalLM, AutoTokenizer
136
+ from transformers.utils import get_json_schema
137
+
138
+
139
+ system_prompt = Template("""You are an expert in composing functions. You are given a question and a set of possible functions.
140
+ Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
141
+ If none of the functions can be used, point it out and refuse to answer.
142
+ If the given question lacks the parameters required by the function, also point it out.
143
+
144
+ You have access to the following tools:
145
+ <tools>{{ tools }}</tools>
146
+
147
+ The output MUST strictly adhere to the following format, and NO other text MUST be included.
148
+ The example format is as follows. Please make sure the parameter type is correct. If no function call is needed, please make the tool calls an empty list '[]'.
149
+ <tool_call>[
150
+ {"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
151
+ ... (more tool calls as required)
152
+ ]</tool_call>""")
153
+
154
+
155
+ def prepare_messages(
156
+ query: str,
157
+ tools: Optional[dict[str, any]] = None,
158
+ history: Optional[list[dict[str, str]]] = None
159
+ ) -> list[dict[str, str]]:
160
+ """Prepare the system and user messages for the given query and tools.
161
+
162
+ Args:
163
+ query: The query to be answered.
164
+ tools: The tools available to the user. Defaults to None, in which case if a
165
+ list without content will be passed to the model.
166
+ history: Exchange of messages, including the system_prompt from
167
+ the first query. Defaults to None, the first message in a conversation.
168
+ """
169
+ if tools is None:
170
+ tools = []
171
+ if history:
172
+ messages = history.copy()
173
+ messages.append({"role": "user", "content": query})
174
+ else:
175
+ messages = [
176
+ {"role": "system", "content": system_prompt.render(tools=json.dumps(tools))},
177
+ {"role": "user", "content": query}
178
+ ]
179
+ return messages
180
+
181
+
182
+ def parse_response(text: str) -> str | dict[str, any]:
183
+ """Parses a response from the model, returning either the
184
+ parsed list with the tool calls parsed, or the
185
+ model thought or response if couldn't generate one.
186
+
187
+ Args:
188
+ text: Response from the model.
189
+ """
190
+ pattern = r"<tool_call>(.*?)</tool_call>"
191
+ matches = re.findall(pattern, text, re.DOTALL)
192
+ if matches:
193
+ return json.loads(matches[0])
194
+ return text
195
+ ```
196
+
197
+ ## Limitations
198
+
199
+ SmolLM2 models primarily understand and generate content in English. They can produce text on a variety of topics, but the generated content may not always be factually accurate, logically consistent, or free from biases present in the training data. These models should be used as assistive tools rather than definitive sources of information. Users should always verify important information and critically evaluate any generated content.
200
+
201
+ ## Training
202
+
203
+ ### Model
204
+
205
+ - **Architecture:** Transformer decoder
206
+ - **Pretraining tokens:** 11T
207
+ - **Precision:** bfloat16
208
+
209
+ ### Hardware
210
+
211
+ - **GPUs:** 256 H100
212
+
213
+ ### Software
214
+
215
+ - **Training Framework:** [nanotron](https://github.com/huggingface/nanotron/tree/main)
216
+ - **Alignement Handbook** [alignement-handbook](https://github.com/huggingface/alignment-handbook/)
217
+
218
+ ## License
219
+
220
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
221
+
222
+ ## Citation
223
+ ```bash
224
+ @misc{allal2024SmolLM2,
225
+ title={SmolLM2 - with great data, comes great performance},
226
+ author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Gabriel Martín Blázquez and Lewis Tunstall and Agustín Piqueres and Andres Marafioti and Cyril Zakka and Leandro von Werra and Thomas Wolf},
227
+ year={2024},
228
+ }
229
+ ```