Skip to content

feat(hybrid): 通过 DCS 同步权重并支持弹性 Rollout - #554

Merged
RexFlux merged 6 commits into
redai-studio:mainfrom
RexFlux:feat/hybrid-dcs-elastic-rollout
Nov 10, 2026
Merged

RexFlux merged 6 commits into
redai-studio:mainfrom
RexFlux:feat/hybrid-dcs-elastic-rollout

Conversation

@RexFlux

@RexFlux RexFlux commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

  • 将 Hybrid 模式的 Actor→Rollout 权重同步切换为 DCS,使扩容和重建后注册到 DCS 的引擎能够参与后续权重广播。
  • DCS 从 actor 快照读取权重,保留 Megatron TP 元数据和 Bridge 的 PP/VP 全局名称映射;新增 --hybrid-weights-backuper-on-gpu,允许在显存充足时将 actor 快照常驻 GPU,默认仍保存在主机内存。
  • 统一各训练 rank 的接收端拓扑与量化权重加载生命周期;评估只保留完整 prompt 分组,并记录有效覆盖率。
  • 增加 Hybrid 弹性 Rollout recipe、权重行为对比工具、回归测试及中英文文档。

Why

Hybrid 原先通过 UpdateWeightFromTensor 推送权重,未复用 Fully Async 已有的 DCS 弹性拓扑和恢复后发布路径。训练模型还会在 actor、reference、actor_fwd 等角色之间切换,因此同步必须读取固定的 actor 快照;快照若丢失 TP 属性,会把分片误当成复制权重。

本 PR 迁移源提交 55d145f31d4ee2c52574d313626e11f776ecba19 相对第一父提交的净改动。该提交是 merge commit,因此采用第一父提交作为 mainline 提取功能增量,并在 GitHub 当前主线上解决冲突。

How

  • Hybrid 初始化 DCS client 时注入 actor snapshot getter;快照保留 TP 属性,CPU→GPU 搬运继续传递这些属性,Bridge 模式将本地名称映射到全局名称并保留原 Parameter 的同步资格。
  • 初始化和每步权重更新恢复训练状态及进程组,在 DCS push 期间禁用 offloader 的临时分配跟踪,并在 finally 中恢复 offload;成功同步后推进 old_actor 队列。GPU 快照按 device/dtype 复用连续 buffer。
  • rank 0 持有同步锁后,所有 rank 再读取同一份广播拓扑;量化权重的 restore、post-process 与 continue 操作等待完成,并将错误传播到所有训练 rank。
  • 保留 GitHub 主线的 score-centering 初始化、resident-SFT flush/快照优化、DCS 分桶及锁释放修复。训练后快照更新沿用现有 helper,仅在该 helper 中适配 GPU 快照选项。
  • 兼容性变化:Hybrid 不再接受 --disable-weights-backuper,同用时启动即报错。评估按原始 prompt 边界过滤缺失、aborted 或无 reward 的组,避免跨 prompt 计算 pass@k,并上报总数、有效数和 coverage。
  • 修复 Hybrid + Bridge + Qwen4Exp PLE 在 TP>1 时的 DCS collective 不匹配:PLE 在普通 TP gather 前分流,所有 TP rank 用局部行消费 iter_ple_shards,仅源 rank 逐片发布,Hybrid 不聚合整张 PLE 表。actor_fwd/ref 的原始 Megatron 权重协议继续保留;未配齐的 fused pair 跨分片保留,导出中断时显式关闭迭代器。
  • 新 recipe 使用 MODEL_DIR、DATA_DIR、SAVE_DIR,以稳定的 ${SAVE_DIR}/${EXP_NAME} 保存和恢复,保留两个 checkpoint;默认启用 ClearML,Ray 提交默认阻塞。

Testing

当前 head:8179ec87ecfd816ffeb486918f235b1b8516036a。两条评审修复提交为 77adc136;随后同步 main@957b4180 消除新产生的合并冲突,保留主线 MOPD teacher response 统计收尾与本 PR 的评估完整组保护。两条修复的生产代码与回归测试在同步主线前后无差异。

同步后的扩展 CPU 回归:497 passed、3 subtests passed、10 skipped,涵盖下述 401 项回归及新增 MOPD、checkpoint/SFT 相关检查。全仓 pre-commit、PR 增量 diff 检查与独立合并审查通过。新提交的 CI 以当前 head 的检查记录为准;当前 head 已补充完成下述 4×B300 GPU/NCCL 定向复测,历史完整训练证据仍绑定原 SHA。

2026-11-10 当前 head 的补充 GPU 验收:4×B300,真实 NCCL,TP2×DP2 与 PP2×TP2 均通过(PyTorch 2.11.0+cu130、CUDA 13.0、NCCL 2.28.9)。

  • 运行真实 PLENGramEmbeddingMapping、BridgeConverter、生产 DCS 分发与实际 Megatron stage/TP 进程组。目标镜像缺少 Qwen4Exp Bridge 模块,完整模块从当前提交跟踪的 patch 原样还原到独立 overlay,未修改已安装依赖;生产源码、patch、overlay 和实际导入路径均按 SHA256 核对。
  • TP2×DP2 的 4 个 rank 各完成 40 个正常组合/更新 + 12 个故障场景;PP2×TP2 的 PLE stage(全局 rank 2/3,source=2)各完成相同矩阵,另一 stage 的 rank 0/1 不进入 PLE,正常退出。上述数量按参与 rank 统计。
  • FP32/BF16、task/registry 两种查找路径、五种发送/跳过组合、同一对象连续两次不同权重更新均通过。12×2 小表拆为三个 HF 分片,中间分片跨 TP 边界;分片与 raw 完整表按原始 tensor 字节精确比对,Hybrid 不触发完整 PLE gather,仅源 rank 发布。
  • 分别在 preflush、raw 发送、首个 HF 分片发送时注入接收错误:源 rank 保留原异常,stage 内 peers 收到同一故障,首分片失败后不进入第二分片,迭代器关闭并恢复映射 group。没有 collective timeout;每次异常后同一发送端对象能重新完成一次新同步。
  • 两次分布式运行均退出 0,8 份 rank 结果文件全部通过,独立只读复核未发现阻断。为使文件与缓存局限于专用可写目录,关闭 NCCL SHM/cuMem host/NVLS,仍使用真实 CUDA/NCCL;此轮不作性能结论。
  • 本次证明的是 PLE 发送端分片与异常协调。任务发现和接收端仍为测试替身;未加载完整 Qwen4Exp,未验证真实 SGLang RPC、部分加载后的接收端恢复、进程死亡、致命 NCCL 故障、多节点、CP>1、大表显存或训练效果,也未重复扩缩容。既有完整训练结果仍按下方历史 SHA 记录。

2026-11-10 评审修复:提交 77adc136e8b6ff9238b2a682896cf498d6e16476 处理两条新反馈,保留当前单 PR 交付。

  • PLE 发送失败传播:preflush、raw 发送和每个 HF shard 发送均在下一次数据 collective 前,将源 rank 的结果广播给同一 PP stage 内全部 TP×DP×CP rank。复用现有 stage 进程组,不引入全局逐分片 fence;源 rank 保留原异常,其他成员收到明确错误,组内成员一致退出,并关闭已打开的分片迭代器,避免下一分片等待已退出的源 rank。
  • 跳过同步后的评估:Hybrid readiness/握手失败、未发布新权重时,不再调度当前训练步评估;metrics flush、barrier 和 /end_update_weight 清理仍执行。正常评估的 finally 复用同一清理 helper。
  • 新增故障回归在修复前得到 5 failed、4 passed,修复后定向回归 43 passed。四进程真实 Gloo 测试分别覆盖 TP2×DP2 的 peer 通知、PP2×TP2 中仅非零 PP stage 参与的 source rank=2,以及 preflush/raw/首 shard 三个失败边界;断言明确错误传播、没有请求下一分片、迭代器清理。扩展现有 Hybrid lifecycle 用例,确认两步训练在握手失败时零发布、零评估且两次结束握手。
  • 相关 CPU 回归:401 passed、3 subtests passed、10 skipped;10 项仍因本机缺少 Qwen4Exp Bridge 模块跳过,不计为通过。全仓 pre-commit、diff 检查及独立只读审查通过。四进程是同时覆盖 DP peers 与不同 PP 局部序列所需的最小拓扑,测试有 collective 和外层进程超时,并只清理本次子进程。
  • 当时的 CPU 回归使用小型分片转换器及接收端故障夹具,生产 DCS 分发和 Gloo 数据/控制 collective 真实执行。后续 GPU/NCCL 补充验收见上;不声明进程死亡、致命 NCCL 故障恢复或不同 PP 同点退出。既有 GPU 验证仍按下方原 SHA 记录。本次 required CI 以同步主线后的当前 head 为准。

2026-11-09 rebase 记录:提交 9a46e17133781b0533c00581fececc9e97fc982e 已基于最新 main(1bec680c)重新整理。评估分组冲突保留主线的 early return 和 OPD helper,并保留本 PR 对评估 aborted 分组的完整性保护;主线 observability 改动完整保留,PLE/DCS/快照实现相对 rebase 前未变。

本次隐藏 GPU 的相关 CPU 回归:383 passed,3 subtests passed,10 skipped。覆盖 Hybrid 生命周期/参数、DCS/PLE、resident SFT、评估分组与 coverage、OPD 和 observability 隔离。10 项因本地缺少 Qwen4Exp Bridge 模块而跳过,未计为通过。全仓 pre-commit、git diff --check、启动脚本 bash 语法检查均通过;独立只读审查未发现 rebase 引入的阻断问题。

上述 rebase 的 CI 状态为历史记录;当前检查以本次评审修复的 head 为准。本次未重新占用 GPU 或运行集群训练;下方既有 GPU 证据仍按原 SHA 记录,不能视为新提交的重新实测结果。

本次评审修复的 CPU 定向回归:65 passed,10 skipped,隐藏 GPU 执行,全仓 pre-commit run --all-files --show-diff-on-failure 通过。新增 3 个回归在修复前均失败;其中双进程用例明确阻止旧路径对 PLE 先做整表 gather,修复后全部通过。

  • 新用例直接运行生产 DCS 分发方法,启动两个 CPU/Gloo 进程,使用真实 all_gather/all_reduce,校验 TP 局部输入、三个 HF 分片的精确数值、逐片发送、连续两次更新,以及 Hybrid、raw+HF、raw-only 和 LoRA 跳过基础权重的调用方式。另覆盖 pending fused pair 保留/字节数及发送失败后的迭代器关闭。
  • 转换器使用轻量协议 fixture,接收端发送被替代;本机缺少 megatron.bridge.models.qwen.qwen4_exp_bridge,真实映射相关 10 项因此跳过,未计为验证通过。本地 CPU 轮次未覆盖 GPU/NCCL;后续定向 GPU 验证见下。真实 Qwen4Exp 整模型和多 rank 异常恢复仍未验证;raw actor_fwd/ref 路径仍保留整表 gather 的原有内存限制。
CUDA_VISIBLE_DEVICES='' python -m pytest -q -rs \
  tests/cpu/distributed/checkpoint_service/test_dcs_ple_weight_sync.py \
  tests/cpu/distributed/checkpoint_service/test_weights_getter.py \
  tests/cpu/distributed/checkpoint_service/test_weight_sync_lifecycle.py \
  tests/cpu/distributed/checkpoint_service/test_dcs_fused_weight_buckets.py \
  tests/cpu/backends/megatron/test_hybrid_weight_sync_lifecycle.py \
  tests/cpu/backends/megatron/weight_update/test_bridge_ple_shards.py \
  tests/cpu/backends/megatron/weight_update/test_bridge_ple_async_gather.py \
  tests/cpu/backends/megatron/weight_update/test_bridge_converter_collectives.py

补充在提交 15beb12c 上完成 2×H20、真实 TP2/NCCL 的 PLE 定向验证(PyTorch 2.11.0+cu129、CUDA 12.9、NCCL 2.28.9):

  • 目标镜像缺少 Qwen4Exp Bridge 模块,因此从本提交跟踪的依赖 patch 还原完整模块,放入独立验证目录加载;未修改镜像依赖。记录实际 mapping、BridgeConverter、DCS handler 的导入路径及 SHA256,核对源码一致。该模块环境下此前跳过的 10 个 PLE 映射 CPU 用例 10 passed。
  • 使用真实 PLENGramEmbeddingMapping、BridgeConverter.iter_ple_shards、生产 DCS 分发方法及 NCCL collective。两个 rank 各完成 40 组组合/更新检查:FP32/BF16、直接 task 与 registry fallback、五种消费者/基础权重跳过标志、同一 mapping/converter/backend 连续两次不同权重。小表拆成三个分片,中间分片横跨 TP 行归属边界;逐元素精确一致,HF-only 无整表 gather,raw 消费者协议保留,仅源 rank 发布,正常结束及一致提前关闭后映射 group 恢复。
  • 验证 Job 成功退出,独立检查无本次遗留探针进程;测试后恢复 GPU 保活,8 个 Actor 存活且心跳增长,三轮共 24 个物理 GPU 利用率采样均为 100%,无 pending resource demand。
  • 本轮 task-map 初始化与接收端为测试夹具,验证范围是 真实 PLE 映射 → DCS 分发 → TP2 NCCL 分片导出。未加载完整 Qwen4Exp,未验证 AutoBridge 自动任务发现、真实 SGLang 接收传输、PP/DP>1、巨表显存峰值或多 rank 异常恢复;未运行扩缩容或效果回测。

以下为本次 PLE 修复之前的迁移验证,不能代替当前修复的真实 Qwen4Exp/GPU 验收。

在基线 551c4ff4dd598def1842e26147e125ece764e15c 上完成迁移,并在隐藏 GPU 的环境运行相关回归:242 passed,3 subtests passed,11 skipped。跳过项需要真实 CUDA,用于快照分配、pinned memory、设备同步和 H2D 搬运;未将这些 skip 计为验证通过。

覆盖 Hybrid 参数、初始化/连续训练/offload/checkpoint 后同步、拓扑与接收端错误传播、完整评估组、恢复引擎注册、权重行为比较工具,并复用 resident-SFT、DCS 分桶、初始权重同步及自动权重同步回归。新增测试用于防止权重来源、TP 属性和同步生命周期退化;不启动 Ray 集群或分布式 GPU 进程。

CUDA_VISIBLE_DEVICES='' python -m pytest -q \
  tests/cpu/utils/test_arguments_hybrid.py \
  tests/cpu/distributed/checkpoint_service/test_weight_sync_lifecycle.py \
  tests/cpu/distributed/checkpoint_service/test_weights_getter.py \
  tests/cpu/backends/megatron/test_hybrid_weight_sync_lifecycle.py \
  tests/cpu/engine/rollout/test_weight_sync_499.py \
  tests/cpu/tools/test_elastic_weight_fingerprint.py \
  tests/cpu/utils/test_metric_utils_rloo.py \
  tests/cpu/distributed/ray/test_recovered_engine_registration.py \
  tests/cpu/backends/megatron/test_resident_sft_param_sync.py \
  tests/cpu/distributed/checkpoint_service/test_dcs_fused_weight_buckets.py \
  tests/cpu/core/test_initial_weight_sync.py \
  tests/cpu/backends/megatron/weight_update/test_auto_weight_sync.py \
  tests/distributed/checkpoint_service/test_weights_getter.py \
  tests/utils/training/test_tensor_backper.py
pre-commit run --all-files
bash -n examples/elastic_rollout/run-qwen3-4B-8xgpu-elastic-hybrid.sh

CI 发现既有 score-centering 手写配置 fixture 缺少 parser 默认提供的 enable_weights_backuper 字段;已补齐该默认值,保持运行时校验不变。相关 score-centering、Hybrid 和 RLOO 参数回归共 65 passed,全仓 pre-commit 再次通过。

另外通过重复定义检查、Ruff F811、git diff --check 和新增内容的内部链接/私有路径检查;独立只读审查未发现阻断问题。

rebase 前提交 15beb12c 的六项 required CI 均通过:CPU Unit Tests、4×H20 Unit Tests、pre-commit、Qwen3-4B Async GPU/NPU,以及 Qwen3-VL GPU 集成。此前手写 fixture 的失败已修复并重新通过。

另在单节点 8×H20、真实 Qwen3-4B、Actor TP2×DP2 上执行定向回归:

  • GPU 快照分配、pinned memory、设备同步与 H2D 相关单测 11 passed,无 skip。
  • CPU actor 快照模式(真实 GPU 训练):开启训练 offload,LR=1e-4、entropy_coef=0.01、KL_coef=0.01,完成 16 步并成功退出。独立审计 51 项通过,16 步指标有限;四次 eval 各 4 prompt×2 样本、coverage=1;checkpoint 7/15 保存完成,common state、Adam 元数据及所有引用文件范围可读。
  • 真实 2→3→2 Rollout 扩缩容完成,原两台引擎身份保留;新增引擎的种子权重探针对齐后,收到后续 actor DCS 广播。冻结版本 1→6 的同版本引擎探针逐 token 一致。排除观察探针的同 PID 窗口内,自然请求计数 +8、生成 token +1024,另有版本 4 下成功生成 128 token 的自然训练请求日志佐证。
  • 固定 3 条探针、共 22 个有效输入 token 的初始 logprob,与旧路径基准差异为 0。此项仅覆盖这些探针,不能外推完整权重或训练轨迹等价。
  • GPU 常驻 actor 快照模式在 LR=1e-5 下完成验收:开启训练 offload,16 步训练与观察任务均成功退出,四次 eval 均完整覆盖,两份 checkpoint 完成相同的落盘/元数据检查。4 rank×16 步共 64 条 KL 诊断记录的输入、输出均有限,max(reference_logprob - policy_logprob)=26.5826,未出现 float32 exp 溢出输入。诊断 hook 只读取 detached 数值并原样调用生产损失,包含额外设备同步,因此此轮不作性能结论。
  • 保留的失败与边界:GPU 常驻模式在 LR=1e-4 时前两步完成,第三步反向传播出现 NaN 梯度,实际根因未确定。生产 compute_approx_kl(low_var_kl) 存在先 exp 再 clamp 的可达反向 NaN 反例,但缺少原失败 batch 的极值证据,不能将该失败精确归因于此,也不能声称已修复。CPU/GPU 两轮学习率不同,不构成相同训练轨迹的 A/B 对比。

简单算术样本曾出现等额 GRPO 奖励、零梯度,因此验证配方启用标准熵正则,以实际 optimizer 更新、live sampled hash 和发布后数值变化为验收条件。两种模式的四次短 eval 均限制输出 64 token,观测 reward=-1、truncated_ratio=1;这里只验收完整分组、覆盖率及生命周期,不能视为业务效果回测通过。本轮是权重同步/生命周期验证,不证明原零 entropy 配方的学习效果或收敛。旧路径基准仅采集 optimizer 前的初始状态,关闭旧源 train offload;未比较完整训练轨迹。

未单独运行完整 pytest tests/ 命令;未验证多节点、PP/VP、MoE、FP8/量化、LoRA、故障注入或 checkpoint resume。checkpoint 审计只证明落盘与元数据/引用范围可读,不能称为恢复训练通过。未构建 VitePress 文档站点,本地未安装文档构建依赖。最终独立审计共 93 项通过。合入仍需维护者审查。高学习率 GPU 轮次的未归因 NaN 保留为独立训练数值问题,不在本 PR 的 Hybrid + DCS 修复范围内。

  • pre-commit run --all-files passes
  • Tests pass (pytest tests/)
  • New tests added (if applicable)
  • Documentation updated (if applicable)

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • CI/CD or build changes

Screenshots / Logs

Current-head B300 NCCL (8179ec87): TP2xDP2 passed; PP2xTP2 passed
Per active rank: 40 success + 12 injected-failure cases; raw tensor bytes exact
Final main merge (8179ec87): 497 passed, 10 skipped, 3 subtests passed
Review fixes (77adc136): 401 passed, 10 skipped, 3 subtests passed
Four-process Gloo fault regression: passed
Rebase CPU regression (9a46e171): 383 passed, 10 skipped, 3 subtests passed
PLE fix CPU regression: 65 passed, 10 skipped
Target-image mapping regression with tracked module overlay: 10 passed
PLE TP2 NCCL GPU probe: passed, 40 cases/updates per rank
Historical migration regression: 242 passed, 11 skipped, 40 warnings, 3 subtests passed
pre-commit: all hooks passed, including gitleaks
check_duplicate_defs: checked 20 Python files
Ruff F811: all checks passed
bash -n: passed
This PR is co-authored with @codex (GPT-6)

@rai-studio-bot

rai-studio-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for contributing to Relax, @RexFlux! 感谢你为 Relax 做出贡献!

📚 Contribution guide / 贡献指南

Describe the problem, your changes, and how you validated them. Keep each PR focused and run pre-commit run --all-files before submitting.

请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 pre-commit run --all-files。

English contribution guide · 中文贡献指南

🛠️ CI commands / CI 指令
Command / 指令 Usage / 用途
/rerun Retry failed CI / 重跑失败的 CI
/rerun <target> Rerun a workflow or check / 重跑指定 workflow 或检查
/cancel <workflow> Cancel an entire workflow / 取消整个 workflow
/help Show commands and targets / 查看指令和 target
/review Request a code review / 请求代码 review

Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access.

在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。

CI usage and targets · CI 用法与 target

🔎 Merge requirements / 合入条件

GitHub:✅ 满足合入条件

Requirement / 条件 Status / 状态
审批人数 ✅ 1/1 · 至少 1 位有仓库 write 或更高权限的人 Approve · 已审批:NINGBENZHE
团队审批(relax-block-reviewers) ✅ 1/1 · 已审批:NINGBENZHE
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 8179ec8

目标分支: main

已完成当前版本审查:PLE 发送失败协调、Hybrid 握手失败后的评估门控,以及合入 main 后的 MOPD 收尾和完整评估组保护均已核对,未发现新增可操作问题。既有 F1 保持已解决。

审查阶段进度范围与结果
常规审查 ✅ 已完成 已覆盖全部 30 个接收路径。29 个文件的旧/新基线与提交内容均相同;唯一合并交互 sglang_rollout.py 已专项复核。
深度审查 ✅ 已完成 已核对 MOPD 训练/评估隔离、aborted 组评分门控、原 prompt 边界和 coverage;复用 77adc13 上两个定向真实 Gloo 用例的通过记录,相关 PLE 实现、测试及 Bridge/MPU 契约未变。本轮未重跑本地测试;真实接收端、当前 head 的 GPU/NCCL、多节点与全局故障恢复未验证,历史硬件结果仍绑定原 SHA。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 High severity Hybrid DCS 的 Bridge PLE TP collective 会失配并卡住 ✅ 已解决 —

改进建议(非阻塞)

拆分

💡 1 个拆分方案

可选边界为 C(PLE 分片与失败协调)先于或随 A(Hybrid DCS)交付,B(评估完整组)独立。2586 行中 1494 行为测试,无生成/锁文件膨胀;尊重作者单 PR 偏好,此方案仅供维护者需要分开评审时采用。

箭头表示前置部分 → 后续部分;目标分支为 main。

flowchart LR
    target["目标分支"]
A["PR A"]
C --> A
B["PR B"]
target --> B
C["PR C"]
target --> C
Loading
部分PR 主题内容与范围验证
A Hybrid DCS 弹性权重同步 actor/components/client/arguments/tensor_backper 及 device_direct.py 非 C hunks;涵盖 TP/PP/VP 快照元数据、CPU/GPU backuper、拓扑/量化/offload/恢复/old_actor、握手失败评估门控与清理。带齐其余 lifecycle/getter/参数/recovery/backuper/指纹及 fixture 测试、六份双语文档、recipe/README、两项验证工具;C 后补齐 Iterator/Mapping 导入。 由 CI 验证对应 CPU 回归、recipe 语法及静态检查;GPU 快照、PP/VP、量化和多节点按实际 revision 另验。
B 完整评估组与覆盖率 sglang_rollout.py 的完整组、原 sample.index 边界与 aborted 评分保护;ray/rollout.py 的 group_size/coverage;对应 test_weight_sync_499.py 和 test_metric_utils_rloo.py。保留 base 的训练侧 MOPD finish 清理;actor 的同步失败评估门控归 A。 由 CI 验证 aborted/unscored/missing、空结果、原 prompt 边界、数据集 group_size/coverage,并复用主线 MOPD 回归。无需 DCS 或 GPU。
C DCS PLE 分片与失败协调 device_direct.py 的 Callable/closing 导入、普通 gather 前 PLE 分流及整个 _update_ple_weight_from_distributed,附完整 test_dcs_ple_weight_sync.py。保留全 TP 导出、同 PP stage TP×DP×CP 失败通知、raw 消费者、LoRA skip、pending fused pair 和关闭迭代器;依赖接口已在 main。 由 CI 验证两进程精确分片/重复更新/raw 消费者和四进程两种拓扑的 preflush/raw/shard 故障回归;轻量夹具不证明真实 Bridge、SGLang 接收端或 GPU/NCCL 端到端。
如何按依赖提交(stack)

已核实 RexFlux 对 redai-studio/Relax 具有 write 权限;PR head 来自 RexFlux/Relax fork。

先按表重组混合提交,每部分携带对应测试和文档;逐层验证,并核对顶层最终树与原 PR 一致。独立部分各自向目标分支开普通 PR;只将有依赖的线性链组成 stack,分叉或多前置依赖按图分别安排提交。

有上游写权限: 将各层分支放在上游仓库,在已按依赖拆好的一条分支链上注册并提交(替换目标分支与分支名):

gh stack init --base <target> <layer-1> <layer-2>
gh stack view
gh stack submit

下层更新后用 gh stack rebase 调整上层,或用 gh stack sync 同步整条链。上述命令管理已拆好的分支,不会自动拆开混合提交。参见 gh-stack 使用说明。

相关 PR

💡 实现与合入建议

#554 与 #502 部分重叠,无当前硬依赖;建议在共享运行时收敛后保留 #502 独有的 9B CE 配方。#526 已关闭未合并。

https://github.com/redai-studio/Relax/pull/502 · fa7320ae08d1a85fe432c3f3bf3a6a3e77e0f551 · 目标分支 main

https://github.com/redai-studio/Relax/pull/526 · 67bb71d99e1d5dde5b54caff18b4decbd0fe0733 · 目标分支 main

实现取舍: 共享 actor/client/backend 方法一致。优先采用 #554 的 PLE 全 TP 分片、stage 内发送失败传播、快照和接收端生命周期;#502 尚无等价 PLE 分流。#502 的 9B actor8 TP4/DP2 + rollout2 配方及双模式 argv 回归仍有独立用途。

当前 PR 调整: 当前 #554 保留完整运行时及对应回归,维持作者单 PR 交付意图;无需提前删除尚未合入的共享实现,也无需吸收 #502 的 9B 配方或重引已在 main 的 #555 observability。

合入顺序: 可先落地就绪的 #554,再让 #502 rebase、移除届时已覆盖的运行时增量,保留独有配方/文档/回归。若选择 #502 先合,应先补齐等价 PLE 与失败协调保护,再让 #554 去重。#526 无需合入;不据此关闭 #502。

依据与验证范围: 已按三 PR 固定 head/base 核对源码及讨论;[PLE 实现](https://github.com/redai-studio/Relax/blob/8179ec87ecfd816ffeb486918f235b1b8516036a/relax/distributed/checkpoint_service/backends/device_direct.py#L925)、[9B 配方](https://github.com/redai-studio/Relax/blob/fa7320ae08d1a85fe432c3f3bf3a6a3e77e0f551/scripts/training/text/run-qwen35-9B-elastic-rollout-hybrid.sh)、[#526 关闭说明](https://github.com/redai-studio/Relax/pull/526#issuecomment-6680093265)。此项仅静态协调分析;作者的训练记录不能证明同条件效果或性能等价。

提交范围 · 接收 30 · 建议移出 0 · 待确认 0

接收 30 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。

文件结论仓库维护必要性依据替代去向或方案
relax/backends/megatron/actor.py
relax/components/actor.py
relax/distributed/checkpoint_service/backends/device_direct.py
relax/distributed/checkpoint_service/client/engine.py
relax/distributed/ray/rollout.py
relax/engine/rollout/sglang_rollout.py
relax/utils/arguments.py
relax/utils/training/tensor_backper.py
接收 这些文件实现混合 DCS 权重快照、设备直连传输、弹性 rollout 注册及参数契约,是本 PR 的运行时行为边界。 固定头相对 main 的直接变更清单,以及现有 actor、checkpoint、rollout 调用链。 无需迁移;按权重同步、rollout 生命周期和参数解析边界分别核查即可。
tests/cpu/backends/megatron/test_hybrid_weight_sync_lifecycle.py
tests/cpu/distributed/checkpoint_service/test_dcs_ple_weight_sync.py
tests/cpu/distributed/checkpoint_service/test_weight_sync_lifecycle.py
tests/cpu/distributed/checkpoint_service/test_weights_getter.py
tests/cpu/distributed/ray/test_recovered_engine_registration.py
tests/cpu/engine/rollout/test_weight_sync_499.py
tests/cpu/tools/test_elastic_weight_fingerprint.py
tests/cpu/utils/test_arguments_hybrid.py
tests/cpu/utils/test_arguments_score_centering.py
tests/cpu/utils/test_metric_utils_rloo.py
tests/distributed/checkpoint_service/test_weights_getter.py
tests/utils/training/test_tensor_backper.py
接收 这些测试直接声明新生命周期、PLE shard 同步、权重 getter、弹性注册、指纹和参数行为;需核对此前失败机制及设备假设。 固定头变更清单中的测试路径及其对应生产模块。 无需迁移;CPU 测试保留现有分类,GPU/NCCL 边界作为验证缺口记录。
examples/elastic_rollout/README.md
examples/elastic_rollout/run-qwen3-4B-8xgpu-elastic-hybrid.sh
接收 脚本和说明是用户可执行的 elastic hybrid 入口,需核对参数、资源拓扑和文档行为。 固定头直接新增的 elastic_rollout 示例。 无需迁移;脚本与 README 作为同一示例入口检查。
tools/elastic_validate/compare_runs_clearml.py
tools/elastic_validate/probe_weight_fingerprint.py
接收 这些工具用于验证弹性运行和权重指纹,契约与生产指纹逻辑相连。 固定头直接新增的 elastic_validate 工具及其生产调用关系。 无需迁移;作为验证辅助代码审查,不把工具结果当作运行时证明。
docs/en/examples/elastic-rollout.md
docs/en/guide/elastic-rollout.md
docs/en/guide/hybrid-training.md
docs/zh/examples/elastic-rollout.md
docs/zh/guide/elastic-rollout.md
docs/zh/guide/hybrid-training.md
接收 中英文文档同步描述 elastic rollout 和 hybrid training 用户契约,需核对与实现一致性。 固定头直接修改的中英文文档路径。 无需迁移;保留双语对照并检查与代码一致性。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结论:需要修改(REQUEST_CHANGES)。

阻断问题:

  • P1:Hybrid + Bridge + Qwen4Exp PLE + TP>1 的 DCS 更新存在 collective 参与失配,可能在首次权重同步时挂起。请修复为全 TP 参与的 PLE shard 导出/广播路径,或在该组合下明确拒绝启动,并补充多 rank 回归测试。详见行内线程。

审查范围已覆盖固定头的 29 个变更路径;当前 CI 检查通过。真实 GPU/NCCL 端到端验证未执行,因此该边界仍需在修复后由 GPU CI 或集群验证确认。拆分分析因服务模型容量失败,dashboard 已记录为未完成的非阻塞建议。

Comment thread relax/backends/megatron/actor.py Resolved

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查结论(15beb12c953e99fab0a471d5c637d5157f3fa8d2):APPROVE。

原先发现的 P1 已修复:DeviceDirectBackend 现在让所有 TP rank 进入 Bridge iter_ple_shards 的逐 shard collective,仅 PP source rank 发送转换后的 shard;actor_fwd/reference 仍使用完整表 gather。新增双进程 Gloo 回归覆盖 Hybrid、raw、actor_fwd-only、LoRA skip-base、多轮更新及融合桶边界,本地选定用例通过(1 passed,26.14s)。当前 CI 刷新无失败项。

未发现其他可行动问题。真实 GPU/NCCL、PP/VP、MoE/量化和多节点端到端验证未在本地执行,需依赖对应 CI/硬件环境。2433 行直接变更的非阻塞拆分建议已记录在审查看板中。

@RexFlux

RexFlux commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 15beb12

目标分支: main

审查完成:原 PLE TP collective 失配已修复并通过双 rank Gloo 回归测试;当前无未解决的可行动问题。真实 GPU/NCCL、PP/VP、MoE/量化和多节点端到端验证仍待 CI/硬件环境。

审查阶段 进度 范围与结果
常规审查 ✅ 已完成 已检查当前固定范围的 30 个准入文件及其直接调用链;未发现第二个可独立确认的阻断点。
深度审查 ✅ 已完成 已复核 Hybrid DCS actor 快照、Bridge PLE shard 导出、TP/PP collective 边界及弹性恢复注册;原 P1 修复已由源码和 2-rank Gloo 回归测试支持。真实 GPU/NCCL 端到端验证未执行。

审查发现

待处理
编号  严重性  问题 状态 规则来源
暂无待处理的记录。
已解决或已取代

改进建议(非阻塞)

拆分

💡 1 个拆分方案

2433 行来自 30 个真实运行时代码、测试、文档和工具文件,没有 generated/vendor/lockfile/binary/rename 膨胀;建议按共享契约拆为 A(Hybrid DCS 主线)、B(评估完整分组与 coverage)、C(依赖 A 的 PLE TP 分片修复)。

箭头表示前置部分 → 后续部分;目标分支为 main。

flowchart LR
    target["目标分支"]
A["PR A"]
target --> A
B["PR B"]
target --> B
C["PR C"]
A --> C
Loading

部分 PR 主题 内容与范围 验证
A Hybrid DCS 弹性权重同步 纳入 8ba7159 与 bd7d66f 的全部主线行为:actor 通过 DCS 推送、TP/PP/Bridge 快照属性与可选 GPU backuper、拓扑/量化生命周期、恢复引擎发布、Hybrid 参数校验,以及 actor、components、checkpoint 客户端和非 PLE 的 device_direct.py hunks。连同 hybrid/elastic 双语文档、elastic recipe、ClearML/weight fingerprint 工具及对应 lifecycle、weights getter、arguments、recovery、tensor backuper 和工具测试;score-centering fixture 迁移留在本层。 验证 CPU lifecycle、weights getter、参数/恢复注册和工具测试,脚本做 bash 语法检查;合入前仍需真实 GPU/NCCL、PP/VP、MoE/量化和多节点检查。
B 评估完整分组与覆盖率 独立提取 sglang_rollout.py 的 aborted/unscored/missing prompt 过滤、group reward 完整性与原始 prompt 边界,以及 distributed/ray/rollout.py 的 group_size、有效数和 coverage 指标;随附对应 CPU 评估用例和 RLOO 指标覆盖。 运行 CPU 评估回归,覆盖 aborted、unscored、missing 样本、group_size 与 partial coverage 的 pass-rate/指标断言;该层不依赖 DCS 或 GPU。
C PLE TP 分片流式同步 在 A 之后仅应用 device_direct.py 的 PLE streaming hunks,并加入 test_dcs_ple_weight_sync.py;所有 TP rank 进入 Bridge iter_ple_shards,只有 PP source 逐 shard 发送,保留 pending fused pair、失败关闭语义和 raw actor_fwd/reference 的整表 gather 协议。 运行新增双进程 Gloo 回归,核对精确 shard 值、重复更新、HF-only/raw 消费者和失败清理;Qwen4Exp Bridge 映射及真实 GPU/NCCL/PP/TP 端到端仍需硬件验证。
如何按依赖提交(stack)
提交范围 · 接收 30 · 建议移出 0 · 待确认 0
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

感谢建议,这次计划保留单个 PR。评估分组与 coverage 部分涉及 4 个文件、259 行增删,约占总改动的 10.6%;拆出后主体仍有约
2,174 行,降低审查规模的收益有限。

当前六项 required CI 均已通过,也完成了真实 GPU 的 Hybrid 弹性 Rollout 验证,以及 PLE 修复后的 TP2/NCCL 定向验证,具体范围
和限制已写入 PR 描述。PLE 修复会与 Hybrid→DCS 切换一起交付,确保该路径的正确性。后续若维护者认为某部分需要独立审查,我们再
调整。

RexFlux and others added 3 commits November 9, 2026 16:23
Route hybrid rollout weight updates through DCS using actor snapshots that
preserve Megatron TP metadata, with optional device-resident backups.
Coordinate topology and receiver lifecycle across training ranks, retain
complete evaluation prompt groups, and add an elastic hybrid recipe.

Preserve current resident-SFT, score-centering, bucket assembly and recovery
behavior while adapting the original merge delta to the GitHub mainline.

(cherry picked from commit 55d145f)

Co-authored-by: Codex <[email protected]>
Supply the parser's default weights-backuper setting in the manually built
score-centering test arguments so Hybrid validation checks the intended
configuration. Preserve the runtime rejection of disabled Hybrid backups.

Co-authored-by: Codex <[email protected]>
Route Bridge PLE weights before the generic full-table TP gather. Consume
TP-local shard exports on every rank and send each HF shard from the source
rank, preserving pending fused pairs and releasing the export on failure.
Keep the existing raw Megatron payload protocol for actor_fwd/reference.

Add a two-process CPU/Gloo regression for collective participation, exact
shard values, repeated updates, and raw/HF consumers. Related CPU tests:
65 passed, 10 skipped (Qwen4Exp Bridge is unavailable locally).
Real Qwen4Exp GPU/NCCL validation remains outstanding.

Co-authored-by: Codex <[email protected]>
@RexFlux
RexFlux force-pushed the feat/hybrid-dcs-elastic-rollout branch from 15beb12 to 9a46e17 Compare November 9, 2026 08:26

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查通过

已复核 9a46e171 相对 1bec680c 的 rebase,DCS/PLE、快照与评估冲突处理保留了原契约,未发现新的可行动问题。源码比较和两项隔离评估探针支持此结论;本轮未重跑完整 GPU/多节点集成。当前 CI 无失败项,部分必要检查仍在排队或运行,尚不能视为全部通过。

审查看板与非阻塞建议

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

Comment thread relax/backends/megatron/actor.py Resolved
RexFlux and others added 2 commits November 10, 2026 17:17
Share source-side preflush, raw-send and PLE shard-send errors with every
TP/DP/CP rank of the same pipeline stage before the next collective. Keep
other PP stages independent, preserve the original source exception, and
close the shard iterator on every participating rank.

When the Hybrid rollout handshake fails, retain metric flushing, the rank
barrier and end-update cleanup while skipping evaluation for unpublished
weights. Reuse the cleanup helper in the normal evaluation finally path.

Add real four-process Gloo fault regressions for TP2/DP2 and a nonzero PP
source, plus skipped-handshake lifecycle coverage. Related CPU regression:
401 passed, 10 skipped (Qwen4Exp Bridge unavailable), 3 subtests passed.
Full pre-commit passed; no new GPU/NCCL validation was performed.

Co-authored-by: Codex <[email protected]>
Merge upstream main at 957b418 while retaining both review fixes from
77adc13. Resolve the grouped-scoring conflict by preserving main's MOPD
response-statistics cleanup and this PR's aborted evaluation-group guard.

Related CPU regression after the merge: 497 passed, 10 skipped for the
unavailable Qwen4Exp Bridge module, and 3 subtests passed. Full pre-commit
passed. Historical GPU results remain bound to their original commits.

Co-authored-by: Codex <[email protected]>

@rai-studio-bot rai-studio-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审查通过

已完成 8179ec87 的增量审查:PLE 发送失败传播和握手失败后的评估门控保持完整,合入 main 后也保留了 MOPD 收尾与评估完整组保护,未发现新增可操作问题。本轮复用原版本的定向 Gloo 证据,未重跑 GPU/NCCL 或多节点集成。

详细结果、验证范围与非阻塞建议

Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@NINGBENZHE NINGBENZHE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已复核此前两条评论。双进程 Gloo 故障注入确认 PLE 发送异常会在当前分片传到对端。Hybrid 握手失败时会跳过本步评估并清理握手。6 项必需检查已通过,同意合入。

@RexFlux
RexFlux merged commit 64ffb3f into redai-studio:main Nov 10, 2026
18 checks passed
RexFlux added a commit that referenced this pull request Nov 11, 2026
## What

Add the Qwen3.5-9B hybrid elastic-rollout CE launch recipe.

## Why

Hybrid DCS support is now available on main through #554. Add a
dedicated 9B hybrid CE entrypoint so the two training recipes remain
independent.

## How

The standalone hybrid script uses actor8 (TP4/DP2), two initial rollout
engines, and the existing autoscaler policy with a maximum of eight
engines. Reference/forward/advantages run on the actor GPUs. The ClearML
project, experiment prefix, and log filename identify hybrid runs.

Following the launcher organization in #517, the hybrid script resolves
its own checkout, dispatches through the standard Ray entrypoint, groups
environment and training arguments, and supports trailing argument
overrides and a side-effect-free JSON `DRY_RUN=1`. It preserves the
existing CE script path, model/data root fallbacks, runtime setup hooks,
and transport settings.

The full-async script is byte-for-byte identical to main. This PR only
adds the hybrid script; framework behavior comes from main.

## Testing

- Ad hoc argument-capture validation: full-async matches main
byte-for-byte; the hybrid training argv and runtime-env match the prior
script, apart from experiment timestamps. The real CE argument-rewrite
function preserves HF/ref checkpoint, ClearML project/name, and
save-directory overrides.
- `bash -n` passes for both scripts.
- `pre-commit run --all-files --show-diff-on-failure`: passed.
- Independent read-only review found no remaining blockers.

- [x] `pre-commit run --all-files` passes
- [ ] Tests pass (`pytest tests/`)
- [ ] New tests added (if applicable)
- [ ] Documentation updated (if applicable)

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

An earlier run pinned to `fa7320ae08d1a85fe432c3f3bf3a6a3e77e0f551`
completed 100 consecutive training steps, six scale-outs from 2 to 8
engines, and one automatic scale-in from 8 to 7, followed by a
successful DCS update and normal completion. That is historical
validation; this rebase onto `64ffb3f0214c815d4bd366215675d5129c4ae264`
has not been rerun on GPUs.

<div align="right">
    <sup>This PR is co-authored with @codex (gpt-6)</sup>
</div>

---------

Co-authored-by: Codex <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants