Update README.md
Browse files
README.md
CHANGED
@@ -1,77 +1,108 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
-
|
6 |
-
- dpo
|
7 |
-
- generated_from_trainer
|
8 |
-
- trl
|
9 |
-
- dpo
|
10 |
-
- generated_from_trainer
|
11 |
-
datasets:
|
12 |
-
- argilla/dpo-mix-7k
|
13 |
-
model-index:
|
14 |
-
- name: cosmo2-350M-webinst-sc2-dpo-argilla-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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
library_name: transformers
|
3 |
+
license: apache-2.0
|
4 |
+
language:
|
5 |
+
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
---
|
7 |
|
|
|
|
|
8 |
|
9 |
+
# SmolLM-Instruct
|
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 |
+
This is the SmolLM-360M-Instruct.
|
31 |
+
|
32 |
+
### Generation
|
33 |
+
```bash
|
34 |
+
pip install transformers
|
35 |
+
```
|
36 |
+
|
37 |
+
#### Running the model on CPU/GPU/multi GPU
|
38 |
+
* _Using full precision_
|
39 |
+
```python
|
40 |
+
# pip install git+https://github.com/huggingface/transformers.git # TODO: merge PR to main
|
41 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
42 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
43 |
+
device = "cuda" # for GPU usage or "cpu" for CPU usage
|
44 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
45 |
+
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
|
46 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
|
47 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
|
48 |
+
outputs = model.generate(inputs)
|
49 |
+
print(tokenizer.decode(outputs[0]))
|
50 |
+
```
|
51 |
+
```bash
|
52 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
53 |
+
Memory footprint: 12624.81 MB
|
54 |
+
```
|
55 |
+
* _Using `torch.bfloat16`_
|
56 |
+
```python
|
57 |
+
# pip install accelerate
|
58 |
+
import torch
|
59 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
60 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
62 |
+
# for fp16 use `torch_dtype=torch.float16` instead
|
63 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
|
64 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
65 |
+
outputs = model.generate(inputs)
|
66 |
+
print(tokenizer.decode(outputs[0]))
|
67 |
+
```
|
68 |
+
```bash
|
69 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
70 |
+
Memory footprint: 269.03 MB
|
71 |
+
```
|
72 |
+
|
73 |
+
#### Quantized Versions through `bitsandbytes`
|
74 |
+
* _Using 8-bit precision (int8)_
|
75 |
+
|
76 |
+
```python
|
77 |
+
# pip install bitsandbytes accelerate
|
78 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
79 |
+
# to use 4bit use `load_in_4bit=True` instead
|
80 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
81 |
+
checkpoint = "HuggingFaceTB/SmolLM-135M"
|
82 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
83 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
|
84 |
+
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
|
85 |
+
outputs = model.generate(inputs)
|
86 |
+
print(tokenizer.decode(outputs[0]))
|
87 |
+
```
|
88 |
+
```bash
|
89 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
90 |
+
# load_in_8bit
|
91 |
+
Memory footprint: 162.87 MB
|
92 |
+
# load_in_4bit
|
93 |
+
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
|
94 |
+
Memory footprint: 109.78 MB
|
95 |
+
```
|
96 |
+
|
97 |
+
# Limitations
|
98 |
+
|
99 |
+
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.
|
100 |
+
|
101 |
+
# Citation
|
102 |
+
```bash
|
103 |
+
@misc{allal2024SmolLM,
|
104 |
+
title={SmolLM - blazingly fast and remarkably powerful},
|
105 |
+
author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Leandro von Werra and Thomas Wolf},
|
106 |
+
year={2024},
|
107 |
+
}
|
108 |
+
```
|