ONNX 模型库
返回模型

说明文档

SmolLM

<center> <img src="https://huggingface.co/datasets/HuggingFaceTB/images/resolve/main/banner_smol.png" alt="SmolLM" width="1100" height="600"> </center>

目录

  1. 模型概述
  2. 局限性
  3. 训练
  4. 许可证
  5. 引用

模型概述

SmolLM 是一系列最先进的小型语言模型,提供三种参数规模:135M、360M 和 1.7B。这些模型基于 Cosmo-Corpus 构建,这是一个精心策划的高质量训练数据集。Cosmo-Corpus 包括 Cosmopedia v2(280亿个由 Mixtral 生成的合成教科书和故事 token)、Python-Edu(来自 The Stack 的 40亿个教育性 Python 样本 token)和 FineWeb-Edu(来自 FineWeb 的 2200亿个去重教育性网页样本 token)。在各种测试常识推理和世界知识的基准测试中,SmolLM 模型与同规模的其他模型相比表现出色。有关训练、基准测试和性能的详细信息,请参阅我们的完整博客文章

这是 SmolLM-135M 模型。

生成

pip install transformers

在 CPU/GPU/多 GPU 上运行模型

  • 使用全精度
# pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "HuggingFaceTB/SmolLM-135M"
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)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to(device)
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 12624.81 MB
  • 使用 torch.bfloat16
# pip install accelerate
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
checkpoint = "HuggingFaceTB/SmolLM-135M"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# 对于 fp16 使用 `torch_dtype=torch.float16` 代替
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 269.03 MB

通过 bitsandbytes 使用量化版本

  • 使用 8 位精度 (int8)
# pip install bitsandbytes accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
# 要使用 4bit 请用 `load_in_4bit=True` 代替
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
checkpoint = "HuggingFaceTB/SmolLM-135M"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
inputs = tokenizer.encode("def print_hello_world():", return_tensors="pt").to("cuda")
outputs = model.generate(inputs)
print(tokenizer.decode(outputs[0]))
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
# load_in_8bit
Memory footprint: 162.87 MB
# load_in_4bit
>>> print(f"Memory footprint: {model.get_memory_footprint() / 1e6:.2f} MB")
Memory footprint: 109.78 MB

局限性

虽然 SmolLM 模型在包含教育内容和合成文本的多样化数据集上进行了训练,但它们仍存在局限性。这些模型主要理解和生成英语内容。它们可以生成各种主题的文本,但生成的内容可能并不总是事实准确、逻辑一致,或不存在训练数据中的偏见。这些模型应作为辅助工具而非确定性的信息来源。用户应始终验证重要信息并批判性地评估任何生成的内容。有关模型能力和局限性的更全面讨论,请参阅我们的完整博客文章

本仓库包含我们最新训练模型的转换版本。我们注意到此转换检查点(transformers)与原始版本之间存在轻微的性能差异。我们正在努力解决此问题。

训练

模型

硬件

  • GPU: 64 张 H100

软件

许可证

Apache 2.0

引用

@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},
}

DewEfresh/SmolLM-135M

作者 DewEfresh

text-generation transformers
↓ 0 ♥ 0

创建时间: 2024-08-06 18:45:37+00:00

更新时间: 2024-08-06 18:45:38+00:00

在 Hugging Face 上查看

文件 (17)

.gitattributes
README.md
config.json
generation_config.json
merges.txt
model.safetensors
onnx/model.onnx ONNX
onnx/model_bnb4.onnx ONNX
onnx/model_fp16.onnx ONNX
onnx/model_int8.onnx ONNX
onnx/model_q4.onnx ONNX
onnx/model_quantized.onnx ONNX
onnx/model_uint8.onnx ONNX
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.json