一邑狸、關(guān)于中文DeepSeek-R1(滿血)蒸餾數(shù)據(jù)集
1.1 數(shù)據(jù)集概況
近期诡必,劉聰NLP開源了開源中文DeepSeek-R1(滿血)蒸餾數(shù)據(jù)集蒿赢,其中包括SFT版本润樱。基于滿血DeepSeek-R1蒸餾的中文數(shù)據(jù)集-110k-SFT地址如下:
https://modelscope.cn/datasets/liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT
1.2 開源此數(shù)據(jù)集初衷
DeepSeek-R1的效果十分強(qiáng)大羡棵,并且基于R1蒸餾數(shù)據(jù)SFT的小模型也展現(xiàn)出了強(qiáng)大的效果壹若,但目前我們發(fā)現(xiàn),大部分開源的R1蒸餾數(shù)據(jù)集均為英文數(shù)據(jù)集皂冰。同時店展,R1的報告中展示,蒸餾模型中同時也使用了部分通用場景數(shù)據(jù)集秃流,來保障訓(xùn)練中不丟失通用能力赂蕴。為了幫助大家更好地復(fù)現(xiàn)R1蒸餾模型的效果,特此開源中文數(shù)據(jù)集舶胀。
1.3 數(shù)據(jù)分布情況
該中文數(shù)據(jù)集中的數(shù)據(jù)分布如下:
? Math:共計36568個樣本睡腿,
? Exam:共計2432個樣本,
? STEM:共計12648個樣本峻贮,
? General:共計58352,包含弱智吧应闯、邏輯推理纤控、小紅書、知乎碉纺、Chat等
1.4 數(shù)據(jù)樣例及蒸餾過程
同時為了方便大家溯源船万,在每條數(shù)據(jù)的repo_name字段中都加入的原始數(shù)據(jù)源repo刻撒。數(shù)據(jù)示例:在蒸餾過程中,按照DeepSeek-R1官方提供的細(xì)節(jié)耿导,進(jìn)行數(shù)據(jù)蒸餾声怔。
? 不增加額外的系統(tǒng)提示詞
? 設(shè)置temperature為0.6
? 如果為數(shù)學(xué)類型數(shù)據(jù),則增加提示詞舱呻,“請一步步推理醋火,并把最終答案放到 \boxed{}∠渎溃”
? 防止跳出思維模式芥驳,強(qiáng)制在每個輸出的開頭增加"\n",再開始生成數(shù)據(jù)茬高。
二兆旬、蒸餾實踐
下面介紹基于蒸餾數(shù)據(jù)訓(xùn)練Qwen2.5-1.5B過程。
ms-swift已經(jīng)接入了中文基于滿血DeepSeek-R1蒸餾數(shù)據(jù)集怎栽,通過指定--dataset liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT
即可選擇該數(shù)據(jù)集進(jìn)行訓(xùn)練丽猬。ms-swift是魔搭社區(qū)官方提供的大模型與多模態(tài)大模型訓(xùn)練部署框架。
ms-swift開源地址:https://github.com/modelscope/ms-swift
本章將展示使用ms-swift對該數(shù)據(jù)集進(jìn)行SFT熏瞄。在開始訓(xùn)練之前脚祟,請先安裝ms-swift:
# pip install git+https://github.com/modelscope/ms-swift.git
git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .
微調(diào)腳本如下,我們隨機(jī)抽樣數(shù)據(jù)集中的1800條進(jìn)行訓(xùn)練:
nproc_per_node=2
CUDA_VISIBLE_DEVICES=0,1 \
NPROC_PER_NODE=$nproc_per_node \
swift sft \
--model Qwen/Qwen2.5-1.5B \
--train_type full \
--dataset 'liucong/Chinese-DeepSeek-R1-Distill-data-110k-SFT#1800' \
--torch_dtype bfloat16 \
--num_train_epochs 10 \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1 \
--learning_rate 1e-5 \
--gradient_accumulation_steps $(expr 16 / $nproc_per_node) \
--eval_steps 200 \
--save_steps 200 \
--save_total_limit 5 \
--logging_steps 5 \
--max_length 8192 \
--output_dir output \
--warmup_ratio 0.05 \
--dataloader_num_workers 4 \
--deepspeed zero2
訓(xùn)練顯存占用:(訓(xùn)練時長:40分鐘)
推理腳本如下巴刻,需要將--model
替換成訓(xùn)練產(chǎn)生的last checkpoint文件夾:
# pip install vllm -U
CUDA_VISIBLE_DEVICES=0 \
swift infer \
--model output/vx-xxx/checkpoint-xxx \
--stream true \
--infer_backend vllm \
--max_model_len 8192 \
--max_new_tokens 2048 \
--temperature 0.3
推送到ModelScope:
swift export \
--model output/vx-xxx/checkpoint-xxx \
--push_to_hub true \
--hub_model_id '<your-model-id>' \
--hub_token '<your-sdk-token>'
訓(xùn)練效果:(有部分內(nèi)容省略)