-
Notifications
You must be signed in to change notification settings - Fork 448
[Feature] Add Checkpoint Engine as a transport between train and rollout #1993
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b13aa1c
add checkpoint-engine transport for sglang
PengchengShi00 869c23e
fix bug when sglang ep>1 and support P2P update in checkpoint-engin
PengchengShi00 7cdf564
Fix MTP config in unit test
PengchengShi00 29b91c4
Fix bug: weight update flow when skip_load_weights
PengchengShi00 a4d1bcf
register tensor in cpu to reduce GPU memory
PengchengShi00 f7c5d4a
add checkpoint-engine[p2p] dependency in pyproject.toml
PengchengShi00 a2dcdcc
fix clear flush in profile memory and fix checkpoint-engine bug
PengchengShi00 6ad708c
rename update_weights to weight_update
PengchengShi00 1c7a850
fix checkpoint engine weight transport setup
PengchengShi00 47b6232
add checkpoint-engine transport for sglang
PengchengShi00 749f5cf
Fix bug: weight update flow when skip_load_weights
PengchengShi00 0fde44d
fix clear flush in profile memory and fix checkpoint-engine bug
PengchengShi00 8e3d62a
rename update_weights to weight_update
PengchengShi00 7365e47
fix checkpoint engine weight transport setup
PengchengShi00 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,85 @@ | ||
| # checkpoint-engine | ||
|
|
||
| ## 简介和安装 | ||
|
|
||
| [checkpoint-engine](https://github.com/MoonshotAI/checkpoint-engine) 是 Moonshot AI 开源的权重更新中间件,用于在 RL 训练中把训练侧权重高效同步到推理引擎。它的核心组件是 `ParameterServer`,支持两种更新方式: | ||
|
|
||
| - **Broadcast**:默认推荐路径,适合同步更新一组推理实例。 | ||
| - **P2P**:适合动态新增或重启推理实例时,只向部分 rank 传输权重,依赖 `mooncake-transfer-engine` 支持 RDMA 传输。 | ||
|
|
||
| 安装方式: | ||
|
|
||
| ```bash | ||
| # 只使用 broadcast | ||
| pip install checkpoint-engine | ||
|
|
||
| # 使用 P2P,会额外安装 mooncake-transfer-engine | ||
| pip install 'checkpoint-engine[p2p]' | ||
| ``` | ||
|
|
||
| ## 进度 | ||
|
|
||
| - [ x ] checkpoint-engine colocate SGLang engine 的常规权重更新 | ||
| - [ ] checkpoint-engine colocate SGLang engine 的失败引擎重启 | ||
| - [ ] checkpoint-engine colocate LMDeploy engine 的权重更新 | ||
|
|
||
| ## xtuner中使用方法 | ||
|
|
||
| 当前 XTuner 中 checkpoint-engine 只用于 colocate 场景下的 SGLang rollout backend。配置 rollout 时设置: | ||
|
|
||
| ```python | ||
| rollout_config = RolloutConfig( | ||
| weight_transport_type="checkpoint_engine", | ||
| ) | ||
| ``` | ||
| 如未设置 `weight_transport_type`,colocate-RL将默认使用 `ipc`,disaggerated-RL默认使用 `NCCL`。 | ||
|
|
||
| 权重更新流程分为两步: | ||
|
|
||
| ```python | ||
| self.train_controller.update_weights(need_register=True, need_update=False) | ||
| self.train_controller.offload(target="model") | ||
| ray.get(self.rollout_controller.onload_weights.remote(), timeout=RL_TRAINER_RAY_GET_TIMEOUT) | ||
| self.train_controller.update_weights(need_register=False, need_update=True) | ||
| ``` | ||
|
|
||
| 其中: | ||
|
|
||
| - `need_register=True, need_update=False`:从训练引擎收集权重并注册到 checkpoint-engine。 | ||
| - `offload(target="model")`:释放训练侧模型显存,为 rollout onload/update 腾空间。 | ||
| - `need_register=False, need_update=True`:复用已注册 checkpoint,把权重更新到 rollout engine。 | ||
|
|
||
| ## IPC/Checkpoint-engine显存和时间对比 | ||
|
|
||
| IPC 路径直接把 tensor 通过 IPC 传给 rollout engine,链路较短,通常延迟更低,但在大模型和复杂并行场景下更容易受显存峰值影响。 | ||
|
|
||
| checkpoint-engine 路径会先把训练侧权重注册到 `ParameterServer`,再由 checkpoint-engine 规划 bucket 并更新 rollout engine。它的好处是更适合大模型、分片权重和失败 engine 恢复;代价是会有一份模型 shard 常驻 CPU Memory,并且 D2H copy、bucket broadcast 会引入额外时间。 | ||
|
|
||
| 如果只需要在 `ParameterServer.register_checkpoint` 后显式等待一次 accelerator 侧异步操作完成,可以设置: | ||
|
|
||
| ```python | ||
| rollout_config = RolloutConfig( | ||
| weight_transport_type="checkpoint_engine", | ||
| checkpoint_engine_sync_after_register=True, | ||
| ) | ||
| ``` | ||
|
|
||
| 该选项默认关闭,profile memory 发现,显式同步会释放掉 GPU 上的 tensor, 在注册时需要等 H2D 完成,而不显式同步,能更快的完成权重更新。 | ||
|
|
||
| 权重更新的显存峰值: | ||
|
|
||
| - IPC:trian worker weight + rollout worker weight + bucket | ||
|
|
||
| - checkpoint-engine(checkpoint_engine_sync_after_register=False):max(trian worker weight + parameter server shard, rollout worker weight + buffer *2) | ||
|
|
||
| - 可以优化降低成:max(trian worker weight + bucket, rollout worker weight + buffer *2),但这会影响性能 | ||
| - parameter server shard 指将完整权重分成若干份,每一份的大小 | ||
|
|
||
| - 这里 bucket 和 buffer 含义不同, bucket是train engine 一次导出的一个batch的权重大小, checkpoint-engine的buffer最小为单个权重的最大大小,该值默认为 8 GiB。 | ||
|
|
||
|
|
||
| ## debug小tips | ||
|
|
||
| - OOM:先看各 rank 的 checkpoint shard 是否划分均匀。日志中已打印 `[checkpoint_engine] collect matched local keys rank=xx parameter server shard total= xxx GiB ` | ||
| - register 后显存不降:可将`checkpoint_engine_sync_after_register=True` 打开,注册后即可释放注册所需GPU memory。 | ||
|
|
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
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
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
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
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
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
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
Oops, something went wrong.
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.
可以同时升级下必须的sglang的版本,现在写的是 0.5.3
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.
我还没跑高版本的sglang,用ray传输expert index用的版本是
sglang==0.5.15.post1,写这个版本吗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.
我担心0.5.3不支持checkpoint engine,那就用0.5.15.post1吧
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.
我测试用的sglang版本是0.5.10