说明文档
SmolLM2

目录
模型概述
SmolLM2 是一系列紧凑型语言模型,提供三种规格:135M、360M 和 1.7B 参数。它们能够解决广泛的任务,同时足够轻量,可在设备端运行。更多详情请参阅我们的论文 https://arxiv.org/abs/2502.02737
SmolLM2 相比其前身 SmolLM1 展现了显著进步,特别是在指令遵循、知识和推理方面。135M 模型使用 2 万亿 token 进行训练,采用多样化的数据集组合:FineWeb-Edu、DCLM、The Stack,以及我们精心筛选并将很快发布的新数据集。我们通过监督微调(SFT)开发了指令版本,使用了公开数据集和我们自己策划的数据集的组合。然后,我们使用 UltraFeedback 应用了直接偏好优化(DPO)。
得益于 Argilla 开发的数据集(如 Synth-APIGen-v0.1),指令模型还支持文本重写、摘要和函数调用(1.7B 版本)等任务。 你可以在这里找到 SFT 数据集:https://huggingface.co/datasets/HuggingFaceTB/smol-smoltalk,微调代码位于 https://github.com/huggingface/alignment-handbook/tree/main/recipes/smollm2
如何使用
Transformers
pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "HuggingFaceTB/SmolLM2-135M-Instruct"
device = "cuda" # 用于 GPU 或 "cpu" 用于 CPU
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# 对于多 GPU,安装 accelerate 并使用 `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
messages = [{"role": "user", "content": "What is gravity?"}]
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
print(input_text)
inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
print(tokenizer.decode(outputs[0]))
在 TRL 中聊天
你也可以使用 TRL CLI 从终端与模型聊天:
pip install trl
trl chat --model_name_or_path HuggingFaceTB/SmolLM2-135M-Instruct --device cpu
评估
在本节中,我们报告 SmolLM2 的评估结果。所有评估均为零样本(除非另有说明),我们使用 lighteval 来运行它们。
基础预训练模型
| 指标 | SmolLM2-135M-8k | SmolLM-135M |
|---|---|---|
| HellaSwag | 42.1 | 41.2 |
| ARC (平均) | 43.9 | 42.4 |
| PIQA | 68.4 | 68.4 |
| MMLU (填空) | 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 |
指令模型
| 指标 | SmolLM2-135M-Instruct | SmolLM-135M-Instruct |
|---|---|---|
| IFEval (平均 prompt/inst) | 29.9 | 17.2 |
| MT-Bench | 19.8 | 16.8 |
| HellaSwag | 40.9 | 38.9 |
| ARC (平均) | 37.3 | 33.9 |
| PIQA | 66.3 | 64.0 |
| MMLU (填空) | 29.3 | 28.3 |
| BBH (3-shot) | 28.2 | 25.2 |
| GSM8K (5-shot) | 1.4 | 1.4 |
局限性
SmolLM2 模型主要理解并生成英语内容。它们可以生成各种主题的文本,但生成的内容可能并不总是事实准确、逻辑一致,或免于训练数据中存在的偏见。这些模型应作为辅助工具使用,而非权威信息来源。用户应始终核实重要信息,并批判性地评估任何生成的内容。
训练
模型
- 架构: Transformer 解码器
- 预训练 token 数: 2T
- 精度: bfloat16
硬件
- GPU: 64 张 H100
软件
- 训练框架: nanotron
许可证
引用
@misc{allal2025smollm2smolgoesbig,
title={SmolLM2: When Smol Goes Big -- Data-Centric Training of a Small Language Model},
author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Gabriel Martín Blázquez and Guilherme Penedo and Lewis Tunstall and Andrés Marafioti and Hynek Kydlíček and Agustín Piqueres Lajarín and Vaibhav Srivastav and Joshua Lochner and Caleb Fahlgren and Xuan-Son Nguyen and Clémentine Fourrier and Ben Burtenshaw and Hugo Larcher and Haojun Zhao and Cyril Zakka and Mathieu Morlon and Colin Raffel and Leandro von Werra and Thomas Wolf},
year={2025},
eprint={2502.02737},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2502.02737},
}
loubnabnl/SmolLM2-135M-Instruct-template2
作者 loubnabnl
创建时间: 2025-02-18 15:22:19+00:00
更新时间: 2025-02-18 15:23:52+00:00
在 Hugging Face 上查看