说明文档
SmolLM2

目录
模型概述
SmolLM2 是一个紧凑语言模型系列,包含三种规格:135M、360M 和 1.7B 参数。它们能够解决广泛的任务,同时足够轻量,可以在设备端运行。更多详情请参阅我们的论文 https://arxiv.org/abs/2502.02737
SmolLM2 相比其前身 SmolLM1 展现出显著的进步,特别是在指令遵循、知识掌握和推理能力方面。135M 模型使用了 2 万亿个 token 进行训练,数据集组合多样化:FineWeb-Edu、DCLM、The Stack,以及我们新筛选整理的数据集(即将发布)。我们通过监督微调(SFT)使用了公开数据集和我们自己整理的数据集来开发指令版本。然后,我们应用了直接偏好优化(DPO),使用了 UltraFeedback。
指令模型还支持文本重写、摘要和函数调用(1.7B 模型)等任务,这要归功于 Argilla 开发的数据集,如 Synth-APIGen-v0.1。 您可以在此处找到 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
Transformers.js
npm i @huggingface/transformers
import { pipeline } from "@huggingface/transformers";
// 创建文本生成管道
const generator = await pipeline(
"text-generation",
"HuggingFaceTB/SmolLM2-135M-Instruct",
);
// 定义消息列表
const messages = [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What is the capital of France?" },
];
// 生成回复
const output = await generator(messages, { max_new_tokens: 128 });
console.log(output[0].generated_text.at(-1).content);
// "The capital of France is Paris."
评估
本节报告 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/指令) | 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},
}
HuggingFaceTB/SmolLM2-135M-Instruct
作者 HuggingFaceTB
创建时间: 2024-10-31 13:41:10+00:00
更新时间: 2025-09-22 20:43:15+00:00
在 Hugging Face 上查看