Views
No views yet
pip install transformers1# pip install transformers
2from transformers import AutoModelForCausalLM, AutoTokenizer
3checkpoint = "HuggingFaceTB/SmolLM2-135M"
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("Gravity is", return_tensors="pt").to(device)
9outputs = model.generate(inputs)
10print(tokenizer.decode(outputs[0]))torch.bfloat161# pip install accelerate
2import torch
3from transformers import AutoTokenizer, AutoModelForCausalLM
4checkpoint = "HuggingFaceTB/SmolLM2-135M"
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("Gravity is", 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: 723.56 MB| Metrics | SmolLM2-135M-8k | SmolLM-135M |
|---|---|---|
| HellaSwag | 42.1 | 41.2 |
| ARC (Average) | 43.9 | 42.4 |
| PIQA | 68.4 | 68.4 |
| MMLU (cloze) | 31.5 | 30.2 |
| CommonsenseQA | 33.9 | 32.7 |
| TriviaQA | 4.1 | 4.3 |
| Winogrande | 51.3 | 51.3 |
| OpenBookQA | 34.6 | 34.0 |
| GSM8K (5-shot) | 1.4 | 1.0 |
| Metric | SmolLM2-135M-Instruct | SmolLM-135M-Instruct |
|---|---|---|
| IFEval (Average prompt/inst) | 29.9 | 17.2 |
| MT-Bench | 1.98 | 1.68 |
| HellaSwag | 40.9 | 38.9 |
| ARC (Average) | 37.3 | 33.9 |
| PIQA | 66.3 | 64.0 |
| MMLU (cloze) | 29.3 | 28.3 |
| BBH (3-shot) | 28.2 | 25.2 |
| GSM8K (5-shot) | 1.4 | 1.4 |
1@misc{allal2024SmolLM2,
2 title={SmolLM2 - with great data, comes great performance},
3 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},
4 year={2024},
5}