jncraton commited on
Commit
83b1658
1 Parent(s): 3200c5e

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/y45hIMNREW7w_XpHYB_0q.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
+ ```
config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|im_start|>",
3
+ "eos_token": "<|im_end|>",
4
+ "layer_norm_epsilon": 1e-05,
5
+ "multi_query_attention": true,
6
+ "quantization_bits": null,
7
+ "quantization_group_size": null,
8
+ "quantization_type": 0,
9
+ "unk_token": "<|endoftext|>"
10
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 2,
6
+ "transformers_version": "4.42.3"
7
+ }
model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:90e4f5c49948fc70ce02cd75a61423bb1af919aa3bc8c4cea65cdea052abf1c5
3
+ size 1714250691
special_tokens_map.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>"
5
+ ],
6
+ "bos_token": {
7
+ "content": "<|im_start|>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false
12
+ },
13
+ "eos_token": {
14
+ "content": "<|im_end|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "pad_token": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false
26
+ },
27
+ "unk_token": {
28
+ "content": "<|endoftext|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<|im_start|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "<|im_end|>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<repo_name>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "4": {
37
+ "content": "<reponame>",
38
+ "lstrip": false,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ },
44
+ "5": {
45
+ "content": "<file_sep>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": true
51
+ },
52
+ "6": {
53
+ "content": "<filename>",
54
+ "lstrip": false,
55
+ "normalized": false,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": true
59
+ },
60
+ "7": {
61
+ "content": "<gh_stars>",
62
+ "lstrip": false,
63
+ "normalized": false,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": true
67
+ },
68
+ "8": {
69
+ "content": "<issue_start>",
70
+ "lstrip": false,
71
+ "normalized": false,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": true
75
+ },
76
+ "9": {
77
+ "content": "<issue_comment>",
78
+ "lstrip": false,
79
+ "normalized": false,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": true
83
+ },
84
+ "10": {
85
+ "content": "<issue_closed>",
86
+ "lstrip": false,
87
+ "normalized": false,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": true
91
+ },
92
+ "11": {
93
+ "content": "<jupyter_start>",
94
+ "lstrip": false,
95
+ "normalized": false,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": true
99
+ },
100
+ "12": {
101
+ "content": "<jupyter_text>",
102
+ "lstrip": false,
103
+ "normalized": false,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": true
107
+ },
108
+ "13": {
109
+ "content": "<jupyter_code>",
110
+ "lstrip": false,
111
+ "normalized": false,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": true
115
+ },
116
+ "14": {
117
+ "content": "<jupyter_output>",
118
+ "lstrip": false,
119
+ "normalized": false,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": true
123
+ },
124
+ "15": {
125
+ "content": "<jupyter_script>",
126
+ "lstrip": false,
127
+ "normalized": false,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": true
131
+ },
132
+ "16": {
133
+ "content": "<empty_output>",
134
+ "lstrip": false,
135
+ "normalized": false,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": true
139
+ }
140
+ },
141
+ "additional_special_tokens": [
142
+ "<|im_start|>",
143
+ "<|im_end|>"
144
+ ],
145
+ "bos_token": "<|im_start|>",
146
+ "chat_template": "{% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful AI assistant named SmolLM, trained by Hugging Face<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
147
+ "clean_up_tokenization_spaces": false,
148
+ "eos_token": "<|im_end|>",
149
+ "model_max_length": 2048,
150
+ "pad_token": "<|im_end|>",
151
+ "tokenizer_class": "GPT2Tokenizer",
152
+ "unk_token": "<|endoftext|>",
153
+ "vocab_size": 49152
154
+ }
vocabulary.json ADDED
The diff for this file is too large to render. See raw diff