文章目录
- 📌 Quick Start Train
MiniMind (ModelScope)
# step 1
git clone https://huggingface.co/jingyaogong/minimind-v1
# step 2
python 2-eval.py
或者启动streamlit,启动网页聊天界面
「注意」需要python>=3.10,安装
pip install streamlit==1.27.2
# or step 3, use streamlit
streamlit run fast_inference.py
📌 Quick Start Train
-
0、克隆项目代码
git clone https://github.com/jingyaogong/minimind.git cd minimind
-
1、环境安装
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
# 测试torch是否可用cuda import torch print(torch.cuda.is_available())
如果不可用,请自行去torch_stable
下载whl文件安装。参考链接 -
2、如果你需要自己训练
-
2.1 下载数据集下载地址放到
./dataset
目录下 -
2.2
python data_process.py
处理数据集,例如pretrain数据提前进行token-encoder、sft数据集抽离qa到csv文件 -
2.3 在
./model/LMConfig.py
中调整model的参数配置这里仅需调整dim和n_layers和use_moe参数,分别是
(512+8)
或(768+16)
,对应于minimind-v1-small
和minimind-v1
-
2.4
python 1-pretrain.py
执行预训练,得到pretrain_*.pth
作为预训练的输出权重 -
2.5
python 3-full_sft.py
执行指令微调,得到full_sft_*.pth
作为指令微调的输出权重 -
2.6
python 4-lora_sft.py
执行lora微调(非必须) -
2.7
python 5-dpo_train.py
执行DPO人类偏好强化学习对齐(非必须)
-
-
3、测试模型推理效果
- 确保需要使用的,训练完成的参数权重
*.pth
文件位于./out/
目录下 - 也可以直接去训练完成的模型权重下载使用我训练好的
*.pth
权重文件minimind/out ├── multi_chat │ ├── full_sft_512.pth │ ├── full_sft_512_moe.pth │ └── full_sft_768.pth ├── single_chat │ ├── full_sft_512.pth │ ├── full_sft_512_moe.pth │ └── full_sft_768.pth ├── pretrain_768.pth ├── pretrain_512_moe.pth ├── pretrain_512.pth
python 0-eval_pretrain.py
测试预训练模型的接龙效果python 2-eval.py
测试模型的对话效果
- 确保需要使用的,训练完成的参数权重
🍭「Tip」预训练和全参微调pretrain和full_sft均支持多卡加速
假设你的设备只有1张显卡,使用原生python启动训练即可:
- 执行预训练或指令微调训练
python 1-pretrain.py # and python 3-full_sft.py