aashish1904 commited on
Commit
49ea989
·
verified ·
1 Parent(s): 3c74f34

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +241 -0
README.md ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+
4
+ library_name: transformers
5
+ license: apache-2.0
6
+ language:
7
+ - en
8
+
9
+ ---
10
+
11
+ [![QuantFactory Banner](https://lh7-rt.googleusercontent.com/docsz/AD_4nXeiuCm7c8lEwEJuRey9kiVZsRn2W-b4pWlu3-X534V3YmVuVc2ZL-NXg2RkzSOOS2JXGHutDuyyNAUtdJI65jGTo8jT9Y99tMi4H4MqL44Uc5QKG77B0d6-JfIkZHFaUA71-RtjyYZWVIhqsNZcx8-OMaA?key=xt3VSDoCbmTY7o-cwwOFwQ)](https://hf.co/QuantFactory)
12
+
13
+
14
+ # QuantFactory/SmolLM2-1.7B-Instruct-GGUF
15
+ This is quantized version of [HuggingFaceTB/SmolLM2-1.7B-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct) created using llama.cpp
16
+
17
+ # Original Model Card
18
+
19
+
20
+
21
+ # SmolLM2
22
+
23
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61c141342aac764ce1654e43/y45hIMNREW7w_XpHYB_0q.png)
24
+
25
+ ## Table of Contents
26
+
27
+ 1. [Model Summary](#model-summary)
28
+ 2. [Evaluation](#evaluation)
29
+ 3. [Examples](#examples)
30
+ 4. [Limitations](#limitations)
31
+ 5. [Training](#training)
32
+ 6. [License](#license)
33
+ 7. [Citation](#citation)
34
+
35
+ ## Model Summary
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ 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).
42
+
43
+ ### How to use
44
+
45
+ ### Transformers
46
+ ```bash
47
+ pip install transformers
48
+ ```
49
+
50
+ ```python
51
+ from transformers import AutoModelForCausalLM, AutoTokenizer
52
+ checkpoint = "HuggingFaceTB/SmolLM2-1.7B-Instruct"
53
+
54
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
55
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
56
+ # for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
57
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
58
+
59
+ messages = [{"role": "user", "content": "What is the capital of France."}]
60
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
61
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
62
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
63
+ print(tokenizer.decode(outputs[0]))
64
+ ```
65
+
66
+
67
+ ### Chat in TRL
68
+ You can also use the TRL CLI to chat with the model from the terminal:
69
+ ```bash
70
+ pip install trl
71
+ trl chat --model_name_or_path HuggingFaceTB/SmolLM2-1.7B-Instruct --device cpu
72
+ ```
73
+
74
+ ## Evaluation
75
+
76
+ 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.
77
+
78
+ ## Base Pre-Trained Model
79
+
80
+ | Metric | SmolLM2-1.7B | Llama-1B | Qwen2.5-1.5B | SmolLM1-1.7B |
81
+ |------------------|--------------|-------------|---------------|--------------|
82
+ | HellaSwag | **68.7** | 61.2 | 66.4 | 62.9 |
83
+ | ARC (Average) | **60.5** | 49.2 | 58.5 | 59.9 |
84
+ | PIQA | **77.6** | 74.8 | 76.1 | 76.0 |
85
+ | MMLU-Pro (MCF) | **19.4** | 11.7 | 13.7 | 10.8 |
86
+ | CommonsenseQA | **43.6** | 41.2 | 34.1 | 38.0 |
87
+ | TriviaQA | **36.7** | 28.1 | 20.9 | 22.5 |
88
+ | Winogrande | **59.4** | 57.8 | 59.3 | 54.7 |
89
+ | OpenBookQA | 42.2 | 38.4 | 40.0 | **42.4** |
90
+ | GSM8K (5-shot) | 31.0 | 7.2 | **61.3** | 5.5 |
91
+
92
+ ## Instruction Model
93
+
94
+ | Metric | SmolLM2-1.7B-Instruct | Llama-1B-Instruct | Qwen2.5-1.5B-Instruct | SmolLM1-1.7B-Instruct |
95
+ |:-----------------------------|:---------------------:|:-----------------:|:----------------------:|:----------------------:|
96
+ | IFEval (Average prompt/inst) | **56.7** | 53.5 | 47.4 | 23.1 |
97
+ | MT-Bench | 6.13 | 5.48 | **6.52** | 4.33 |
98
+ | OpenRewrite-Eval (micro_avg RougeL) | 44.9 | 39.2 | **46.9** | NaN |
99
+ | HellaSwag | **66.1** | 56.1 | 60.9 | 55.5 |
100
+ | ARC (Average) | **51.7** | 41.6 | 46.2 | 43.7 |
101
+ | PIQA | **74.4** | 72.3 | 73.2 | 71.6 |
102
+ | MMLU-Pro (MCF) | 19.3 | 12.7 | **24.2** | 11.7 |
103
+ | BBH (3-shot) | 32.2 | 27.6 | **35.3** | 25.7 |
104
+ | GSM8K (5-shot) | **48.2** | 26.8 | 42.8 | 4.62 |
105
+
106
+
107
+ ## Examples
108
+ Below are some system and instruct prompts that work well for special tasks
109
+
110
+ ### Text rewriting
111
+
112
+ ```python
113
+ 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."
114
+ 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:"
115
+ messages = [{"role": "system", "content": system_prompt_rewrite}, {"role": "user", "content":f"{user_prompt_rewrite} The CI is failing after your last commit!}"]
116
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
117
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
118
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
119
+ print(tokenizer.decode(outputs[0]))
120
+ ```
121
+ ```
122
+ 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!
123
+ ```
124
+
125
+ ### Summarization
126
+
127
+ ```python
128
+ 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."
129
+ messages = [{"role": "system", "content": system_prompt_rewrite}, {"role": "user", "content": INSERT_LONG_EMAIL]
130
+ input_text=tokenizer.apply_chat_template(messages, tokenize=False)
131
+ inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
132
+ outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
133
+ print(tokenizer.decode(outputs[0]))
134
+ ```
135
+
136
+ ### Function calling
137
+
138
+ 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:
139
+
140
+ ```python
141
+ import json
142
+ import re
143
+ from typing import Optional
144
+
145
+ from jinja2 import Template
146
+ import torch
147
+ from transformers import AutoModelForCausalLM, AutoTokenizer
148
+ from transformers.utils import get_json_schema
149
+
150
+
151
+ system_prompt = Template("""You are an expert in composing functions. You are given a question and a set of possible functions.
152
+ Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
153
+ If none of the functions can be used, point it out and refuse to answer.
154
+ If the given question lacks the parameters required by the function, also point it out.
155
+
156
+ You have access to the following tools:
157
+ <tools>{{ tools }}</tools>
158
+
159
+ The output MUST strictly adhere to the following format, and NO other text MUST be included.
160
+ 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 '[]'.
161
+ <tool_call>[
162
+ {"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}},
163
+ ... (more tool calls as required)
164
+ ]</tool_call>""")
165
+
166
+
167
+ def prepare_messages(
168
+ query: str,
169
+ tools: Optional[dict[str, any]] = None,
170
+ history: Optional[list[dict[str, str]]] = None
171
+ ) -> list[dict[str, str]]:
172
+ """Prepare the system and user messages for the given query and tools.
173
+
174
+ Args:
175
+ query: The query to be answered.
176
+ tools: The tools available to the user. Defaults to None, in which case if a
177
+ list without content will be passed to the model.
178
+ history: Exchange of messages, including the system_prompt from
179
+ the first query. Defaults to None, the first message in a conversation.
180
+ """
181
+ if tools is None:
182
+ tools = []
183
+ if history:
184
+ messages = history.copy()
185
+ messages.append({"role": "user", "content": query})
186
+ else:
187
+ messages = [
188
+ {"role": "system", "content": system_prompt.render(tools=json.dumps(tools))},
189
+ {"role": "user", "content": query}
190
+ ]
191
+ return messages
192
+
193
+
194
+ def parse_response(text: str) -> str | dict[str, any]:
195
+ """Parses a response from the model, returning either the
196
+ parsed list with the tool calls parsed, or the
197
+ model thought or response if couldn't generate one.
198
+
199
+ Args:
200
+ text: Response from the model.
201
+ """
202
+ pattern = r"<tool_call>(.*?)</tool_call>"
203
+ matches = re.findall(pattern, text, re.DOTALL)
204
+ if matches:
205
+ return json.loads(matches[0])
206
+ return text
207
+ ```
208
+
209
+ ## Limitations
210
+
211
+ 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.
212
+
213
+ ## Training
214
+
215
+ ### Model
216
+
217
+ - **Architecture:** Transformer decoder
218
+ - **Pretraining tokens:** 11T
219
+ - **Precision:** bfloat16
220
+
221
+ ### Hardware
222
+
223
+ - **GPUs:** 256 H100
224
+
225
+ ### Software
226
+
227
+ - **Training Framework:** [nanotron](https://github.com/huggingface/nanotron/tree/main)
228
+ - **Alignement Handbook** [alignement-handbook](https://github.com/huggingface/alignment-handbook/)
229
+
230
+ ## License
231
+
232
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
233
+
234
+ ## Citation
235
+ ```bash
236
+ @misc{allal2024SmolLM2,
237
+ title={SmolLM2 - with great data, comes great performance},
238
+ 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},
239
+ year={2024},
240
+ }
241
+ ```