Update README.md
Browse files
README.md
CHANGED
@@ -1,78 +1,106 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
-
|
6 |
-
- dpo
|
7 |
-
- generated_from_trainer
|
8 |
-
- trl
|
9 |
-
- dpo
|
10 |
-
- generated_from_trainer
|
11 |
-
datasets:
|
12 |
-
- HuggingFaceTB/Helpsteer
|
13 |
-
model-index:
|
14 |
-
- name: cosmo2-135M-webinst-sc2-dpo-helpsteer-ep1
|
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 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
language:
|
5 |
+
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
---
|
7 |
|
|
|
|
|
8 |
|
9 |
+
# SmolLM
|
10 |
+
|
11 |
+
<center>
|
12 |
+
<img src="https://huggingface.co/datasets/HuggingFaceTB/images/resolve/main/banner_smol.png" alt="SmolLM" width="1100" height="600">
|
13 |
+
</center>
|
14 |
+
|
15 |
+
## Table of Contents
|
16 |
+
|
17 |
+
1. [Model Summary](##model-summary)
|
18 |
+
2. [Limitations](##limitations)
|
19 |
+
3. [Training](##training)
|
20 |
+
4. [License](##license)
|
21 |
+
5. [Citation](##citation)
|
22 |
+
|
23 |
+
## Model Summary
|
24 |
+
|
25 |
+
SmolLM is a series of state-of-the-art small language models available in three sizes: 135M, 360M, and 1.7B parameters. These models are built on Cosmo-Corpus, a meticulously curated high-quality training dataset. Cosmo-Corpus includes Cosmopedia v2 (28B tokens of synthetic textbooks and stories generated by Mixtral), Python-Edu (4B tokens of educational Python samples from The Stack), and FineWeb-Edu (220B tokens of deduplicated educational web samples from FineWeb). For duther details, we refer to our blogpost TODO.
|
26 |
+
|
27 |
+
To build SmolLM-Instruct, we instruction tuned the models using publicly available permissive instruction datasets. We trained all three models for one epoch on the permissive subset of the WebInstructSub dataset, combined with StarCoder2-Self-OSS-Instruct. Following this, we performed DPO (Direct Preference Optimization) for one epoch: using HelpSteer for the 135M and 1.7B models, and argilla/dpo-mix-7k for the 360M model. We followed the training parameters from the Zephyr-Gemma recipe in the alignment handbook, but adjusted the SFT (Supervised Fine-Tuning) learning rate to 3e-4.
|
28 |
+
[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
29 |
+
|
30 |
+
### Generation
|
31 |
+
```bash
|
32 |
+
pip install transformers
|
33 |
+
```
|
34 |
+
|
35 |
+
#### Running the model on CPU/GPU/multi GPU
|
36 |
+
* _Using full precision_
|
37 |
+
```python
|
38 |
+
# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main
|
39 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
40 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
41 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
42 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
43 |
+
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
|
44 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
45 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
|
46 |
+
outputs = model.generate(inputs)
|
47 |
+
print(tokenizer.decode(outputs[0]))
|
48 |
+
```
|
49 |
+
```bash
|
50 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
51 |
+
Memory footprint: 12624.81 MB
|
52 |
+
```
|
53 |
+
* _Using `torch.bfloat16`_
|
54 |
+
```python
|
55 |
+
# pip install accelerate
|
56 |
+
import torch
|
57 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
58 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
59 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
60 |
+
# for fp16 use `torch_dtype=torch.float16` instead
|
61 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
|
62 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
63 |
+
outputs = model.generate(inputs)
|
64 |
+
print(tokenizer.decode(outputs[0]))
|
65 |
+
```
|
66 |
+
```bash
|
67 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
68 |
+
Memory footprint: 269.03 MB
|
69 |
+
```
|
70 |
+
|
71 |
+
#### Quantized Versions through `bitsandbytes`
|
72 |
+
* _Using 8-bit precision (int8)_
|
73 |
+
|
74 |
+
```python
|
75 |
+
# pip install bitsandbytes accelerate
|
76 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
77 |
+
# to use 4bit use `load_in_4bit=True` instead
|
78 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
79 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
80 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
81 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
|
82 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
83 |
+
outputs = model.generate(inputs)
|
84 |
+
print(tokenizer.decode(outputs[0]))
|
85 |
+
```
|
86 |
+
```bash
|
87 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
88 |
+
# load_in_8bit
|
89 |
+
Memory footprint: 162.87 MB
|
90 |
+
# load_in_4bit
|
91 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
92 |
+
Memory footprint: 109.78 MB
|
93 |
+
```
|
94 |
+
|
95 |
+
# Limitations
|
96 |
+
|
97 |
+
While SmolLM models have been trained on a diverse dataset including educational content and synthetic texts, they have limitations. The 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. For a more comprehensive discussion of the models' capabilities and limitations, please refer to our full blog post.
|
98 |
+
|
99 |
+
# Citation
|
100 |
+
```bash
|
101 |
+
@misc{allal2024SmolLM,
|
102 |
+
title={SmolLM - blazingly fast and remarkably powerful},
|
103 |
+
author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Leandro von Werra and Thomas Wolf},
|
104 |
+
year={2024},
|
105 |
+
}
|
106 |
+
```
|