效果秒杀同类模型,HuggingFace发布手机上能跑的SmolLM

人工智能
SmolLM系列包括三个成员,它们分别拥有1.35亿、3.6亿和17亿参数量,它们被设计来满足不同层次的计算需求。尽管这些模型体积轻巧,但在常识推理和世界知识基准测试中却展现出了卓越的性能。

Hugging Face最近推出了一套精巧的紧凑型语言模型——SmolLM,它们在性能上已经超越了微软、Meta和阿里巴巴的千问系列等竞争对手。这些新晋模型不仅为个人设备带来了尖端的AI功能,并不耗费过多的设备性能,更能保护用户隐私。

SmolLM系列包括三个成员,它们分别拥有1.35亿、3.6亿和17亿参数量,它们被设计来满足不同层次的计算需求。尽管这些模型体积轻巧,但在常识推理和世界知识基准测试中却展现出了卓越的性能。

特别值得一提的是,即使是体积最小的SmolLM-135M,在训练中使用的token数量较少的情况下,其性能也超过了Meta的MobileLM-125M。而SmolLM-360M则宣称,在所有低于5亿参数的模型中,它的性能是最牛的,包括Meta和阿里巴巴的千问系列产品。至于旗舰模型SmolLM-1.7B,则在多个基准测试中战胜了微软的Phi-1.5、Meta的MobileLM-1.5B以及千问Qwen2-1.5B,确立了其在高端AI模型中的领先地位。

SmolLM的发布也有望对AI的可及性及用户隐私产生重大影响。这些模型完全可以在手机及笔记本电脑等个人设备上运行,因此消除了云计算需求,同时缓解了成本与隐私问题。希望有更多类似模型推出哦!!!

下面我们将介绍系列模型的一些细节。

各方发言

Hugging Face公司SmolLM项目首席机器学习工程师Ben Allal在采访时解释道:“通过SmolLM的现实性能,我们证明数据质量是决定模型水平的关键因素。我们开发出的创新方法能够精心策划高质量数据,将网络来源与合成数据相结合,从而建立起性能最佳小模型。”

Hugging Face研究团队负责人Leandro von Werra在采访时还特别强调了SmolLM的实际意义。“这些紧凑型模型为开发人员和最终用户打开了一个充满可能性的世界。从个性化自动补全功能到解析复杂的用户请求,SmolLM无需昂贵的GPU或者云基础设施即可支撑起自定义AI应用程序。无论是降低AI的访问门槛、还是为每个人提供隐私保护,SmolLM的出现都代表着迈向未来的重要一步。”

随着SmolLM模型家族、数据集以及训练代码的正式亮相,全球AI社区及开发人员现在已经可以探索、改进并构建这种创新的语言模型方法。正如Ben Allal在采访中做出的总结:“希望更多人参与进来,帮助SmolLM更上一层楼!”

佩服HF的开放精神,方法全开源,点赞。

数据集介绍

这些模型的出色表现,离不开精心策划的训练数据,也是本文最大的创新点。

Smollm Corpus 数据集:

  • Cosmopedia v2: 由Mixtral 生成的包含38B tokens的合成教材和故事内容的
  • Python-Edu: Stack 上的教育性Python示例(4B tokens)
  • FineWeb-Edu (deduplicated): FineWeb 上的精选教育性网络内容(220B tokens)

训练数据量:

SmolLM模型有三个不同尺寸,它们分别在不同量级的混合数据上训练得到:

  • 135M and 360M models, 在Smollm-Corpus数据集中选择了600B tokens的训练数据;
  • 1.7B model, 在Smollm-Corpus数据集中选择了1T的训练数据。

数据分布图:

图片图片

指令微调数据集:StarCoder2-Self-OSS-Instruct

dpo数据集:

  • 集中135M和1.7B模型使用的是HelpSteer数据集;
  • 360M的模型,使用的是argilla/dpo-mix-7k;

    都只训练了一个epoch。

表现介绍

在大多数任务以及平均得分上,在相同尺寸的模型上取得了state-of-the-art的成绩,但是并没有在所有测试集上都最好。

图片图片

模型结构

参数配置

自注意力的是GQA分组查询注意力,模型具体配置如下:

图片图片

显存占用

下面是模型占用显存的小,官方已经给出了量化版的onnx权重:

图片图片

支持长度:这几款模型支持的长度都是2048个token(通过微调后,可以支持更长)

Tokenizer:在Smollm Corpus上训练得到,词表大小为49152.

跑起来

官方给的推理代码(有些小问题需要自己改一下)

# pip install transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
checkpoint = "HuggingFaceTB/SmolLM-1.7B-Instruct"


device = "cuda" # for GPU usage or "cpu" for CPU usage
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
# for multiple GPUs install accelerate and do `model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto")`
model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)


messages = [{"role": "user", "content": "List the steps to bake a chocolate cake from scratch."}]
input_text=tokenizer.apply_chat_template(messages, tokenize=False)
print(input_text)
inputs = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(inputs, max_new_tokens=100, temperature=0.6, top_p=0.92, do_sample=True)
print(tokenizer.decode(outputs[0]))

测试小例子

chat("hello")
# The statement is false. 


chat("1+1=")
# The equation 1+1=1 is true, but the equation 1+1=2 is false. This is because the statement "1+1=1" is a tautology, meaning that it is always true regardless of the values of its variables. However, the statement "1+1=2" is a contradiction, meaning that it is false if and only if both 1 and 1 are true. Since 1 is true, the statement "1+1

官方例子

chat("List the steps to bake a chocolate cake from scratch.")
# result
To bake a chocolate cake from scratch, follow these steps:


1. Gather ingredients:
   - 2 cups all-purpose flour
   - 1 cup unsweetened cocoa powder
   - 2 teaspoons baking soda
   - 1 teaspoon salt
   - 2 cups granulated sugar
   - 2 large eggs
   - 1 cup whole milk
   - 1/2 cup vegetable oil
   - 2 teaspoons vanilla extract


2. Preheat the oven to 350°F (175°C).


3. Combine dry ingredients:
   - In a large bowl, whisk together flour, cocoa powder, baking soda, and salt.


4. Mix wet ingredients:
   - In another bowl, beat sugar, eggs, milk, oil, and vanilla until well combined.


5. Combine wet and dry mixtures:
   - Gradually add the wet mixture to the dry ingredients, stirring until just combined.


6. Pour batter into a greased 9-inch round cake pan.


7. Bake for 30-35 minutes, or until a toothpick inserted into the center comes out clean.


8. Allow the cake to cool in the pan for 10 minutes, then transfer it to a wire rack to cool completely.


Note: The original answer provided a list of ingredients and a step-by-step process, but it lacked a clear explanation of the steps and the reasoning behind them. The revised answer provides a more detailed and coherent explanation of the baking process.

这个模型实测起来,除了官方例子,表现并不像说的那么好,感觉像个傻子一样,难道是我的姿势不对吗。真像说的那样Bad Baseline Is All You Need吗。希望大家都卷起来,这个开源项目数据处理部分有很大的参考意义,感兴趣的可以关注一下:

# 博客地址
https://huggingface.co/blog/smollm
# 无法访问的可以访问下面的地址
https://hf-mirror.com/blog/smollm

由于各种原因huggingface不容易访问了,还好有个镜像https://hf-mirror.com可以使用。

如果对内容有什么疑问和建议可以私信和留言,也可以添加我加入大模型交流群,一起讨论大模型在创作、RAG和agent中的应用。

责任编辑:武晓燕 来源: 哎呀AIYA
相关推荐

2023-12-13 12:55:39

模型数据

2024-05-17 17:16:50

SOTA视觉模型

2023-03-28 15:48:39

开源模型

2023-06-08 11:06:17

OpenAITigerBot

2024-05-10 13:53:25

人工智能AI大模型

2011-10-21 10:26:51

Howdy明信片

2012-03-07 13:32:38

2021-04-21 10:22:56

Python 开发编程语言

2011-09-15 16:09:13

Meexo游戏式约会在线约会

2020-09-05 16:35:20

AndroidPython软件开发

2017-07-24 14:18:16

Windows XPWindows手机上网

2023-05-16 13:54:00

模型AI

2014-05-16 14:18:08

OONE手机隐私

2011-03-30 13:56:06

2021-03-24 20:30:15

AndroidPython学习

2023-12-03 22:51:35

谷歌论文

2022-02-20 20:14:49

安卓LinuxLinux 命令

2024-02-22 09:30:15

Gemma开源模型谷歌

2012-03-14 10:04:49

手机浏览器海豚浏览器
点赞
收藏

51CTO技术栈公众号