Compare commits

...

8 Commits

Author SHA1 Message Date
100apps 630501c585
Merge 68c00c22b0 into dddedc6881 2026-05-07 19:21:37 +08:00
100apps 68c00c22b0
Fix path separator in download command 2026-05-06 12:42:34 +08:00
100apps ebf36783b8 fix(eval_toolcall): 修复模型路径解析与加载问题
- 新增_resolve_path函数以支持绝对路径和相对路径解析
- 在init_model中改用_resolve_path处理load_from和save_dir路径
- 修正模型权重文件路径拼接方式,避免路径错误
- 保证模型加载时使用绝对路径,提高加载稳定性
- 使代码结构更清晰,增强路径处理的健壮性
2026-05-05 21:34:10 +08:00
100apps 7cf7881064 docs(readme): 优化已训练模型测试说明
- 增加已训练模型权重下载链接
- 提供下载命令示例,方便用户获取模型文件
- 明确文件存放目录,提升测试流程可操作性
2026-05-05 18:39:37 +08:00
100apps 509d2522ba docs(readme): 优化已训练模型测试说明
- 将模型文件位置说明调整为“确保待测试的模型 `*.pth` 文件位于 `./out/` 目录下”
- 将下载已训练好的模型权重说明标注为“(可选)”
- 调整命令块格式,提升文档清晰度和阅读体验
2026-05-05 18:37:38 +08:00
100apps 5fc34ff6c5 docs(readme): 补充模型权重下载命令示例
- 在 README.md 中添加使用 modelscope 下载权重的命令示例
- 提供了具体的命令行指令方便用户获取训练好的模型文件
- 优化文档的易用性,减少手动下载的操作步骤
- 保持原有评估命令示例不变,便于用户快速测试模型
2026-05-05 18:36:03 +08:00
100apps b9de7c17fb docs(readme): 优化数据集下载说明部分格式
- 在数据集下载链接说明中添加了bash代码块格式
- 补充了示例命令以指导数据集下载操作
- 保留原有说明,增强文档可读性与操作指引
- 修正了格式使内容更加清晰易懂
2026-05-05 17:47:14 +08:00
100apps 97903ffe56 chore(deps): 使用uv pyproject.toml替代requirements.txt管理依赖并增加vscode debug 配置,方便debug。
- 新增pyproject.toml文件,定义项目依赖和Python版本要求3.10
- 移除旧的requirements.txt文件,依赖迁移至pyproject.toml中
- 添加uv工具配置,支持依赖索引和同步管理
- 更新README文档中依赖安装指令,使用uv sync替代pip install
- 统一运行命令前添加uv run,提高一致性和环境隔离
- 在.gitignore中添加虚拟环境和缓存相关文件夹忽略规则
- 新增.python-version文件指定Python版本3.10
2026-05-05 15:26:33 +08:00
9 changed files with 2513 additions and 67 deletions

8
.gitignore vendored
View File

@ -4,3 +4,11 @@ __pycache__/
out out
website/ website/
docs-minimind/ docs-minimind/
minimind-3
dataset/**
!dataset/lm_dataset.py
!dataset/__init__.py
!dataset/dataset.md
checkpoints/
.venv/
.uv-cache/

1
.python-version Normal file
View File

@ -0,0 +1 @@
3.10

227
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,227 @@
{
// 使用 IntelliSense 了解可用属性。
// 悬停以查看现有属性的相关描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
//
// 使用说明:
// 1. 先执行 `uv sync` 安装依赖
// 2. 在 VS Code 中按 Ctrl+Shift+P → "Python: Select Interpreter"
// 选择 `./.venv/Scripts/python.exe` (Windows) 或 `./.venv/bin/python` (Linux/Mac)
// 3. 按 F5 或 Ctrl+Shift+D 选择对应配置启动调试
//
// 注:对应 README.md 中所有 `uv run python` / `uv run streamlit` 的单卡命令
// 多卡训练 (`torchrun`) 建议在终端直接执行,不在此列出
"version": "0.2.0",
"configurations": [
// ==================== 1. 推理与评测 ====================
{
"name": "推理: eval_llm (transformers格式)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/eval_llm.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--load_from", "./minimind-3"]
},
{
"name": "推理: eval_llm (pytorch格式)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/eval_llm.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--load_from", "./model", "--weight", "full_sft"]
},
{
"name": "推理: eval_llm (open_thinking)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/eval_llm.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--load_from", "./minimind-3", "--open_thinking", "1"]
},
{
"name": "推理: eval_llm (RoPE外推)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/eval_llm.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--weight", "full_sft", "--inference_rope_scaling"]
},
{
"name": "评测: eval_toolcall (full_sft)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/scripts/eval_toolcall.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--weight", "full_sft"]
},
{
"name": "评测: eval_toolcall (agent)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/scripts/eval_toolcall.py",
"cwd": "${workspaceFolder}",
"console": "integratedTerminal",
"args": ["--weight", "agent"]
},
// ==================== 2. WebUI 与服务 ====================
{
"name": "服务: WebUI (streamlit)",
"type": "debugpy",
"request": "launch",
"module": "streamlit",
"cwd": "${workspaceFolder}/scripts",
"console": "integratedTerminal",
"args": ["run", "web_demo.py"]
},
{
"name": "服务: OpenAI API Server",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/scripts/serve_openai_api.py",
"cwd": "${workspaceFolder}/scripts",
"console": "integratedTerminal"
},
{
"name": "服务: Chat API 测试",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/scripts/chat_api.py",
"cwd": "${workspaceFolder}/scripts",
"console": "integratedTerminal"
},
// ==================== 3. 预训练与微调 ====================
{
"name": "训练: Pretrain (预训练)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_pretrain.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "训练: Pretrain (断点续训)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_pretrain.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal",
"args": ["--from_resume", "1"]
},
{
"name": "训练: Full SFT (全参数微调)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_full_sft.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "训练: Full SFT (断点续训)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_full_sft.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal",
"args": ["--from_resume", "1"]
},
{
"name": "训练: LoRA",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_lora.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "训练: Distillation (知识蒸馏)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_distillation.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "训练: Tokenizer (分词器训练)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_tokenizer.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
// ==================== 4. 强化学习 ====================
{
"name": "RL: DPO",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_dpo.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "RL: PPO",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_ppo.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "RL: GRPO",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_grpo.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "RL: CISPO (GRPO变体)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_grpo.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal",
"args": ["--loss_type", "cispo"]
},
{
"name": "RL: Agentic RL",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_agent.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal"
},
{
"name": "RL: Agentic RL (SGLang)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/trainer/train_agent.py",
"cwd": "${workspaceFolder}/trainer",
"console": "integratedTerminal",
"args": [
"--rollout_engine", "sglang",
"--sglang_base_url", "http://localhost:8998",
"--sglang_shared_path", "./ckpt_mm",
"--data_path", "../dataset/agent_rl_math.jsonl",
"--use_wandb"
]
},
// ==================== 5. 工具与转换 ====================
{
"name": "工具: 模型转换",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/scripts/convert_model.py",
"cwd": "${workspaceFolder}/scripts",
"console": "integratedTerminal"
}
]
}

View File

@ -220,7 +220,7 @@ minimind2系列旧模型均经过权重映射+(微调训练)QKVO线性层校
* Ubuntu==20.04 * Ubuntu==20.04
* CUDA==12.2 * CUDA==12.2
* Python==3.10.16 * Python==3.10.16
* [requirements.txt](./requirements.txt) * [uv](https://docs.astral.sh/uv/) + [pyproject.toml](./pyproject.toml)
</details> </details>
@ -229,7 +229,8 @@ minimind2系列旧模型均经过权重映射+(微调训练)QKVO线性层校
```bash ```bash
# 克隆仓库、安装依赖 # 克隆仓库、安装依赖
git clone --depth 1 https://github.com/jingyaogong/minimind git clone --depth 1 https://github.com/jingyaogong/minimind
cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple cd minimind
uv sync
``` ```
## Ⅰ 🚀 模型推理 ## Ⅰ 🚀 模型推理
@ -239,7 +240,7 @@ cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pyp
在项目根目录: 在项目根目录:
```bash ```bash
# 方式1 # 方式1
modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3 uv run modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3
# 方式2 # 方式2
git clone https://huggingface.co/jingyaogong/minimind-3 git clone https://huggingface.co/jingyaogong/minimind-3
``` ```
@ -248,17 +249,17 @@ git clone https://huggingface.co/jingyaogong/minimind-3
```bash ```bash
# 方式1:使用 Transformers 格式模型 # 方式1:使用 Transformers 格式模型
python eval_llm.py --load_from ./minimind-3 uv run python eval_llm.py --load_from ./minimind-3
# 方式2:基于 PyTorch 模型(确保./out目录下有对应权重) # 方式2:基于 PyTorch 模型(确保./out目录下有对应权重)
python eval_llm.py --load_from ./model --weight full_sft uv run python eval_llm.py --load_from ./model --weight full_sft
``` ```
### 3'(可选)WebUI ### 3'(可选)WebUI
```bash ```bash
# 可能需要`python>=3.10`,安装 `pip install streamlit` # 使用 `uv sync` 安装依赖后即可运行
# ⚠️ 须先将 transformers 格式模型文件夹复制到 ./scripts/ 目录下(例如:cp -r minimind-3 ./scripts/minimind-3),web_demo 脚本会自动扫描该目录下包含权重文件的子文件夹,如不存在则报错 # ⚠️ 须先将 transformers 格式模型文件夹复制到 ./scripts/ 目录下(例如:cp -r minimind-3 ./scripts/minimind-3),web_demo 脚本会自动扫描该目录下包含权重文件的子文件夹,如不存在则报错
cd scripts && streamlit run web_demo.py cd scripts && uv run streamlit run web_demo.py
``` ```
### 4'(可选)第三方推理框架 ### 4'(可选)第三方推理框架
@ -282,7 +283,7 @@ print(torch.cuda.is_available())
若你计划使用 CUDA 训练,建议先确认当前环境是否已正确识别 GPU。 若你计划使用 CUDA 训练,建议先确认当前环境是否已正确识别 GPU。
若 `cuda` 不可用,也仍可根据自身设备选择 `CPU` 或 `MPS` 运行,但训练速度与兼容性会有非常大的差异。 若 `cuda` 不可用,也仍可根据自身设备选择 `CPU` 或 `MPS` 运行,但训练速度与兼容性会有非常大的差异。
如需安装或更换 PyTorch 版本,可参考 [torch_stable](https://download.pytorch.org/whl/torch_stable.html) 与[链接](https://blog.csdn.net/weixin_45456738/article/details/141029610?ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%AE%89%E8%A3%85torch&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-141029610.nonecase&spm=1018.2226.3001.4187) 默认 `pyproject.toml` 使用 PyTorch 官方 `cu128` wheel,可覆盖 Windows 11 + RTX 50 系显卡的常见 CUDA 运行环境;如需切换 CPU 或其它 CUDA 版本,请调整 `pyproject.toml` 中的 `pytorch-cu128` 索引与 `torch` / `torchvision` 版本后重新执行 `uv sync`。
</details> </details>
@ -291,7 +292,11 @@ print(torch.cuda.is_available())
从下文提供的[数据集下载链接](https://www.modelscope.cn/datasets/gongjy/minimind_dataset/files) 下载所需数据文件,并放入 `./dataset` 目录 从下文提供的[数据集下载链接](https://www.modelscope.cn/datasets/gongjy/minimind_dataset/files) 下载所需数据文件,并放入 `./dataset` 目录
> 当前默认仅需下载 `pretrain_t2t_mini.jsonl` 与 `sft_t2t_mini.jsonl`,即可较快复现 `MiniMind Zero` 对话模型。 > 当前默认仅需下载 `pretrain_t2t_mini.jsonl` 与 `sft_t2t_mini.jsonl`,即可较快复现 `MiniMind Zero` 对话模型。
如有更多需求,下文提供多种搭配方案,可根据自身任务目标与 GPU 资源灵活选择。
```bash
// (可选)如有更多需求,下文提供多种搭配方案,可根据自身任务目标与 GPU 资源灵活选择。
uv run modelscope download --dataset gongjy/minimind_dataset --local_dir ./dataset
```
### 2' 开始训练 ### 2' 开始训练
@ -301,8 +306,8 @@ print(torch.cuda.is_available())
所有训练脚本均支持检查点保存。添加 `--from_resume 1` 参数后,即可自动检测并恢复训练进度: 所有训练脚本均支持检查点保存。添加 `--from_resume 1` 参数后,即可自动检测并恢复训练进度:
```bash ```bash
python train_pretrain.py --from_resume 1 uv run python train_pretrain.py --from_resume 1
python train_full_sft.py --from_resume 1 uv run python train_full_sft.py --from_resume 1
# ... # ...
``` ```
@ -319,7 +324,7 @@ python train_full_sft.py --from_resume 1
#### 2.1 预训练(必须) #### 2.1 预训练(必须)
```bash ```bash
cd trainer && python train_pretrain.py cd trainer && uv run python train_pretrain.py
``` ```
> 训练后,将得到 `out/pretrain_*.pth` 作为输出权重(其中 `*` 为模型 dimension,默认为 `768`) > 训练后,将得到 `out/pretrain_*.pth` 作为输出权重(其中 `*` 为模型 dimension,默认为 `768`)
@ -327,17 +332,22 @@ cd trainer && python train_pretrain.py
#### 2.2 指令微调(必须) #### 2.2 指令微调(必须)
```bash ```bash
cd trainer && python train_full_sft.py cd trainer && uv run python train_full_sft.py
``` ```
> 训练后,将得到 `out/full_sft_*.pth` 作为输出权重(其中 `full` 表示全参数微调) > 训练后,将得到 `out/full_sft_*.pth` 作为输出权重(其中 `full` 表示全参数微调)
#### 2.3 测试已训练模型(可选) #### 2.3 测试已训练模型(可选)
确保待测试的模型 `*.pth` 文件位于 `./out/` 目录下;也可直接前往[此处](https://www.modelscope.cn/models/gongjy/minimind-3-pytorch/files)下载我已训练好的 `*.pth` 权重。 确保待测试的模型 `*.pth` 文件位于 `./out/` 目录下;也可直接前往[此处](https://www.modelscope.cn/models/gongjy/minimind-3-pytorch/files)下载我已训练好的 `*.pth` 权重
```bash ```bash
python eval_llm.py --weight full_sft // (可选) 下载已经训练好的模型
uv run modelscope download --model gongjy/minimind-3-pytorch --local_dir ./out
```
```bash
uv run python eval_llm.py --weight full_sft
``` ```
> `--weight` 用于指定权重名称前缀,例如 `pretrain`、`full_sft` 等;更多参数可直接参考 `eval_llm.py` > `--weight` 用于指定权重名称前缀,例如 `pretrain`、`full_sft` 等;更多参数可直接参考 `eval_llm.py`
@ -350,7 +360,7 @@ python eval_llm.py --weight full_sft
2、若你的设备有 `N (N > 1)` 张显卡,可通过以下方式启动单机 `N` 卡训练(DDP,也支持扩展到多机多卡): 2、若你的设备有 `N (N > 1)` 张显卡,可通过以下方式启动单机 `N` 卡训练(DDP,也支持扩展到多机多卡):
```bash ```bash
torchrun --nproc_per_node N train_xxx.py uv run torchrun --nproc_per_node N train_xxx.py
``` ```
3、可根据需要开启 wandb 记录训练过程。 3、可根据需要开启 wandb 记录训练过程。

View File

@ -219,7 +219,7 @@ After this update, maintenance for the entire `minimind-v1` series will be disco
* Ubuntu==20.04 * Ubuntu==20.04
* CUDA==12.2 * CUDA==12.2
* Python==3.10.16 * Python==3.10.16
* [requirements.txt](./requirements.txt) * [uv](https://docs.astral.sh/uv/) + [pyproject.toml](./pyproject.toml)
</details> </details>
@ -228,7 +228,8 @@ After this update, maintenance for the entire `minimind-v1` series will be disco
```bash ```bash
# Clone repository and install dependencies # Clone repository and install dependencies
git clone --depth 1 https://github.com/jingyaogong/minimind git clone --depth 1 https://github.com/jingyaogong/minimind
cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple cd minimind
uv sync
``` ```
## Ⅰ 🚀 Model Inference ## Ⅰ 🚀 Model Inference
@ -238,7 +239,7 @@ cd minimind && pip install -r requirements.txt -i https://mirrors.aliyun.com/pyp
In the project root directory: In the project root directory:
```bash ```bash
# Method 1 # Method 1
modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3 uv run modelscope download --model gongjy/minimind-3 --local_dir ./minimind-3
# Method 2 # Method 2
git clone https://huggingface.co/jingyaogong/minimind-3 git clone https://huggingface.co/jingyaogong/minimind-3
``` ```
@ -247,17 +248,17 @@ git clone https://huggingface.co/jingyaogong/minimind-3
```bash ```bash
# Method 1: Using Transformers format model # Method 1: Using Transformers format model
python eval_llm.py --load_from ./minimind-3 uv run python eval_llm.py --load_from ./minimind-3
# Method 2: Based on PyTorch model (ensure corresponding weights are in the ./out directory) # Method 2: Based on PyTorch model (ensure corresponding weights are in the ./out directory)
python eval_llm.py --load_from ./model --weight full_sft uv run python eval_llm.py --load_from ./model --weight full_sft
``` ```
### 3' (Optional) WebUI ### 3' (Optional) WebUI
```bash ```bash
# May need `python>=3.10`, install `pip install streamlit` # Run this after installing dependencies with `uv sync`
# ⚠️ You must first copy the transformers-format model folder into ./scripts/ (e.g.: cp -r minimind-3 ./scripts/minimind-3). The web_demo script will auto-scan subdirectories containing weight files; it will throw an error if none are found. # ⚠️ You must first copy the transformers-format model folder into ./scripts/ (e.g.: cp -r minimind-3 ./scripts/minimind-3). The web_demo script will auto-scan subdirectories containing weight files; it will throw an error if none are found.
cd scripts && streamlit run web_demo.py cd scripts && uv run streamlit run web_demo.py
``` ```
### 4' (Optional) Third-party Inference Frameworks ### 4' (Optional) Third-party Inference Frameworks
@ -281,7 +282,7 @@ print(torch.cuda.is_available())
If you plan to use CUDA for training, it is recommended to first confirm whether the current environment has correctly recognized the GPU. If you plan to use CUDA for training, it is recommended to first confirm whether the current environment has correctly recognized the GPU.
If `cuda` is not available, you can still choose `CPU` or `MPS` to run based on your device, but training speed and compatibility will differ significantly. If `cuda` is not available, you can still choose `CPU` or `MPS` to run based on your device, but training speed and compatibility will differ significantly.
If you need to install or switch PyTorch versions, refer to [torch_stable](https://download.pytorch.org/whl/torch_stable.html) and [this link](https://blog.csdn.net/weixin_45456738/article/details/141029610?ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%AE%89%E8%A3%85torch&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-2-141029610.nonecase&spm=1018.2226.3001.4187) By default, `pyproject.toml` uses the official PyTorch `cu128` wheels, which cover common CUDA runtime setups for Windows 11 + RTX 50-series GPUs. To switch to CPU or another CUDA version, adjust the `pytorch-cu128` index and the `torch` / `torchvision` versions in `pyproject.toml`, then run `uv sync` again.
</details> </details>
@ -300,8 +301,8 @@ For other use cases, several data combinations are provided below and can be sel
All training scripts support checkpoint saving. After adding the `--from_resume 1` parameter, the script will automatically detect and resume training progress: All training scripts support checkpoint saving. After adding the `--from_resume 1` parameter, the script will automatically detect and resume training progress:
```bash ```bash
python train_pretrain.py --from_resume 1 uv run python train_pretrain.py --from_resume 1
python train_full_sft.py --from_resume 1 uv run python train_full_sft.py --from_resume 1
# ... # ...
``` ```
@ -318,7 +319,7 @@ python train_full_sft.py --from_resume 1
#### 2.1 Pretraining (Required) #### 2.1 Pretraining (Required)
```bash ```bash
cd trainer && python train_pretrain.py cd trainer && uv run python train_pretrain.py
``` ```
> After training, `out/pretrain_*.pth` will be produced as output weights (where `*` is the model dimension, default `768`) > After training, `out/pretrain_*.pth` will be produced as output weights (where `*` is the model dimension, default `768`)
@ -326,7 +327,7 @@ cd trainer && python train_pretrain.py
#### 2.2 Instruction Fine-tuning (Required) #### 2.2 Instruction Fine-tuning (Required)
```bash ```bash
cd trainer && python train_full_sft.py cd trainer && uv run python train_full_sft.py
``` ```
> After training, `out/full_sft_*.pth` will be produced as output weights (where `full` indicates full-parameter fine-tuning) > After training, `out/full_sft_*.pth` will be produced as output weights (where `full` indicates full-parameter fine-tuning)
@ -336,7 +337,7 @@ cd trainer && python train_full_sft.py
Ensure the model `*.pth` files to be tested are located in the `./out/` directory; you can also go directly to [here](https://www.modelscope.cn/models/gongjy/minimind-3-pytorch/files) to download my pre-trained `*.pth` weights. Ensure the model `*.pth` files to be tested are located in the `./out/` directory; you can also go directly to [here](https://www.modelscope.cn/models/gongjy/minimind-3-pytorch/files) to download my pre-trained `*.pth` weights.
```bash ```bash
python eval_llm.py --weight full_sft uv run python eval_llm.py --weight full_sft
``` ```
> `--weight` is used to specify the weight name prefix, such as `pretrain`, `full_sft`, etc.; for more parameters, refer directly to `eval_llm.py` > `--weight` is used to specify the weight name prefix, such as `pretrain`, `full_sft`, etc.; for more parameters, refer directly to `eval_llm.py`
@ -349,7 +350,7 @@ python eval_llm.py --weight full_sft
2. If your device has `N (N > 1)` GPUs, you can start single-machine `N`-GPU training as follows (DDP, also supports extension to multi-machine multi-GPU): 2. If your device has `N (N > 1)` GPUs, you can start single-machine `N`-GPU training as follows (DDP, also supports extension to multi-machine multi-GPU):
```bash ```bash
torchrun --nproc_per_node N train_xxx.py uv run torchrun --nproc_per_node N train_xxx.py
``` ```
3. You can enable wandb to record the training process as needed. 3. You can enable wandb to record the training process as needed.

62
pyproject.toml Normal file
View File

@ -0,0 +1,62 @@
[project]
name = "minimind"
version = "0.1.0"
description = "MiniMind training and inference scripts."
readme = "README.md"
requires-python = ">=3.10,<3.11"
dependencies = [
"datasets==3.6.0",
"datasketch==1.6.4",
"einops==0.8.1",
"fastapi==0.115.14",
"flask==3.0.3",
"flask-cors==4.0.0",
"jieba==0.42.1",
"jinja2==3.1.2",
"jsonlines==4.0.0",
"marshmallow==3.22.0",
"modelscope>=1.36.3",
"ngrok==1.4.0",
"nltk==3.8",
"numpy==1.26.4",
"openai==1.59.6",
"psutil==5.9.8",
"pydantic==2.11.5",
"requests==2.32.5",
"rich==13.7.1",
"scikit-learn==1.5.1",
"sentence-transformers==2.3.1",
"setuptools>=82.0.1",
"simhash==2.1.2",
"streamlit==1.50.0",
"swanlab==0.7.11",
"tiktoken==0.10.0",
"tokenizers==0.22.1",
"torch==2.10.0",
"torchvision==0.25.0",
"transformers==4.57.6",
"trl==0.13.0",
"ujson==5.1.0",
"uvicorn==0.35.0",
"wandb==0.18.3",
]
[tool.uv]
package = false
[tool.uv.sources]
torch = [
{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
]
torchvision = [
{ index = "pytorch-cu128", marker = "sys_platform == 'win32' or sys_platform == 'linux'" },
]
[[tool.uv.index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
default = true
[[tool.uv.index]]
name = "pytorch-cu128"
url = "https://download.pytorch.org/whl/cu128"
explicit = true

View File

@ -1,32 +0,0 @@
datasets==3.6.0
datasketch==1.6.4
Flask==3.0.3
Flask_Cors==4.0.0
jieba==0.42.1
jsonlines==4.0.0
marshmallow==3.22.0
# matplotlib==3.10.0
ngrok==1.4.0
nltk==3.8
numpy==1.26.4
openai==1.59.6
# peft==0.7.1
psutil==5.9.8
pydantic==2.11.5
rich==13.7.1
scikit_learn==1.5.1
sentence_transformers==2.3.1
simhash==2.1.2
tiktoken==0.10.0
transformers==4.57.6
jinja2==3.1.2
jsonlines==4.0.0
trl==0.13.0
ujson==5.1.0
wandb==0.18.3
streamlit==1.50.0
einops==0.8.1
swanlab==0.7.11
modelscope==1.30.0
# torch==2.6.0
# torchvision==0.21.0

View File

@ -54,15 +54,27 @@ TEST_CASES = [
] ]
def _resolve_path(path):
if os.path.isabs(path):
return path
abs_path = os.path.abspath(path)
if os.path.isdir(abs_path):
return abs_path
script_dir = os.path.dirname(os.path.abspath(__file__))
return os.path.abspath(os.path.join(script_dir, path))
def init_model(args): def init_model(args):
tokenizer = AutoTokenizer.from_pretrained(args.load_from) load_path = _resolve_path(args.load_from)
tokenizer = AutoTokenizer.from_pretrained(load_path)
if 'model' in args.load_from: if 'model' in args.load_from:
model = MiniMindForCausalLM(MiniMindConfig(hidden_size=args.hidden_size, num_hidden_layers=args.num_hidden_layers, use_moe=bool(args.use_moe))) model = MiniMindForCausalLM(MiniMindConfig(hidden_size=args.hidden_size, num_hidden_layers=args.num_hidden_layers, use_moe=bool(args.use_moe)))
moe_suffix = '_moe' if args.use_moe else '' moe_suffix = '_moe' if args.use_moe else ''
ckp = f'./{args.save_dir}/{args.weight}_{args.hidden_size}{moe_suffix}.pth' save_dir = _resolve_path(args.save_dir)
ckp = os.path.join(save_dir, f'{args.weight}_{args.hidden_size}{moe_suffix}.pth')
model.load_state_dict(torch.load(ckp, map_location=args.device), strict=True) model.load_state_dict(torch.load(ckp, map_location=args.device), strict=True)
else: else:
model = AutoModelForCausalLM.from_pretrained(args.load_from, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained(load_path, trust_remote_code=True)
get_model_params(model, model.config) get_model_params(model, model.config)
return model.half().eval().to(args.device), tokenizer return model.half().eval().to(args.device), tokenizer

2157
uv.lock Normal file

File diff suppressed because it is too large Load Diff