69 lines
2.6 KiB
Markdown
69 lines
2.6 KiB
Markdown
|
||
---
|
||
license: mit
|
||
library_name: transformers
|
||
base_model:
|
||
- flylcw/seq_monkey_pretrain_base_1.5B
|
||
language:
|
||
- zh
|
||
tags:
|
||
- qwen2
|
||
- qwen
|
||
- sft
|
||
- instruction-tuning
|
||
- chinese
|
||
- chat
|
||
datasets:
|
||
- BelleGroup/train_3.5M_CN
|
||
- m-a-p/COIG-CQIA
|
||
---
|
||
|
||
# seq_monkey_pretrain_sft_optimization_1.5B(中文指令微调模型)
|
||
|
||
在 [seq_monkey_pretrain_base_1.5B](https://huggingface.co/flylcw/seq_monkey_pretrain_base_1.5B) 之上,经过 **两阶段全参 SFT** 得到的中文指令对话模型:第一阶段用 BelleGroup 通用指令数据建立指令跟随能力,第二阶段用 COIG-CQIA 高质量数据进一步对齐。
|
||
|
||
## 模型结构(与 Base 完全一致)
|
||
|
||
**SFT 仅更新权重,不改变模型架构**,因此本模型的 `config.json` 与 Base 模型**完全相同**:
|
||
|
||
| 项目 | 值 |
|
||
|---|---|
|
||
| 架构 | Qwen2ForCausalLM |
|
||
| 参数量 | 1.5B 级(HF 统计约 2B) |
|
||
| hidden / layers / heads / kv_heads | 1536 / 28 / 12 / 2 |
|
||
| intermediate / vocab / max_pos | 8960 / 151936 / 131072 |
|
||
| 激活 / 归一化 / 位置编码 | SiLU(SwiGLU) / RMSNorm / RoPE |
|
||
|
||
|
||
## 两阶段 SFT 流程
|
||
|
||
| 阶段 | 数据 | 规模 | 学习率 | epoch | 目的 |
|
||
|---|---|---|---|---|---|
|
||
| 阶段一 | [BelleGroup/train_3.5M_CN](https://huggingface.co/datasets/BelleGroup/train_3.5M_CN) | 3.5M 中文指令 | 2e-5 | 3 | 建立通用指令跟随 |
|
||
| 阶段二 | [m-a-p/COIG-CQIA](https://huggingface.co/datasets/m-a-p/COIG-CQIA) | 数万条高质量中文指令 | 5e-6 | 3 | 高质量对齐、提升回答质量 |
|
||
|
||
- **训练方式**:全参 SFT(非 LoRA),Causal LM,仅对 assistant 回答部分计算 loss
|
||
- **对话模板**:Qwen ChatML(`<|im_start|> / <|im_end|>`)
|
||
- **序列长度**:1024
|
||
- **优化**:bf16,cosine 学习率调度
|
||
- **第二阶段说明**:在阶段一 checkpoint 基础上继续 SFT,学习率调小以防破坏已学能力
|
||
|
||
|
||
## 快速开始(对话)
|
||
|
||
```python
|
||
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||
import torch
|
||
|
||
name = "flylcw/seq_monkey_pretrain_sft_optimization_1.5B"
|
||
tok = AutoTokenizer.from_pretrained(name, trust_remote_code=True)
|
||
model = AutoModelForCausalLM.from_pretrained(
|
||
name, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
|
||
|
||
messages = [{"role": "user", "content": "用三句话介绍一下序列猴子数据集"}]
|
||
text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
||
ids = tok(text, return_tensors="pt").to(model.device)
|
||
out = model.generate(**ids, max_new_tokens=256, do_sample=True,
|
||
temperature=0.7, top_p=0.9, repetition_penalty=1.1)
|
||
print(tok.decode(out[0], skip_special_tokens=True))
|