MiniMind——跑通项目

文章目录

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-smallminimind-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
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值