效果秒殺同類模型,HuggingFace發(fā)布手機上能跑的SmolLM
Hugging Face最近推出了一套精巧的緊湊型語言模型——SmolLM,它們在性能上已經(jīng)超越了微軟、Meta和阿里巴巴的千問系列等競爭對手。這些新晉模型不僅為個人設(shè)備帶來了尖端的AI功能,并不耗費過多的設(shè)備性能,更能保護用戶隱私。
SmolLM系列包括三個成員,它們分別擁有1.35億、3.6億和17億參數(shù)量,它們被設(shè)計來滿足不同層次的計算需求。盡管這些模型體積輕巧,但在常識推理和世界知識基準測試中卻展現(xiàn)出了卓越的性能。
特別值得一提的是,即使是體積最小的SmolLM-135M,在訓練中使用的token數(shù)量較少的情況下,其性能也超過了Meta的MobileLM-125M。而SmolLM-360M則宣稱,在所有低于5億參數(shù)的模型中,它的性能是最牛的,包括Meta和阿里巴巴的千問系列產(chǎn)品。至于旗艦?zāi)P蚐molLM-1.7B,則在多個基準測試中戰(zhàn)勝了微軟的Phi-1.5、Meta的MobileLM-1.5B以及千問Qwen2-1.5B,確立了其在高端AI模型中的領(lǐng)先地位。
SmolLM的發(fā)布也有望對AI的可及性及用戶隱私產(chǎn)生重大影響。這些模型完全可以在手機及筆記本電腦等個人設(shè)備上運行,因此消除了云計算需求,同時緩解了成本與隱私問題。希望有更多類似模型推出哦!??!
下面我們將介紹系列模型的一些細節(jié)。
各方發(fā)言
Hugging Face研究團隊負責人Leandro von Werra在采訪時還特別強調(diào)了SmolLM的實際意義?!斑@些緊湊型模型為開發(fā)人員和最終用戶打開了一個充滿可能性的世界。從個性化自動補全功能到解析復雜的用戶請求,SmolLM無需昂貴的GPU或者云基礎(chǔ)設(shè)施即可支撐起自定義AI應(yīng)用程序。無論是降低AI的訪問門檻、還是為每個人提供隱私保護,SmolLM的出現(xiàn)都代表著邁向未來的重要一步?!?/p>
隨著SmolLM模型家族、數(shù)據(jù)集以及訓練代碼的正式亮相,全球AI社區(qū)及開發(fā)人員現(xiàn)在已經(jīng)可以探索、改進并構(gòu)建這種創(chuàng)新的語言模型方法。正如Ben Allal在采訪中做出的總結(jié):“希望更多人參與進來,幫助SmolLM更上一層樓!”
佩服HF的開放精神,方法全開源,點贊。
數(shù)據(jù)集介紹
Smollm Corpus 數(shù)據(jù)集:
- Cosmopedia v2: 由Mixtral 生成的包含38B tokens的合成教材和故事內(nèi)容的
- Python-Edu: Stack 上的教育性Python示例(4B tokens)
- FineWeb-Edu (deduplicated): FineWeb 上的精選教育性網(wǎng)絡(luò)內(nèi)容(220B tokens)
訓練數(shù)據(jù)量:
SmolLM模型有三個不同尺寸,它們分別在不同量級的混合數(shù)據(jù)上訓練得到:
- 135M and 360M models, 在Smollm-Corpus數(shù)據(jù)集中選擇了600B tokens的訓練數(shù)據(jù);
- 1.7B model, 在Smollm-Corpus數(shù)據(jù)集中選擇了1T的訓練數(shù)據(jù)。
數(shù)據(jù)分布圖:
圖片
指令微調(diào)數(shù)據(jù)集:StarCoder2-Self-OSS-Instruct
dpo數(shù)據(jù)集:
- 集中135M和1.7B模型使用的是HelpSteer數(shù)據(jù)集;
- 360M的模型,使用的是argilla/dpo-mix-7k;
都只訓練了一個epoch。
表現(xiàn)介紹
圖片
模型結(jié)構(gòu)
參數(shù)配置
自注意力的是GQA分組查詢注意力,模型具體配置如下:
圖片
顯存占用
圖片
支持長度:這幾款模型支持的長度都是2048個token(通過微調(diào)后,可以支持更長)
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.
這個模型實測起來,除了官方例子,表現(xiàn)并不像說的那么好,感覺像個傻子一樣,難道是我的姿勢不對嗎。真像說的那樣Bad Baseline Is All You Need嗎。希望大家都卷起來,這個開源項目數(shù)據(jù)處理部分有很大的參考意義,感興趣的可以關(guān)注一下:
# 博客地址
https://huggingface.co/blog/smollm
# 無法訪問的可以訪問下面的地址
https://hf-mirror.com/blog/smollm
由于各種原因huggingface不容易訪問了,還好有個鏡像https://hf-mirror.com可以使用。
如果對內(nèi)容有什么疑問和建議可以私信和留言,也可以添加我加入大模型交流群,一起討論大模型在創(chuàng)作、RAG和agent中的應(yīng)用。