作者:蔡文睿(清素)、汪誠愚(熊兮)、嚴(yán)俊冰(玖燭)、黃俊(臨在)
前言
自然語言處理領(lǐng)域因大語言模型(LLM)的突破發(fā)生重大變革,深度推理模型如 Open AI o1、DeepSeek-R1 等,通過思維鏈推理策略,模擬人類思考過程。然而上述長推理模型在實(shí)際使用中仍然存在兩個問題。首先,模型體積龐大,計算需求高,部署成本昂貴,這為實(shí)際應(yīng)用場景帶來了一系列挑戰(zhàn)。其次,在某些特定任務(wù)中,思維鏈推理的過程常因路徑過長導(dǎo)致冗余,在效率和準(zhǔn)確性上存在進(jìn)一步提升的空間。
基于阿里云星空人工智能平臺(PAI)的蒸餾工具包EasyDistill(https://github.com/modelscope/easydistill),我們提出變長思維鏈蒸餾技術(shù),探索如何通過蒸餾的方式將小模型的推理能力提升到極致。在此基礎(chǔ)上產(chǎn)出了當(dāng)時業(yè)界最大的高質(zhì)量變長思維鏈數(shù)據(jù)集OmniThought,以及DistilQwen-ThoughtX系列蒸餾模型(DistilQwen-ThoughtX:變長思維鏈推理模型,能力超越DeepSeek蒸餾模型)。近期,PAI團(tuán)隊進(jìn)一步更新了OmniThought數(shù)據(jù)集,并發(fā)布了新的蒸餾模型DistillQwen-ThoughtY系列。DistillQwen-ThoughtY系列是基于全新Qwen3 學(xué)生模型和DeepSeek-R1-0528教師模型訓(xùn)練而成。該模型在數(shù)學(xué)、代碼等領(lǐng)域,全面提升小模型推理能力。相關(guān)模型權(quán)重、蒸餾方法與蒸餾DeepSeek-R1-0528模型獲得的OmniThought-0528數(shù)據(jù)集已在 EasyDistill框架開源。
本文將重點(diǎn)解析基于EasyDistill框架實(shí)現(xiàn)DistillQwen-ThoughtY模型的蒸餾,評測模型相關(guān)效果,最后介紹了DistillQwen-ThoughtY模型在開源社區(qū)和PAI平臺上的使用方式。
技術(shù)簡介
OmniThought-0528數(shù)據(jù)集的構(gòu)建
在先前的工作(DistilQwen-ThoughtX:變長思維鏈推理模型,能力超越DeepSeek蒸餾模型),我們構(gòu)建了OmniThought思維鏈數(shù)據(jù)集,從多個公開數(shù)據(jù)源搜集推理問題構(gòu)成框架的輸入,涵蓋數(shù)學(xué)、編碼、科學(xué)等不同領(lǐng)域的推理問題。對于每個問題,采用DeepSeek-R1和QwQ-32B作為教師模型生成多個思維鏈,采用“LLM-as-a-judge”方法對生成的思維鏈進(jìn)行多個方面的正確性驗(yàn)證,僅當(dāng)驗(yàn)證為正確的思維鏈才能最終被選為訓(xùn)練集。此外,對于每條思維鏈,我們標(biāo)注了“推理冗余度(Reasoning Verbosity,RV)”和“認(rèn)知難度(Cognitive Difficulty,CD)”這兩個指標(biāo),描述如下所示:
評分
推理冗余度
認(rèn)知難度
0-1
最低冗余度,直接輸出結(jié)果,幾乎沒有詳細(xì)說明。
小學(xué)、入門級知識,或者單一簡單思考模式。
2-3
較低冗余度,有清晰簡潔的推理過程,包含必要的解釋。
多步算術(shù),枚舉,基于基本規(guī)則的推理。
4-5
中等冗余度,提供詳細(xì)解釋并進(jìn)行充分推理。
初級邏輯/代數(shù)知識;非顯而易見的推理。
6-7
較高冗余度,全面的論證,進(jìn)行復(fù)雜的探索。
使用高級技術(shù)(行列式,動態(tài)規(guī)劃,代碼推理等)。
8-9
高冗余度,深入、詳盡的推理;涉及詳細(xì)論述、嵌套論證及考慮反對論點(diǎn)的討論。
高度抽象的方法,包括嵌套證明、復(fù)雜算法分析等。
從推理冗余度的角度看,由于對于難度較大的問題,較長的思維鏈能夠糾正模型自身的錯誤;而在處理簡單任務(wù)時,思維鏈的過度推理和驗(yàn)證不僅會增加計算資源的消耗,還可能降低解決問題的準(zhǔn)確性。因此,推理冗余度與問題的難度有較大的關(guān)聯(lián)性。從認(rèn)知難度的角度看,小模型由于參數(shù)量和學(xué)習(xí)到的知識量限制,通常依賴更簡單的方法來解決問題,而大模型則能夠施展其高級的認(rèn)知優(yōu)勢,應(yīng)用更高階的技術(shù)。因此,思維鏈的認(rèn)知難度應(yīng)該與需要訓(xùn)練的學(xué)生模型大小相匹配。最終,我們可以根據(jù)目標(biāo)模型大小和問題難度,選擇合適的思維鏈用于蒸餾訓(xùn)練。
為了進(jìn)一步加強(qiáng)高質(zhì)量思維鏈數(shù)據(jù)對模型蒸餾的效果,我們采用DeepSeek-R1-0528作為教師模型,構(gòu)建了OmniThought數(shù)據(jù)的最新版本——OmniThought-0528。DeepSeek-R1-0528模型在數(shù)學(xué)、編程以及通用邏輯等多個測評基準(zhǔn)上表現(xiàn)優(yōu)異,整體表現(xiàn)接近國際頂尖模型。在本次的發(fā)布中,OmniThought-0528思維鏈的標(biāo)注標(biāo)準(zhǔn)與OmniThought原始數(shù)據(jù)集相同。
OmniThought-0528數(shù)據(jù)集已經(jīng)在Huggingface和ModelScope開源,包括36.5萬條思維鏈數(shù)據(jù)。數(shù)據(jù)格式如下,其中每條數(shù)據(jù)都包括一個問題(question),和至少2個思維鏈回答(reasoning),每個思維鏈都包含認(rèn)知難度(Cognitive_Difficulty)和推理冗余度(Reasoning_Verbosity)的評分,并且包含一個思維鏈回答(full_response):
{
"question": "TL;DR",
"reasoning": [
{
"Cognitive_Difficulty": {
"judge": "QwQ-32B",
"level": 6
},
"Reasoning_Verbosity": {
"judge": "QwQ-32B",
"level": 5
},
"full_response": "TL;DR"
},
{
"Cognitive_Difficulty": {
"judge": "QwQ-32B",
"level": 5
},
"Reasoning_Verbosity": {
"judge": "QwQ-32B",
"level": 5
},
"full_response": "TL;DR"
}
]
}
使用EasyDistill進(jìn)行思維鏈數(shù)據(jù)生成、評分
通過使用阿里云星空人工智能平臺(PAI)推出的新的開源工具包EasyDistill ,用戶可以輕松實(shí)現(xiàn)生成思維鏈數(shù)據(jù)、對思維鏈數(shù)據(jù)打分。
1. 克隆代碼庫,并安裝相關(guān)依賴:
git clone https://github.com/modelscope/easydistill
cd EasyDistill
pip install -r requirements.txt
2. 可以使用各種配置文件生成訓(xùn)練數(shù)據(jù),以思維鏈數(shù)據(jù)生成為例,配置文件如下:
{
"job_type": "cot_generation_api",
"dataset": {
"input_path": "./cot_question.json",
"output_path": "./cot_question_with_answer.json"
},
"inference":{
"base_url": "ENDPOINT",
"api_key": "TOKEN",
"stream": true,
"prompt" : "Your role as an assistant involves thoroughly exploring questions through a systematic long thinking process before providing the final precise and accurate solutions. This requires engaging in a comprehensive cycle of analysis, summarizing, exploration, reassessment, reflection, backtracing, and iteration to develop well-considered thinking process. Please structure your response into two main sections: Thought and Solution. In the Thought section, detail your reasoning process using the specified format: <|begin_of_thought|> {thought with steps separated with '\n\n'} <|end_of_thought|> Each step should include detailed considerations such as analisying questions, summarizing relevant findings, brainstorming new ideas, verifying the accuracy of the current steps, refining any errors, and revisiting previous steps. In the Solution section, based on various attempts, explorations, and reflections from the Thought section, systematically present the final solution that you deem correct. The solution should remain a logical, accurate, concise expression style and detail necessary step needed to reach the conclusion, formatted as follows: <|begin_of_solution|> {final formatted, precise, and clear solution} <|end_of_solution|> Now, try to solve the following question through the above guidelines:",
"max_new_tokens": 1024
}
}
3. 完成思維鏈數(shù)據(jù)生成后,可以使用思維鏈評價打分功能,配置文件如下:
{
"job_type": "cot_eval_api",
"dataset": {
"input_path": "cot_input.json",
"output_path": "cot_output.json"
},
"inference":{
"base_url": "ENDPOINT",
"api_key": "TOKEN",
"max_new_tokens": 8196
}
}
運(yùn)行下面的命令,即可完成對cot數(shù)據(jù)質(zhì)量的評價打分:
python .eval/data_eval.py --config .configs/cot_eval_api.json
DistillQwen-ThoughtY的模型訓(xùn)練
基于我們提出的OmniThought數(shù)據(jù)集及其擴(kuò)展版本OmniThought-0528數(shù)據(jù)集,我們訓(xùn)練了DistillQwen-ThoughtY系列模型,這一系列模型是對DistillQwen-ThoughtX系列模型的重大升級,主要體現(xiàn)在兩個方面:第一,模型基于Qwen3底座,分為4B、8B和32B三個參數(shù)量級,分別適配不用的使用和部署場景;第二,模型的訓(xùn)練數(shù)據(jù)集同時考慮了OmniThought和OmniThought-0528,同時融合了DeepSeek-R1、DeepSeek-R1-0528以及QwQ-32B這三個教師大模型的深度推理知識。在思維鏈篩選方面,同樣使用了基于OmniThought數(shù)據(jù)集的篩選方法(參考DistilQwen-ThoughtX:變長思維鏈推理模型,能力超越DeepSeek蒸餾模型)。
此外,為了保證模型盡可能從DeepSeek-R1-0528學(xué)習(xí)知識,我們規(guī)定數(shù)據(jù)集來源于兩個部分:1. 原始OmniThought數(shù)據(jù)集和2. OmniThought-0528思維鏈。在最終的方案中,我們并沒有完全使用來自DeepSeek-R1-0528的思維鏈而是采用混合的方式,因?yàn)殡m然DeepSeek-R1-0528整體表現(xiàn)較好,但在特定問題上,并非DeepSeek-R1-0528生成的思維鏈質(zhì)量最佳。相反,采用不同教師模型生成思維鏈并且篩選能取得更好的效果。
我們使用單機(jī)8卡(A800 80GB)進(jìn)行DistillQwen-ThoughtY-4B/8B的訓(xùn)練,使用4機(jī)32卡(A800 80GB)進(jìn)行DistillQwen-ThoughtY-32B的訓(xùn)練。默認(rèn)使用的學(xué)習(xí)率為5e-5,epoch為3,序列長度為8192,我們也嘗試了其他超參數(shù)的組合進(jìn)行模型優(yōu)化。我們從 Qwen3 系列底座(4B、8B和32B)初始化,訓(xùn)練三個模型,分別命名為 DistillQwen-ThoughtY-4B/8B/32B。數(shù)據(jù)組織的格式與Qwen3 系列的thinking模式相同。我們將我們的模型先前的DistillQwen-ThoughtX,DeepSeek蒸餾的R1模型進(jìn)行比較。結(jié)果表明,DistillQwen-ThoughtY 模型在數(shù)學(xué)、代碼等場景下的效果相比 Baseline 模型有明顯的提升,證明了 DistillQwen-ThoughtY 模型強(qiáng)悍的推理能力,以及蒸餾方法的有效性。
Model
AIME2024
MATH500
GPQA Diamond
LiveCodeBench V2
Avg.
4B量級
DistillQwen-ThoughtY-4B
76.7
95.2
56.1
75.8
76.0
7B/8B量級
DeepSeek-R1-Distill-Qwen-7B
57.3
89.6
47.3
48.4
60.6
OpenThinker2-7B
50.0
88.4
49.3
55.6
60.8
DistillQwen-ThoughtX-7B
56.7
90.2
50.0
56.8
63.4
DistillQwen-ThoughtY-8B
76.7
94.6
62.1
78.1
77.9
32B量級
DeepSeek-R1-Distill-Qwen-32B
74.7
90.0
62.4
72.3
74.8
OpenThinker2-32B
76.7
90.8
64.1
72.5
76.0
DistillQwen-ThoughtX-32B
80.0
92.6
64.0
73.4
77.5
DistillQwen-ThoughtY-32B
90.0
95.2
63.6
76.3
81.3
在下文中,我們描述如何使用EasyDistill框架進(jìn)行訓(xùn)練。
使用EasyDistill進(jìn)行思維鏈數(shù)據(jù)篩選和模型訓(xùn)練
在生成思維鏈數(shù)據(jù)和完成思維鏈打分后,我們需要對思維鏈進(jìn)行篩選,并將篩選出的思維鏈數(shù)據(jù)進(jìn)行模型訓(xùn)練。
1. 運(yùn)行下面的腳本篩選思維鏈數(shù)據(jù):
python ./recipes/distilqwen_series/distillqwen2.5-thoughtX/filter.py
2. 用篩選出的思維鏈數(shù)據(jù)進(jìn)行模型的訓(xùn)練,配置文件如下,可以按需更新配置文件并訓(xùn)練:
{
"job_type": "kd_black_box_local",
"dataset": {
"labeled_path": "train_labeled.json",
"template" : "./chat_template/chat_template_kd.jinja",
"seed": 42
},
"models": {
"student": "student/Qwen/Qwen2.5-0.5B-Instruct/"
},
"training": {
"output_dir": "./result/",
"num_train_epochs": 3,
"per_device_train_batch_size": 1,
"gradient_accumulation_steps": 8,
"max_length":512,
"save_steps": 1000,
"logging_steps": 1,
"learning_rate": 2e-5,
"weight_decay": 0.05,
"warmup_ratio": 0.1,
"lr_scheduler_type": "cosine"
}
}
訓(xùn)練腳本如下:
accelerate launch --num_processes n \
--config_file ./configs/train-config/muti_gpu.ymal ./easydistill/black-box/train.py \
--config ./configs/kd_black_box_local.json
模型和數(shù)據(jù)集下載和使用
DistillQwen-ThoughtY在開源社區(qū)的下載
我們在 Hugging Face 和 Model Scope 上開源了我們蒸餾后的模型,分別為DistillQwen-ThoughtY-4B、 DistillQwen-ThoughtY-8B、DistillQwen-ThoughtY-32B。以Hugging Face為例,用戶可以使用如下代碼下載這兩個模型:
from huggingface_hubimport snapshot_download
model_name = "alibaba-pai/DistillQwen-ThoughtY-4B"
snapshot_download(repo_id=model_name, cache_dir="./DistillQwen-ThoughtY-4B/")
model_name = "alibaba-pai/DistillQwen-ThoughtY-8B"
snapshot_download(repo_id=model_name, cache_dir="./DistillQwen-ThoughtY-8B/")
model_name = "alibaba-pai/DistillQwen-ThoughtY-32B"
snapshot_download(repo_id=model_name, cache_dir="./DistillQwen-ThoughtY-32B/")
以下給出一個ModelScope的使用示例:
from modelscope import AutoModelForCausalLM, AutoTokenizer
model_name = "pai/DistillQwen-ThoughtY-4B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto")
prompt = "Solve ∫x e^x dx. Show your reasoning step-by-step."
messages = [
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)
inputs = tokenizer([text], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=32768)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
OmniThought-0528數(shù)據(jù)集在開源社區(qū)的下載
我們在 HuggingFace和 ModelScope上開源了我們的數(shù)據(jù)集OmniThought-0528。用戶可以使用如下代碼下載這兩個模型:
from datasets import load_dataset
OmniThought = load_dataset("alibaba-pai/OmniThought-0528")
from modelscope.msdatasets import MsDataset
ds = MsDataset.load('PAI/OmniThought-0528')
DistillQwen-ThoughtY模型在PAI的使用
DistillQwen-ThoughtY模型已經(jīng)在PAI-Model Gallery中上線,使用方式可以參考:DistilQwen-ThoughtX 蒸餾模型在 PAI-ModelGallery 的訓(xùn)練、評測、壓縮及部署實(shí)踐。
可以點(diǎn)擊PAI-DistilQwen-ThoughtY查看模型詳情。
本文小結(jié)
近年來,大語言模型(LLM)推動了自然語言處理(NLP)的深刻變革,尤其在語言理解和推理任務(wù)方面取得重大進(jìn)展。然而,長思維鏈策略在某些任務(wù)中引發(fā)“過度思考”問題,影響了模型的響應(yīng)效率。阿里云PAI團(tuán)隊基于蒸餾工具包EasyDistill,推出了DistillQwen-ThoughtY系列模型基于更強(qiáng)的底座Qwen3和教師模型DeepSeek-R1-0528,顯著提升了數(shù)學(xué)、科學(xué)及代碼生成領(lǐng)域的表現(xiàn)。這些模型、蒸餾方法以及和相關(guān)數(shù)據(jù)集現(xiàn)已在EasyDistill中開源。在未來,我們將進(jìn)一步基于EasyDistill框架開源更多DistillQwen模型系列和相應(yīng)資源。歡迎大家加入我們,一起交流大模型蒸餾技術(shù)!
參考工作
相關(guān)論文
· Wenrui Cai, Chengyu Wang, Junbing Yan, Jun Huang, Xiangzhong Fang. Reasoning with OmniThought: A Large CoT Dataset with Verbosity and Cognitive Difficulty Annotations. arXiv preprint
· Chengyu Wang, Junbing Yan, Wenrui Cai, Yuanhao Yue, Jun Huang. EasyDistill: A Comprehensive Toolkit for Effective Knowledge Distillation of Large Language Models. arXiv preprint
· Wenrui Cai, Chengyu Wang, Junbing Yan, Jun Huang, Xiangzhong Fang. Training Small Reasoning LLMs with Cognitive Preference Alignment. arXiv preprint
· Chengyu Wang, Junbing Yan, Yuanhao Yue, Jun Huang. DistillQwen2.5: Industrial Practices of Training Distilled Open Lightweight Language Models. ACL 2025
· Yuanhao Yue, Chengyu Wang, Jun Huang, Peng Wang. Building a Family of Data Augmentation Models for Low-cost LLM Fine-tuning on the Cloud. COLING 2025
· Yuanhao Yue, Chengyu Wang, Jun Huang, Peng Wang. Distilling Instruction-following Abilities of Large Language Models with Task-aware Curriculum Planning. EMNLP 2024
技術(shù)介紹
· 阿里云星空人工智能平臺 PAI 開源 EasyDistill 框架助力大語言模型輕松瘦身
· DistillQwen-ThoughtX:變長思維鏈推理模型,能力超越DeepSeek蒸餾模型
· DistillQwen2:通義千問大模型的知識蒸餾實(shí)踐
· DistillQwen2.5發(fā)布:通義千問蒸餾小模型再升級
· DistillQwen2.5-R1發(fā)布:知識蒸餾助推小模型深度思考
· 星空人工智能平臺 PAI DistillQwen2.5-DS3-0324發(fā)布:知識蒸餾+快思考=更高效解決推理難題
· 基于多輪課程學(xué)習(xí)的大語言模型蒸餾算法TAPIR
聯(lián)系星空
星空人工智能技術(shù)網(wǎng) 倡導(dǎo)尊重與保護(hù)知識產(chǎn)權(quán)。如發(fā)現(xiàn)本站文章存在版權(quán)等問題,煩請30天內(nèi)提供版權(quán)疑問、身份證明、版權(quán)證明、聯(lián)系方式等發(fā)郵件至1851688011@qq.com我們將及時溝通與處理。!:首頁 > 星空人工智能產(chǎn)業(yè) > AI大模型 » DistillQwen-ThoughtY:通過變長思維鏈蒸餾,全面提升模型推理能力!