RUC-GSAI/YuLan-Mini
关于
A highly capable 2.4B lightweight LLM using only 1T pre-training data with all details.
人工智能与机器学习可以做什么
- an elaborately designed data pipeline that combines data cleaning with data schedule strategies;
- a systematic optimization method that can effectively mitigate training instability;
- an effective annealing approach that integrate targeted data selection and long context training.
- Pre-train your own LLM. You can use our data and curriculum to train a model that's just as powerful as YuLan-Mini.
实测星标增长
- 24小时
- 0
- 7天
- -1
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README_zh.md
原文
YuLan-Mini 是一个 2.4B 参数量的轻量化语言模型。仅使用 1.08T Tokens 进行预训练,却达到了与使用更多数据的行业领先模型相媲美的性能,尤其是 数学 和 代码 两个领域。为方便复现,我们将开源相关预训练资源。
新闻
- [2025.01.29] YuLan-Mini-Instruct-v1 发布
- [2024.12.23] YuLan-Mini 及预训练资源发布
模型下载 🔗
YuLan-Mini 是 YuLan 系列 的一部分,该系列还包括更大规模和不同训练策略的模型。
| 模型 | 上下文长度 | SFT | 🤗 Hugging Face | ModelScope | Wise Model |
|---|---|---|---|---|---|
| YuLan-Mini | 28K | ❎ | Base |
Base |
Base |
| YuLan-Mini-Instruct | 28K | ✅ | Instruct |
中间检查点可以在这里找到。
能力介绍 🌟
我们的预训练方法通过以下三项关键技术改进提升了训练效率:
- 精细的数据处理流程,将数据清洗与数据课程策略相结合;
- 稳定的优化方法,有效缓解预训练中的不稳定性;
- 高效的退火策略,融合了目标数据选择和长上下文训练。
最终,使用我们的高效预训练策略,仅 1T 的数据量便可在数学和代码等领域,媲美 Qwen2.5-1.5B 在 18T 数据上的效果。我们将开源使用到的 1T 数据,其中指令数据仅占 3.5%。
基准测试 🌟
| Models | MMLU | CEVAL | GSM8K | ARC_CHALLENGE | GPQA | MATH | HUMANEVAL@1 | MBPP@1 |
|---|---|---|---|---|---|---|---|---|
| Qwen-2.5-1.5B-Instruct | 57.5 | 65.4 | 73.2 | 47.8 | 29.8 | 55.2 | 61.6 | 88.1 |
| Llama3.2-3B-Instruct | 60 | 45.9 | 43.4 | 78.6 | 38.6 | 48 | 51.5 | 80.4 |
| YuLan-Mini-Instruct | 53.6 | 50.5 | 82.3 | 51.8 | 30.1 | 55.2 | 67.7 | 85.7 |
注意:模型大小的计算包含了嵌入层(embedding)的大小。
| Models | Model Size | # Train Tokens | Context Length | MATH 500 | GSM 8K | Human Eval | MBPP | RACE Middle | RACE High | RULER |
|---|---|---|---|---|---|---|---|---|---|---|
| MiniCPM | 2.6B | 1.06T | 4K | 15.00 | 53.83 | 50.00* | 47.31 | 56.61 | 44.27 | N/A |
| Qwen-2 | 1.5B | 7T | 128K | 22.60 | 46.90* | 34.80* | 46.90* | 55.77 | 43.69 | 60.16 |
| Qwen2.5 | 0.5B | 18T | 128K | 23.60 | 41.60* | 30.50* | 39.30* | 52.36 | 40.31 | 49.23 |
| Qwen2.5 | 1.5B | 18T | 128K | 45.40 | 68.50* | 37.20* | 60.20* | 58.77 | 44.33 | 68.26 |
| Gemma2 | 2.6B | 2T | 8K | 18.30* | 30.30* | 19.50* | 42.10* | - | - | N/A |
| StableLM2 | 1.7B | 2T | 4K | - | 20.62 | 8.50* | 17.50 | 56.33 | 45.06 | N/A |
| SmolLM2 | 1.7B | 11T | 8K | 11.80 | - | 23.35 | 45.00 | 55.77 | 43.06 | N/A |
| Llama3.2 | 3.2B | 9T | 128K | 7.40 | - | 29.30 | 49.70 | 55.29 | 43.34 | 77.06 |
| YuLan-Mini | 2.4B | 1.04T | 4K | 32.60 | 66.65 | 61.60 | 66.70 | 55.71 | 43.58 | N/A |
| YuLan-Mini | 2.4B | 1.08T | 28K | 37.80 | 68.46 | 64.00 | 65.90 | 57.18 | 44.57 | 51.48 |
| Models | LAMBADA | MMLU | CMMLU | CEval | HellaSwag | WinoGrande | StoryCloze | ARC-e | ARC-c |
|---|---|---|---|---|---|---|---|---|---|
| MiniCPM-2.6B | 61.91 | 53.37 | 48.97 | 48.24 | 67.92 | 65.74 | 78.51 | 55.51 | 43.86 |
| Qwen2-1.5B | 64.68 | 55.90 | 70.76 | 71.94 | 66.11 | 66.14 | 77.60 | 62.21 | 42.92 |
| Qwen2.5-0.5B | 52.00 | 47.50 | 52.17 | 54.27 | 50.54 | 55.88 | 71.67 | 56.10 | 39.51 |
| Qwen2.5-1.5B | 62.12 | 60.71 | 67.82 | 69.05 | 67.18 | 64.48 | 76.80 | 71.51 | 53.41 |
| Gemma2-2.6B | - | 52.20* | - | 28.00* | 74.60* | 71.50* | - | - | 55.70* |
| StableLM2-1.7B | 66.15 | 40.37 | 29.29 | 26.99 | 69.79 | 64.64 | 78.56 | 54.00 | 40.78 |
| SmolLM2-1.7B | 67.42 | 51.91 | 33.46 | 35.10 | 72.96 | 67.40 | 79.32 | 44.82 | 35.49 |
| Llama3.2-3B | 69.08 | 63.40 | 44.44 | 44.49 | 75.62 | 67.48 | 76.80 | 70.12 | 48.81 |
| YuLan-Mini | 64.72 | 51.79 | 48.35 | 51.47 | 68.65 | 67.09 | 76.37 | 69.87 | 50.51 |
| YuLan-Mini | 65.67 | 49.10 | 45.45 | 48.23 | 67.22 | 67.24 | 75.89 | 67.47 | 49.32 |
预训练资源 🔧
为了提高研究的透明度和可复现性,我们开源了相关的预训练资源:
预训练
1. 预训练和评估代码
预训练代码可以在这里找到。请注意,由于后续的代码修改,此代码可能无法直接运行,可能需要进行一些调整。
步骤 1:修改 config.json
由于 Hugging Face Trainer 的实现,某些参数存储在 config.json 文件中,无法通过 Trainer 的命令行参数进行修改。因此,您需要首先更新 config.json 文件中的这些参数,特别是:
save_steps:保存中间检查点的频率。train_batch_size:每个 GPU 的批大小(相当于 Trainer 中的per_device_train_batch_size)。在稳定训练阶段,我们使用了 1008 的批大小(大约 4M 个 token)。保持相同的批大小对于训练效果同样重要。
以下是一个正确配置的 config.json 文件示例:
{
"best_metric": null,
"best_model_checkpoint": null,
"epoch": 0.0,
"eval_steps": 500,
"global_step": 0,
"is_hyper_param_search": false,
"is_local_process_zero": true,
"is_world_process_zero": true,
"log_history": [],
"logging_steps": 3,
"max_steps": 0,
"num_input_tokens_seen": 0,
"num_train_epochs": 0,
"save_steps": 250,
"stateful_callbacks": {
"TrainerControl": {
"args": {
"should_epoch_stop": false,
"should_evaluate": false,
"should_log": false,
"should_save": true,
"should_training_stop": true
},
"attributes": {}
}
},
"total_flos": 0,
"train_batch_size": 3,
"trial_name": null,
"trial_params": null
}
步骤 2:在 DeepSpeed 配置中启用通用检查点
为了确保 DeepSpeed 集成加载通用检查点,您需要在 DeepSpeed 配置 JSON 文件中启用此功能。
以下是一个启用了通用检查点的 ZeRO2 配置示例:
{
"bf16": {
"enabled": "auto"
},
"zero_optimization": {
"stage": 2,
"allgather_partitions": true,
"allgather_bucket_size": 8e8,
"overlap_comm": true,
"reduce_scatter": true,
"reduce_bucket_size": 8e8,
"contiguous_gradients": true
},
"gradient_accumulation_steps": "auto",
"gradient_clipping": "auto",
"steps_per_print": 16,
"train_batch_size": "auto",
"train_micro_batch_size_per_gpu": "auto",
"wall_clock_breakdown": false,
"dump_state": true,
"optimizer": {
"type": "AdamW",
"params": {
"lr": "auto",
"betas": "auto",
"eps": "auto",
"weight_decay": "auto"
}
},
"checkpoint": {
"load_universal": true
}
}
步骤 3:恢复训练
调用 trainer.train 时,包含 resume_from_checkpoint 参数以从通用检查点加载分布式优化器状态并恢复训练。
trainer.train(resume_from_checkpoint=training_args.resume_from_checkpoint)
我们提供了一个内部训练框架供您参考,但您可以自由选择其他框架。
2. 中间阶段检查点
中间阶段检查点发布在 YuLan-Mini 中。| 阶段 | 课程阶段 | 4K 上下文 | 28K 上下文 | 优化器 | 推理架构 | LAMBADA Acc |
GSM8K Acc |
HumanEval pass@1 |
|---|---|---|---|---|---|---|---|---|
| 稳定 | 5 | YuLan-Mini-Phase5 | yulanmini |
53.85 | 3.41 | 12.26 | ||
| 稳定 | 10 | YuLan-Mini-Phase10 | yulanmini |
55.00 | 9.57 | 15.95 | ||
| 稳定 | 15 | YuLan-Mini-Phase15 | yulanmini |
55.81 | 13.81 | 16.99 | ||
| 稳定 | 20 | YuLan-Mini-Phase20 | ✅ | yulanmini |
55.81 | 21.39 | 20.79 | |
| 稳定 | 25 (1T tokens) | YuLan-Mini-Before-Annealing | ✅ | yulanmini |
55.67 | 29.94 | 34.06 | |
| 退火 | 26 | YuLan-Mini-4K | llama* |
64.72 | 66.65 | 61.60 | ||
| 退火 | 27 | YuLan-Mini | llama* |
65.67 | 68.46 | 64.00 |
*:为了更容易推理和部署,我们将重新参数化的附加参数和缩放因子合并到最终发布的模型中 (YuLan-Mini 和 YuLan-Mini-Intermediate-4K),使其能够在 Llama 架构上运行。但是,这些参数仍然保留在训练过程的中间检查点中。
3. 退火前的优化器状态
数据集
4. 使用的开源数据集
您可以使用这些预训练资源做什么
- 预训练您自己的 LLM。您可以使用我们的数据和课程来训练一个与 YuLan-Mini 一样强大的模型。
- 执行您自己的学习率退火。在退火阶段,YuLan-Mini 的学习能力达到顶峰。您可以从退火前的检查点恢复训练,并使用您自己的数据集进行学习率退火。
- 微调 LLM 的 Instruct 版本。您可以使用 YuLan-Mini 基础模型来训练您自己的 Instruct 版本。
- 训练动态研究。您可以使用 YuLan-Mini 的中间检查点来探索预训练过程中的内部变化。
- 合成您自己的数据。您可以使用 YuLan-Mini 的数据流程来清理和生成您自己的数据集。
快速开始 💻
以下是使用 Huggingface 的简单推理代码示例:
Huggingface 推理示例
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("yulan-team/YuLan-Mini-Instruct")
model = AutoModelForCausalLM.from_pretrained("yulan-team/YuLan-Mini-Instruct", torch_dtype=torch.bfloat16)
# Input text
chat = [
{"role": "system", "content": "You are YuLan-Mini, created by RUC AI Box. You are a helpful assistant."},
{"role": "user", "content": "What is Renmin University of China?"}
]
formatted_chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(formatted_chat, return_tensors="pt", add_special_tokens=False)
# Completion
output = model.generate(inputs["input_ids"], max_new_tokens=100, temperature=0.5)
print(tokenizer.decode(output[0][inputs['input_ids'].size(1):], skip_special_tokens=True))
vLLM部署示例
vllm serve yulan-team/YuLan-Mini-Instruct --dtype bfloat16
SGLang部署示例
python -m sglang.launch_server --model-path yulan-team/YuLan-Mini-Instruct --port 30000 --host 0.0.0.0
Ollama部署示例
ollama run hf.co/mradermacher/YuLan-Mini-Instruct-GGUF:IQ4_XS
贡献
我们欢迎任何形式的贡献,包括模型错误案例的反馈、功能建议和示例贡献。您可以通过提交issue来贡献。
许可协议
- 本仓库代码使用 MIT License。
- 局限性:尽管我们尝试减少模型在使用中可能出现的安全性问题,并鼓励模型生成符合道德和法律要求的文本,但由于语言模型基于概率生成的范式,模型仍然可能会产生意外的输出。例如,生成的响应可能包含偏见、歧视或其他有害内容。请不要传播此类内容。我们对因传播有害信息而造成的任何后果不承担任何责任。
引用
如果您发现 YuLan-Mini 对您的研究或开发有帮助,请引用我们的技术报告:
@article{hu2024yulan,
title={YuLan-Mini: An Open Data-efficient Language Model},
author={Hu, Yiwen and Song, Huatong and Deng, Jia and Wang, Jiapeng and Chen, Jie and Zhou, Kun and Zhu, Yutao and Jiang, Jinhao and Dong, Zican and Zhao, Wayne Xin and others},
journal={arXiv preprint arXiv:2412.17743},
year={2024}
}
探索相关项目
加载中…