说明文档
SmolLM-1.7B-Instruct
<center> <img src="https://huggingface.co/datasets/HuggingFaceTB/images/resolve/main/banner_smol.png" alt="SmolLM" width="1100" height="600"> </center>
模型概述
SmolLM 是一系列小型语言模型,提供三种参数规模:135M、360M 和 1.7B。
这些模型在 SmolLM-Corpus 上进行预训练,这是一个经过精心筛选的高质量教育和合成数据集合,专为训练大语言模型而设计。更多详细信息,请参阅我们的博客文章。
为了构建 SmolLM-Instruct,我们在公开可用的数据集上对基础模型进行了微调。
更新日志
| 版本 | 描述 |
|---|---|
| v0.1 | SmolLM-Instruct 初始版本。我们在 WebInstructSub 数据集的允许使用子集上进行微调,并结合 StarCoder2-Self-OSS-Instruct。然后,我们对 135M 和 1.7B 模型在 HelpSteer 上进行了一个周期的 DPO(直接偏好优化),对 360M 模型在 argilla/dpo-mix-7k 上进行了 DPO。 |
| v0.2 | 我们调整了微调数据集组合,使其更适合小型模型。我们训练使用了 llama3.1-70B 生成的 2k 条简单日常对话新数据集 everyday-conversations-llama3.1-2k、Magpie-Pro-300K-Filtered、StarCoder2-Self-OSS-Instruct,以及 OpenHermes-2.5 的一个小子集 |
v0.2 模型在保持话题聚焦和对标准提示(如问候语和关于其 AI 助手身份的问题)做出恰当回应方面表现更好。SmolLM-360M-Instruct (v0.2) 在 AlpacaEval 上对 SmolLM-360M-Instruct (v0.1) 的胜率为 63.3%。您可以在这里查看详细信息。
您可以通过在 transformers 代码中指定 revision="v0.1" 来加载 v0.1 检查点:
model = AutoModelForCausalLM.from_pretrained("HuggingFaceTB/SmolLM-1.7B-Instruct", revision="v0.1")
使用方法
本地应用
⚡ 对于本地应用,您可以在以下合集中找到模型的优化实现,包括 MLC、GGUF 和 Transformers.js 格式,以及快速的浏览器内演示:https://huggingface.co/collections/HuggingFaceTB/local-smollms-66c0f3b2a15b4eed7fb198d0
我们注意到 4bit 量化会降低 135M 和 360M 模型的质量,因此对于 MLC 和 WebGPU 演示的 ONNX/Transformers.js 检查点,我们使用 q016。我们还建议使用 temperature 0.2 和 top-p 0.9。
Transformers
pip install transformers
# pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "HuggingFaceTB/SmolLM-1.7B-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 the capital of France."}]
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/SmolLM-1.7B-Instruct --device cpu
局限性
此外,生成的内容可能并不总是事实准确、逻辑一致,或不存在训练数据中的偏见。我们建议用户将其作为辅助工具而非权威信息来源。我们发现它们可以处理一般知识问题、创意写作和基础 Python 编程。但它们仅支持英语,在算术、编辑任务和复杂推理方面可能存在困难。有关模型能力的更多详细信息,请参阅我们的博客文章。
训练参数
我们使用 alignment-handbook 训练模型,使用更新日志中提到的数据集,参数如下 v0.2(大部分来自 Zephyr Gemma 配方):
- 1 个 epoch
- 学习率 1e-3
- 余弦学习率调度
- 预热比例 0.1
- 全局批次大小 262k tokens
您可以在这里找到训练配方:https://github.com/huggingface/alignment-handbook/tree/smollm/recipes/smollm
引用
@misc{allal2024SmolLM,
title={SmolLM - blazingly fast and remarkably powerful},
author={Loubna Ben Allal and Anton Lozhkov and Elie Bakouch and Leandro von Werra and Thomas Wolf},
year={2024},
}
nanocoh/SmolLM-1.7B-Instruct
作者 nanocoh
创建时间: 2025-04-01 13:48:51+00:00
更新时间: 2025-04-01 13:48:51+00:00
在 Hugging Face 上查看