-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[feat /train] 增加一键启动多机多卡分布式训练shell #7333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
liangxiaoyun
wants to merge
2
commits into
modelscope:main
Choose a base branch
from
liangxiaoyun:qwen_train
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||||||||||||||||||
| # ms-swift 训练框架 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 大语言模型训练框架,支持 deepspeed 和 Megatron 并行技术。[官方说明](https://swift.readthedocs.io/zh-cn/v3.7/index.html) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 安装 | ||||||||||||||||||||||
| 参考wiki文档:【Megatron-swift 环境安装】(https://iwiki.woa.com/p/4016971017) | ||||||||||||||||||||||
| pip install -e . | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 参数说明 | ||||||||||||||||||||||
| | 参数 | 是否必须 | 默认值 | 说明 | | ||||||||||||||||||||||
| |------|----------|--------|------| | ||||||||||||||||||||||
| | `--ips` | 是 | - | 分布式训练的节点IP地址列表,多个IP用逗号分隔 | | ||||||||||||||||||||||
| | `--ssh_password` | 是 | - | 分布式训练的节点的帐户密码 | | ||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| | `--save` | 是 | - | 模型checkpoint保存路径 | | ||||||||||||||||||||||
| | `--dataset` | 是 | - | 训练数据集路径,支持jsonl格式 | | ||||||||||||||||||||||
| | `--port` | 否 | `29500` | 分布式通信端口号 | | ||||||||||||||||||||||
| | `--micro_bs` | 否 | `8` | 微批次大小(Micro Batch Size),单个GPU单次前向的样本数 | | ||||||||||||||||||||||
| | `--global_bs` | 否 | `64` | 全局批次大小(Global Batch Size),所有GPU累计的总样本数 | | ||||||||||||||||||||||
| | `--tensor_model_parallel_size` | 否 | `8` | 张量并行度(TP),将模型参数在层内切分到多个GPU | | ||||||||||||||||||||||
| | `--context_parallel_size` | 否 | `4` | 上下文并行度(CP),将长序列切分到多个GPU处理 | | ||||||||||||||||||||||
| | `--max_length` | 否 | `64000` | 最大序列长度,单位为token | | ||||||||||||||||||||||
| | `--epochs` | 否 | `1` | 训练轮数 | | ||||||||||||||||||||||
| | `--save_interval` | 否 | `50` | 保存checkpoint的间隔步数 | | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 🚀 快速开始 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 1. qwen3-32B Agent SFT | ||||||||||||||||||||||
| 4*8 GPUS, 建议:(tp,cp,dp) = (8,4,1) | ||||||||||||||||||||||
| 8*8 GPUS, 建议:(tp,cp,dp) = (8,8,1) | ||||||||||||||||||||||
| 12*8 GPUS, 建议:(tp,cp,dp) = (8,4,3) | ||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||
| # 4*8 GPUS 训练任务启动示例脚本 | ||||||||||||||||||||||
| bash Qwen3_32B_agent_sft.sh \ | ||||||||||||||||||||||
| --ips "10.0.8.7,10.0.8.8,10.0.8.9,10.0.8.11" \ | ||||||||||||||||||||||
| --ssh_password "<PASSWORD>" \ | ||||||||||||||||||||||
| --save /path/to/output \ | ||||||||||||||||||||||
| --dataset /path/to/jsonl \ | ||||||||||||||||||||||
| --port 29900 \ | ||||||||||||||||||||||
| --micro_bs 8 \ | ||||||||||||||||||||||
| --global_bs 64 \ | ||||||||||||||||||||||
| --tensor_model_parallel_size 8 \ | ||||||||||||||||||||||
| --context_parallel_size 4 \ | ||||||||||||||||||||||
| --max_length 64000 \ | ||||||||||||||||||||||
| --epochs 1 \ | ||||||||||||||||||||||
| --save_interval 50 | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 2. qwen2.5-72B Agent SFT | ||||||||||||||||||||||
| 4*8 GPUS, 建议:(tp,cp,dp) = (8,4,1) | ||||||||||||||||||||||
| 8*8 GPUS, 建议:(tp,cp,dp) = (8,8,1) | ||||||||||||||||||||||
| 12*8 GPUS, 建议:(tp,cp,dp) = (8,4,3) | ||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||
| # 8*8 GPUS 训练任务启动示例脚本 | ||||||||||||||||||||||
| bash Qwen2.5_72B_agent_sft.sh \ | ||||||||||||||||||||||
| --ips "10.0.8.7,10.0.8.8,10.0.8.9,10.0.8.11" \ | ||||||||||||||||||||||
| --ssh_password "<PASSWORD>" \ | ||||||||||||||||||||||
| --save /path/to/output \ | ||||||||||||||||||||||
| --dataset /path/to/jsonl \ | ||||||||||||||||||||||
| --port 29900 \ | ||||||||||||||||||||||
| --micro_bs 4 \ | ||||||||||||||||||||||
| --global_bs 32 \ | ||||||||||||||||||||||
| --tensor_model_parallel_size 8 \ | ||||||||||||||||||||||
| --context_parallel_size 8 \ | ||||||||||||||||||||||
| --max_length 64000 \ | ||||||||||||||||||||||
| --epochs 1 \ | ||||||||||||||||||||||
| --save_interval 50 | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## ⚙️更多Megatron并行参数配置说明 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| 参考 [wiki](https://iwiki.woa.com/p/4016813135) | ||||||||||||||||||||||
| - 建议开启 flash_attn 和 SP; | ||||||||||||||||||||||
| - 建议 CP > 1,否则相当于同时关闭了 CP 和 SP; | ||||||||||||||||||||||
| - 优先开 TP,剩下的余量,如果剩余显存空间较多,用 DP 或使用 CP + 高 Batch_Size (长窗口下建议优先 DP,超大LLM 建议优先 CP),如果剩余显存空间较少,可以尽量提高 CP,提高效率; | ||||||||||||||||||||||
| - QWEN3-32B 在 16 GPU 情况下,最佳参数组合:MBS=4,TP=8,CP=2,DP=1,训练效率为 2828 token/s,2w数据预计训练5天; | ||||||||||||||||||||||
| - QWEN2.5-72B-Instruct 在 32 GPU 情况下,最佳参数组合:MBS=1,TP=8,CP=4,DP=1,训练效率为 2884 token/s,2w数据预计训练5天; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 📊 数据格式 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### SFT Agent 数据格式 | ||||||||||||||||||||||
| ```json | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| "id": str "数据唯一ID", | ||||||||||||||||||||||
| "tools": List[Dict[str, Any]] 工具列表, | ||||||||||||||||||||||
| "messages": List[Dict[str, str]] 对话列表, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+83
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处提供的 JSON 示例格式不正确,混合了 Python 类型提示和中文描述,无法被解析。这可能会误导需要准备数据的用户。建议提供一个真实、有效的 JSON 数据示例,以帮助用户理解所需的数据结构。
Suggested change
|
||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## 🛠️ 工具使用 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 1. 模型转换(HF → Megatron)模型 | ||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||
| bash tools/export_hf_2_megatron_model.sh | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 2. 模型转换(Megatron → HF)模型 | ||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||
| bash tools/export_megatron_2_hf_model.sh | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### 3. 查看训练日志 | ||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||
| tensorboard --logdir /path/to/output/runs | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markdown 链接语法有误。括号应使用半角括号
()而不是全角括号(),否则链接无法正确解析。