This model is a quantized version of the original model
HuggingFaceTB/SmolLM-1.7B.
It's quantized using the BitsAndBytes library to 4-bit using the
bnb-my-repo space.
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.
1# pip install transformers
2from transformers import AutoModelForCausalLM, AutoTokenizer
3checkpoint = "HuggingFaceTB/SmolLM-1.7B"
4device = "cuda" # for GPU usage or "cpu" for CPU usage
5tokenizer = AutoTokenizer.from_pretrained(checkpoint)
6# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
7model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
8inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
9outputs = model.generate(inputs)
10print(tokenizer.decode(outputs[0]))
1# pip install accelerate
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM
4checkpoint = "HuggingFaceTB/SmolLM-1.7B"
5tokenizer = AutoTokenizer.from_pretrained(checkpoint)
6# for fp16 use `torch_dtype=torch.float16` instead
7model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
8inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
9outputs = model.generate(inputs)
10print(tokenizer.decode(outputs[0]))
1>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
2Memory footprint: 3422.76 MB
1# pip install bitsandbytes accelerate
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3# to use 4bit use `load_in_4bit=True` instead
4quantization_config = BitsAndBytesConfig(load_in_8bit=True)
5checkpoint = "HuggingFaceTB/SmolLM-1.7B"
6tokenizer = AutoTokenizer.from_pretrained(checkpoint)
7model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
8inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
9outputs = model.generate(inputs)
10print(tokenizer.decode(outputs[0]))
1>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
2# load_in_8bit
3Memory footprint: 1812.14 MB
4# load_in_4bit
5>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
6Memory footprint: 1006.84 MB
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.
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.
1@misc{allal2024SmolLM,
2 title={SmolLM - blazingly fast and remarkably powerful},
3 author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Leandro von Werra and Thomas Wolf},
4 year={2024},
5}