professorf commited on
Commit
2dc989d
·
verified ·
1 Parent(s): b11f69e

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +131 -0
README.md ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ language:
5
+ - en
6
+ datasets:
7
+ - HuggingFaceTB/smollm-corpus
8
+ ---
9
+ <!-- header start -->
10
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
11
+ <div style="text-align:center; margin-top: 0em; margin-bottom: 0em"><p style="margin-top: 0.25em; margin-bottom: 0em;">ProfessorF is Nick V. Flor, PhD<br>Models quantized for research reproducibility purposes</p></div>
12
+ <hr style="margin-top: 1.0em; margin-bottom: 1.0em;">
13
+ <!-- header end -->
14
+ # SmolLM
15
+
16
+ <center>
17
+ <img src="https://huggingface.co/datasets/HuggingFaceTB/images/resolve/main/banner_smol.png" alt="SmolLM" width="1100" height="600">
18
+ </center>
19
+
20
+ ## Table of Contents
21
+
22
+ 1. [Model Summary](##model-summary)
23
+ 2. [Limitations](##limitations)
24
+ 3. [Training](##training)
25
+ 4. [License](##license)
26
+ 5. [Citation](##citation)
27
+
28
+ ## Model Summary
29
+
30
+ 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). SmolLM models have shown promising results when compared to other models in their size categories across various benchmarks testing common sense reasoning and world knowledge. For detailed information on training, benchmarks and performance, please refer to our full [blog post](https://huggingface.co/blog/smollm).
31
+
32
+
33
+ This is SmolLM-1.7B
34
+
35
+ ### Generation
36
+
37
+ ```bash
38
+ pip install transformers
39
+ ```
40
+
41
+ #### Running the model on CPU/GPU/multi GPU
42
+ * _Using full precision_
43
+ ```python
44
+ # pip install transformers
45
+ from transformers import AutoModelForCausalLM, AutoTokenizer
46
+ checkpoint = "HuggingFaceTB/SmolLM-1.7B"
47
+ device = "cuda" # for GPU usage or "cpu" for CPU usage
48
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
49
+ # for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
50
+ model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
51
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
52
+ outputs = model.generate(inputs)
53
+ print(tokenizer.decode(outputs[0]))
54
+ ```
55
+
56
+ * _Using `torch.bfloat16`_
57
+ ```python
58
+ # pip install accelerate
59
+ import torch
60
+ from transformers import AutoTokenizer, AutoModelForCausalLM
61
+ checkpoint = "HuggingFaceTB/SmolLM-1.7B"
62
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
63
+ # for fp16 use `torch_dtype=torch.float16` instead
64
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
65
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
66
+ outputs = model.generate(inputs)
67
+ print(tokenizer.decode(outputs[0]))
68
+ ```
69
+ ```bash
70
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
71
+ Memory footprint: 3422.76 MB
72
+ ```
73
+
74
+ #### Quantized Versions through `bitsandbytes`
75
+ * _Using 8-bit precision (int8)_
76
+
77
+ ```python
78
+ # pip install bitsandbytes accelerate
79
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
80
+ # to use 4bit use `load_in_4bit=True` instead
81
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
82
+ checkpoint = "HuggingFaceTB/SmolLM-1.7B"
83
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
84
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
85
+ inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
86
+ outputs = model.generate(inputs)
87
+ print(tokenizer.decode(outputs[0]))
88
+ ```
89
+ ```bash
90
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
91
+ # load_in_8bit
92
+ Memory footprint: 1812.14 MB
93
+ # load_in_4bit
94
+ >>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
95
+ Memory footprint: 1006.84 MB
96
+ ```
97
+
98
+ # Limitations
99
+
100
+ 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](https://huggingface.co/blog/smollm).
101
+
102
+ This repository contains a converted version of our latest trained model. We've noticed a small performance difference between this converted checkpoint (transformers) and the original (nanotron). We're currently working to resolve this issue.
103
+ # Training
104
+
105
+ ## Model
106
+
107
+ - **Architecture:** For architecture detail, see the [blog post](https://huggingface.co/blog/smollm).
108
+ - **Pretraining steps:** 500k
109
+ - **Pretraining tokens:** 1T
110
+ - **Precision:** bfloat16
111
+
112
+ ## Hardware
113
+
114
+ - **GPUs:** 64 H100
115
+
116
+ ## Software
117
+
118
+ - **Training Framework:** [Nanotron](https://github.com/huggingface/nanotron/tree/main)
119
+
120
+ # License
121
+
122
+ [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
123
+
124
+ # Citation
125
+ ```bash
126
+ @misc{allal2024SmolLM,
127
+ title={SmolLM - blazingly fast and remarkably powerful},
128
+ author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Leandro von Werra and Thomas Wolf},
129
+ year={2024},
130
+ }
131
+ ```