Skip to content

feat(recovery): recover existing inference services locally - #548

Open
RexFlux wants to merge 23 commits into
redai-studio:mainfrom
RexFlux:feat/recovery-phase1-04-rollout-restart
Open

RexFlux wants to merge 23 commits into
redai-studio:mainfrom
RexFlux:feat/recovery-phase1-04-rollout-restart

Conversation

@RexFlux

@RexFlux RexFlux commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

What

支持 colocate、全异步和 hybrid 模式下,已有 Rollout 服务在生成数据时发生明确异常后的局部重建;支持全异步模式下独立 ActorFwd 服务的局部重建。局部恢复成功后,保留原训练 Actor、optimizer、scheduler 和训练任务。

生产代码规模:relax/ 共 20 个文件,新增 1363 行、删除 220 行,累计改动 1583 行,净增 1143 行。 测试与文档另计,未混入生产代码统计。

Why

推理服务故障可能导致整个训练任务重新初始化。对于支持的明确异常,可在有限恢复预算内仅重建故障服务,同步当前训练权重后继续训练,减少全局重启。

How

  • 暂停新的数据生产和消费,排空正在执行的工作;丢弃生成半成品和未训练的 pending batches,输入 cursor 不回退。重建故障推理服务、同步当前权重,确认接管后恢复运行。
  • Rollout 和 ActorFwd 共用默认累计 3 次的局部恢复预算,成功后不清零;预算耗尽或无法安全局部恢复时,沿用现有全局重启路径。
  • 保留当前 Controller 重启生命周期、训练 Actor 故障上报确认、启动阶段权重响应处理、TransferQueue 生命周期及传输资源清理。Hybrid 恢复与全异步共用 DCS 传输重置和权重同步,从现有 Actor 快照发送权重,不新增独立 ActorFwd。
  • 补充中英文文档,说明各模式的默认开关、配置冲突检查和支持范围。训练 Actor 自愈、hung 检测、节点/GPU 丢失、权重同步中故障、严格 on-policy 和零样本丢失不属于本次局部恢复承诺。

wait_all 的 600 秒总截止时间继承自迁移前的恢复实现,涉及正常训练、前向和权重等待调用。本 PR 保留该行为,等待策略调整不纳入本次迁移。

代码改动范围与规模

统计对应当前提交 0ab3d29ad44f7fee7366ef675a2d710d83a63fda,采用 GitHub PR 的三点 diff(main...HEAD;共同基线为 9dc2ca63b96082aa60a625cdba0d9ea1bd11876c)。仅统计 relax/ 生产代码:20 个文件,新增 1363 行、删除 220 行,累计变更 1583 行,净增 1143 行。已同步最新 main,包含 hybrid DCS(#554);上游已有改动不计入本 PR。

模块 文件数 新增 删除 主要改动
relax/core/ 4 581 16 共享恢复状态、准入与排空、累计预算和配置检查;独立执行器负责数据清理和权重接管,Controller 保留线程监督、锁内任务发布及全局回退,Service 复用 placement group 重建推理角色。
relax/backends/ 3 216 83 Megatron 恢复当前权重到替换后的推理实例;hybrid 复用 main 的 DCS 快照权重同步,移除旧 tensor updater 专用恢复入口;重置推理通信资源并确认旧 SGLang 服务进程退出;局部恢复严格比对全部替换 Engine 与 DCS 实际接收集合,不完整时各训练 rank 一致失败并全局回退,普通弹性同步保持原行为。
relax/components/ 4 241 109 Actor、ActorFwd、Advantages、Rollout 接入恢复准入及失败收尾;Actor 抽出单步训练方法,保留原异常传播和状态释放顺序;保留 main 的动态分区排空及删除保护。
relax/distributed/ 4 183 10 停止旧推理子 Actor、Manager 和 Router;清理并重建 Actor 到推理角色的传输组、代理和接收端元数据;严格注销由 DCS Client 确认 ACK,保留既有 best-effort 注销语义。
relax/engine/ 2 42 2 丢弃 pending 样本且不回退输入 cursor;确认旧生成及存储写入终态,并标记完整数据分区。
relax/utils/ 3 100 0 增加恢复环境配置和全异步训练字段,保留 Agentic 观测字段;TQ 适配模块严格等待存储清理 ACK 后再释放分区索引。
合计 20 1363 220 生产代码累计变更 1583 行。

以上不含测试和文档:tests/ 为 28 个文件,新增 2387 行、删除 83 行;docs/ 为 7 个文件,新增 220 行。 **全 PR 共 55 个文件,累计变更 4273 行:生产代码 1583 行、测试 2470 行、文档 220 行;测试和文档合计约占 63%。**行数包含注释和空行,替换一行同时计一次删除和一次新增,累计变更量与净增量分别统计。

后续代码调整时,同步更新这里的模块说明、行数统计及对应提交;验证结果也同步注明实测版本,未重跑的 GPU 验证继续保留原提交边界。

Testing

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

P2 修复:评测收尾与全局接管互斥(0ab3d29a)

修复健康检查先取消旧等待、延迟的 Manager 查询随后又登记慢 drain 的竞态。仅在 Controller 中使用现有重启锁,将接管检查、drain RPC 提交和 pending Future 登记放在同一临界区;查询及等待仍在锁外。接管先发生时拒绝新 drain,登记先发生时待完成的 Future 可被取消。正常评测 drain、活跃恢复线程退出保护和训练 waiter 屏障均保留。本次生产代码仅一个文件 +6/-3,未实施此前讨论的 Actor/Service 架构调整。

新增一个三时序参数化回归:正常慢 drain、先登记后接管、查询延迟且先取消后返回。远端 CPU 旧代码为 2 passed / 1 failed,第三种时序触发退出替身;修复后四个相关 CPU 文件 116 passed、0 failed、0 skipped,包括真实 CPU Ray/Serve 用例。RPC、judge 和进程退出仍由替身隔离,不将该结果声称为真实 GPU 故障注入。

全量 pre-commit 与独立只读复核通过。当前提交必需 GitHub CI 已全部通过:CPU 为 9853 passed、0 failed、155 skipped,另有 3 个 subtests passed;H20 单卡/四卡单测及三项 GPU/NPU 集成测试均通过。单测记录。未运行本地 pytest,未另启 GPU 故障注入训练;原 P2 线程已用 gh 回复并补充最终结果。

Rebase 最新 main(ef0022c8)

将已有 20 个开发提交 rebase 到 main@62cead37,保留 main 新增的异步 eval judge 和 managed teacher rollout-only 修复。Controller 继续等待受恢复监督的服务,随后执行上游完整的 judge drain,并把线程安全 Future 登记到 pending 列表,供重启取消等待;RolloutManager 同时保留 eval judge、LoRA 与恢复状态字段。

  • 两处生产冲突及一处测试 namespace 冲突均保留双方必需逻辑;独立只读复核通过,全量 pre-commit 通过。
  • 适配既有恢复测试中的假 Manager,按 main 既有夹具协议提供已完成的 drain_eval_judges.remote().future();原恢复、全局回退及清理断言不变,没有关闭异步评测、新增 skip 或放宽超时。
  • 相对新 main 的生产代码仍为 20 个文件、+1357/-217,累计 1574 行;测试和文档规模已同步到上方统计。
  • 该提交 CI 已全部通过,CPU 为 9850 passed、155 skipped,另有 3 个 subtests passed。未运行本地 pytest,未启动远端 GPU 训练;历史 GPU 证据继续绑定各自实测提交。

Rebase 最新 main 与 CPU 用例修复(7f41270f)

将 19 个开发提交 rebase 到 main@ed7bcbdf,随后单独提交测试适配;保留恢复逻辑以及 main 的 LoRA、teacher PG、NEXTN 与 score-centering 改动。初始化同时保留两组状态字段;搬迁后的全异步训练字段复用 main 的 SCORE_CENTERING_TRAIN_FIELDS,包含新增加的 rollout_topk_support_complete,避免遗漏训练所需字段。

旧提交 8884516f 的 CPU CI 为 9788 passed、1 failed、155 skipped,另有 3 个 subtests passed。失败的取消测试使用 AST 提取 generate,但假 Manager 没有 main 新增的 _begin_generation,任务在进入生成线程前就失败。仅在该用例补真实方法绑定及 RLock,保留原 3 秒超时、取消异常和线程活跃状态断言;未用 no-op、skip 或增加超时绕过问题。

同时扩展原有两个 score-centering 字段用例,检查普通/全异步两个真实 builder 的三个字段,防止再次遗漏 support-complete。未新增测试用例或依赖。全量 pre-commit 与独立只读复核通过,未运行本地 pytest。该提交的 GitHub required CI 已全部通过:CPU 全量 9813 passed、0 failed、155 skipped,另有 3 个 subtests passed,原失败取消用例与两个字段用例均通过;H20 单卡/四卡单测及三项 GPU/NPU 集成测试均通过。运行记录:单测、集成测试。

相对新 main 的生产代码规模仍为 20 个文件、+1357/-217,累计 1574 行。当前包含新的 main 生产改动,未重跑远端 GPU 训练;历史 GPU 证据继续绑定原实测提交。

同步 main 与冲突解决(8884516f)

在已有 GitHub 同步提交 e84a8355 上合并 main@3816c3e5。唯一文本冲突为 RolloutManager.__init__ 的状态初始化:同时保留本 PR 的两个恢复字段与 main 的四个 LoRA 字段。上游 generate/eval 的 LoRA 生成准入检查、固定池和发布前保护均保留;恢复路径仍通过 _generate_batch 的 finally 清理活跃标记,DCS 严格接收方集合、ACK 等待、旧进程退出和锁清理均保留。

  • 全量 pre-commit 通过,独立只读复核通过。四个重叠生产模块的 AST 三方检查确认 46 个单侧变更方法原样保留,另人工复核双方同时变更的三个方法。
  • 相对新 main 的 PR 规模保持 20 个生产文件、+1357/-217(累计 1574 行),测试与文档统计也未增加。合并带入的 main 既有变更不计入本 PR 新增改动。
  • 该合并提交后 CPU 出现一项 AST 测试夹具适配失败,已在上方 rebase 记录处理;未运行本地 pytest,未启动 GPU 训练。历史 GPU 验证继续绑定各自实测提交,不冒充本次合并后的 GPU 验证。

CPU CI 稳定性修复(b37fded5)

8edce112 的 CPU CI 为 9078 passed、1 failed、154 skipped,另有 3 个 subtests passed;唯一失败为 main 继承的 test_stage_recorder_keeps_the_open_file_count_flat,读取异步阶段日志时文件尚不存在。该测试隐含要求所有写入必须在生产 close() 的 1 秒截止时间内完成,而超时后 writer 可以丢弃排队工作。

仅增加 4 行测试代码:在队列末尾提交 FIFO 完成屏障,有界等待写入完成,再检查活跃 appender 上限并执行原有关闭及 12 个文件内容断言。没有改生产 writer 的关闭策略,没有放宽断言或新增 skip。独立只读复核与全量 pre-commit 通过。远端隐藏 GPU 运行两个相关 CPU 测试文件:143 passed,0 failed、0 skipped;额外以首批写入延迟 1.2 秒对照,旧测试失败、修复后通过。

b37fded5 的 relax/ Git tree 与 GPU 实测 90dddd43 完全一致。该提交的 GitHub required CI 已全部通过:pre-commit、CPU / H20 单卡 / H20 四卡单测,以及三项 GPU/NPU 集成测试。CPU 全量结果为 9080 passed、0 failed、154 skipped,另有 3 个 subtests passed;单测运行记录。未手动运行未分组的全仓 pytest tests/。

Rebase 后 GPU 定向回归(生产实测 90dddd43;对应测试修复 b37fded5)

固定生产源码 90dddd43a51eec92f587542165d0ecdc9a239673,使用真实 Qwen2.5-1.5B-Instruct、H20 GPU 和短算术 GRPO/DAPO 数据完成三组回归,三个 Job 均 SUCCEEDED,并经独立只读复核。训练 TP2/PP1、推理 TP1、GBS8、每轮两次 optimizer 更新;fully-async 使用 Actor2 + ActorFwd2 + Rollout2,hybrid 使用 Actor4 + Rollout2。没有导出 checkpoint,没有运行本地 pytest。

场景 实测结果
Fully-async 共享累计预算 Rollout / ActorFwd / Rollout 三次局部恢复,恢复后分别共同完成 14 / 12 / 12 次更新;第四次 ActorFwd 故障耗尽预算,恰好一次全局回退。原 Actor cohort 共 44 次完整更新,新 cohort 共 80 次;两个 Rollout 重建的替换引擎版本分别为 3/3、21/21。
HealthChecker 全局恢复与新回执链 原 Actor cohort 完成 10 次更新,新 cohort 完成 28 次;同一非空 recovery ID 依次出现 handling_started → recovery_handoff → recovery_succeeded,handoff 时观察到 15 位证据,实际接收完成后达到 expected=observed=31,failed=0。
Hybrid 当前 DCS 路径 一次 Rollout 局部恢复,零全局重启;4 个 Actor rank 共完成 32 次完整更新,恢复后 28 次。4 个 DCS sender 的实际版本均为 3,两个替换引擎均为 3,严格接收方集合与实际替换 Engine ID 一致。

完整更新按全部训练 rank 的 (rollout_id, step_id) 交集统计。已核对 optimizer 更新成功且计数连续、原生 loss/grad 有限且存在非零梯度、局部恢复前后训练 Actor/model/optimizer/scheduler/训练任务身份保持、旧 SGLang 进程按 PID 与创建时间确认退出,以及 driver/worker 实际导入路径和冻结来源摘要。三个 Job 完成后训练 CUDA 上下文均已清理。

8edce112 仅适配 main 引入的全局恢复 CPU 测试夹具(一个测试支持文件,+6/-1),不改生产逻辑、原有断言或 skip。其 relax/ Git tree 与 GPU 实测提交完全相同:bd4988e52260a59d91f0035e852cace6f0d1392d。CI 原先失败的 3 个真实 CPU Ray/Serve 用例已在远端隐藏 GPU 复跑通过(3 passed,142.21s);全量 pre-commit 通过,后续 CI 修复及状态见上方最新记录。

边界:本轮针对 rebase 后的 fully-async、hybrid DCS 和非空 recovery token 回执链;colocate 基线/局部恢复、DCS 部分接收方失败仍保留下方 3eaadd2e 的历史实测边界。本轮不覆盖推理 TP2 恢复、多节点、长期收敛、checkpoint/optimizer 跨全局重启续训或外部 OTLP Collector 交付。

Rebase 最新 main(90dddd43)

已将现有开发提交 rebase 到 main@9689b0f8,保留 main 新增的全局恢复观测、初始化同步回执和 recovery identity 传递。局部推理恢复执行模块与此前 c78d6cc0 相同;Actor 与 ActorFwd 的成功/失败回执包住实际同步等待,严格接收方集合检查仍生效。初始化同步保留 begin_sync → 等待真实同步响应 → end_sync,失败时不释放同步、不启动训练。

  • 全量 pre-commit run --all-files --show-diff-on-failure 通过,独立只读复核通过。
  • 在指定远端隐藏 GPU(CUDA_VISIBLE_DEVICES="")执行 19 个恢复、初始化同步、全局恢复观测和回执相关 CPU 测试文件:630 passed,另有 3 个 subtests passed,0 failed、0 skipped。未运行本地 pytest。
  • 复用既有用例适配 token 参数、Controller 重启前置保护和 receipt fixture;未新增测试用例,原有结果断言保留。
  • 当前相对 main 的生产代码为 20 个文件、1574 行;测试为 25 个文件、2349 行。新增涉及的两个测试文件仅适配上游既有 fixture,未增加生产模块。
  • 远端镜像的 OTel SDK 为 1.44,未满足仓库的 >=1.45.0,<1.46;3 个 OTLP 导出用例未通过该环境验证。尝试在允许目录隔离安装既有声明依赖,但当前 pip 源缺少所需 opentelemetry-proto 1.45.x。未修改系统环境、项目依赖或测试断言;这 3 项留给安装匹配依赖的 CI 验证,不计作通过。
  • 该阶段尚未重跑 GPU;后续针对同一生产提交完成的三组回归见上方“Rebase 后 GPU 定向回归”。

同步 main 与冲突解决(c78d6cc0)

已合并 main@325a4f84,保留分支原有提交历史。唯一冲突位于 S3 缓存清理测试:保留本 PR 的初始化权重同步成功、等待及失败传播用例,同时保留 main 新增的普通/Agentic 启动时 tokenizer 缓存保护回归。Controller 自动合并保留 main 在模型消费者启动前清理旧缓存的修复,恢复训练循环与 077e9ac0 相同。

  • 全量 pre-commit run --all-files --show-diff-on-failure 通过,独立只读复核通过。
  • 远端隐藏 GPU 执行 21 个相关 CPU 测试文件:609 passed,另有 3 个 subtests passed,6 failed、0 skipped。恢复、初始化同步、S3/Agentic 缓存保护及 Controller 用例通过;未运行本地 pytest。
  • 6 个失败均为既有 test_train_shutdown_deadline_exits_blocked_process 参数:50 毫秒强制退出时尚未写完终态日志。使用 main 原始测试和 train.py 在同一环境重放,6 个同样失败;被测入口与 Agentic 观测模块和 main 一致。该环境下实际 RunRecorder.flush() 三次耗时约 159 / 140 / 147 毫秒,均超过测试限制;本次不修改上游退出逻辑或放宽该测试,不把这 6 项记作通过。
  • 本次仅解决合并冲突,生产代码相对 main 仍为 20 个文件、1578 行,测试仍为 23 个文件、2310 行;上游已有变更未计入本 PR。
  • GPU 训练未重跑。当前源码包含新 main 的生产改动,下方 GPU 实测结果继续绑定 3eaadd2e,不作为 c78d6cc0 的新一轮 GPU 验证。

单测精简与验证(077e9ac0)

本次仅调整测试:合并重复的重启信号、取消引用、进程启停和预算用例,将事件身份、配置透传及进程退出等独有断言迁入保留测试;移除与本 PR 行为无关的 shutdown 用例,撤回无关的 affinity fixture 重写。修正 Actor 健康检查测试的 ray.get 绑定并检查上报确认、等待调用,避免原先因缺少 ray 而误走上报失败分支。

  • 单测累计 diff 从 2490 行降到 2310 行,减少 180 行;测试文件数从 25 降到 23。
  • 全量 pre-commit run --all-files --show-diff-on-failure 通过,两路独立只读复核通过。
  • 在远端隐藏 GPU(CUDA_VISIBLE_DEVICES="")执行 17 个相关 CPU 测试文件:511 passed,另有 3 个 subtests passed,0 failed、0 skipped。未运行本地 pytest。
  • 当前 077e9ac005d7ed31de1c0010c42dbe870889c34e 的 relax/ Git tree 与下方 GPU 实测版本 3eaadd2e 完全相同。没有重跑 GPU 训练,GPU 证据继续绑定其原始实测提交。

GPU 功能回测(实测提交 3eaadd2e)

固定版本 3eaadd2ee3cf6727030d253009c0d24f9b42f704,使用真实 Qwen2.5-1.5B-Instruct、H20 GPU 完成功能回测,五项均正常结束并经独立只读复核。该轮没有修改生产代码,没有运行本地 pytest,没有导出训练 checkpoint。

场景 该历史版本的实测结果
恢复关闭的 colocate 基线 6 个训练 rank 共同完成 8 次更新
Colocate Rollout 局部恢复 恢复后共同完成 18 次更新;6 个替换引擎权重版本均为 5,无全局重启
Fully-async:Rollout / ActorFwd / Rollout,共享累计预算 三次局部恢复后分别共同完成 14 / 12 / 12 次更新;第四次 ActorFwd 故障触发一次全局重启,新 cohort 完成 72 次更新
Hybrid Rollout,当前 DCS 路径 恢复后 4 个训练 rank 共同完成 20 次更新;两个替换引擎版本均为 3,无全局重启
DCS 部分接收方失败 人为移除两个预期接收方中的一个同步代理;原生 NCCL 实际仅向一个接收方完成同步,4 个训练 rank 均拒绝不完整集合,无局部成功;一次全局重启后新 cohort 完成 28 次更新

完整更新按全部训练 rank 的 (rollout_id, step_id) 交集统计,并核对 optimizer 更新成功、有限 loss/grad,以及局部恢复前后的 Actor、model module、optimizer、scheduler 和训练任务身份。Rollout 核对发送端与替换引擎版本;ActorFwd 核对替换实例、接收完成 ACK 及实际前向接管,不声称逐字节验证其权重或优化器状态。

配置与限制: 基线使用推理 TP2;恢复场景使用训练 TP2/PP1、推理 TP1、NCCL_NVLS_ENABLE=0。该机器的推理 TP2 恢复尝试遇到 multicast/symmetric-memory 阻塞,未完成该配置的恢复验收,不能外推 TP1 结果。全局重启验证从原始 HF 权重启动的新 cohort,未验证 checkpoint/optimizer 断点续训。Fully-async 后半段出现间歇性的 5 秒 HTTP health 读取超时,重试和同步组重建后完成;本轮没有做性能 A/B,也不据此归因于本 PR。

历史验证(保留原提交边界)

未手动运行全仓 pytest tests/。按要求停止本地 pytest,后续使用指定远端 GPU 环境及 GitHub CI。历史 GPU 实验固定源码与配置,使用真实 Qwen3-8B 训练、6 张 H20、TP2、GBS96、上下文512、最大响应256;不额外下载模型或保存 checkpoint。

完整恢复矩阵绑定提交 60763cf266682475fba6b6d6728956f9f62a4ee3,该提交所有已报告 CI 检查通过。

场景 完整有效全局更新数 结果
恢复关闭的 colocate smoke 每个训练 rank 各8次 正常结束
Colocate Rollout 局部恢复 恢复后14次 正常结束,无全局重启
全异步 Rollout / ActorFwd / Rollout,共用累计3次预算 分别恢复后12 / 14 / 14次 第4次故障按预算耗尽转入一次全局重启;新训练实例完成12次后主动结束有界验证
Hybrid Rollout,Tensor snapshot 路径,无独立 ActorFwd 恢复后16次 正常结束,无全局重启

有效更新按所有训练 rank 的 (rollout_id, step_id) 交集统计,包含真实 optimizer 更新及有限的原生 loss/grad。局部恢复保留训练 Actor、model、optimizer、scheduler 和训练任务,计数连续;全局重启使用新实例,不承诺保留训练状态。旧实例在局部恢复返回后立即独立核验退出。Rollout 直接核对 sender 与新 engine 的版本;ActorFwd 验证维护同步内的新实例接收完成、真实前向接管及14次更新,接收端没有独立数值版本字段,不声称测得数值版本相等。

历史提交 0a9acde463148b82659f86c31264be62b799b00e 基于当时的 upstream/main@64ffb3f0,包含已合入的 hybrid DCS #554。 Hybrid 改为复用现有 DCS 恢复链路,删除旧 Tensor snapshot 专用恢复入口;保留 main 的 hybrid 握手失败跳过 eval、Agentic 观测字段和 Advantages 分区删除保护。扩展已有恢复发布回归,覆盖无独立 ActorFwd 的 hybrid Rollout,并删除失效的 tensor 专用 helper 测试。

该历史提交的 pre-commit run --all-files --show-diff-on-failure 通过;独立只读审查通过,未发现必须调整的问题;机器人已确认生产修复提交 47310938 的 P1 修复并 APPROVE,原线程已关闭。历史提交 0a9acde4 仅补齐测试 fixture,relax/ 与该生产修复提交逐字节相同。该历史阶段未运行本地 pytest,也尚未完成 hybrid DCS 的真实 GPU 回测;当前 3eaadd2e 的实测结果以本节上方的“GPU 功能回测”为准。旧版本暂停的 smoke / colocate 增量验证不计为当前版本通过。上述 60763cf2 矩阵继续保留原提交及 Tensor snapshot 路径边界。测试 fixture 同步适配新 main:补齐绕过构造函数的恢复 fixture、AST Controller 的 time/monotonic 依赖,并对齐 main 的故障事件关键字断言;扩展真实恢复调用链回归,覆盖两个替换引擎只同步一个、空或额外接收集合、非零 rank 失败传播,以及同步失败不恢复生成。历史提交 0a9acde4 的六项必需 GitHub CI 全部通过:Pre-commit、CPU Unit Tests、H20 4-GPU Unit Tests、Qwen3-4B 异步 GPU 集成、Qwen3-VL 多模态 GPU 集成及 Qwen3-4B 异步 NPU 集成。CPU 结果为 9009 passed、154 skipped、0 failed(另有6个 subtests passed);跳过用例不计为验证通过。见 CPU 单测日志 和 集成 CI。

当前新推理局部恢复路径尚未接入上游新增的完整 OTel 恢复完成事件;本轮使用进程、同步、实例身份及训练更新证据验收。

历史吞吐对照仍绑定 85a8004a1d977678f48ac450bf09c246798485ae:全异步关闭/开启7.413 / 9.603序列/秒,hybrid关闭/开启7.213 / 12.709序列/秒。窗口为全rank完成零起算step3至step15,分母12次更新×GBS96=1152条训练样本序列;生成长度、微批量、编译缓存和长等待有差异,不能归因为恢复加速或用于证明零开销。本轮不重复吞吐对照。

以上限于受控 Python 明确异常,不外推任意引擎崩溃根因、hung、节点/GPU丢失、权重同步中故障、长期精度或完整多节点训练验收。

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

上述表格汇总本轮受控 GPU 实测结果。详细验收资料独立保存,未放入公开源码历史。

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 / 状态
审批人数 ⏳ 0/1 · 至少 1 位有仓库 write 或更高权限的人 Approve
团队审批(relax-block-reviewers) ⏳ 0/1 · 可联系:Aurelius84, Yangruipis, yuanlehome, SigureMo, NINGBENZHE, Lemon-412
CI ✅ 已通过

@rai-studio-bot

rai-studio-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: 0ab3d29

目标分支: main

已完成0ab3d29a复核,结论通过。评测收尾登记与全局接管现已使用同一重启锁互斥,F3在源码和匹配CPU回归中确认修复;F1/F2保持源码已修复,未发现剩余审查问题。

审查阶段进度范围与结果
常规审查 ✅ 已完成 55路径、4273行全部准入;本轮仅Controller与既有回归文件变化,另外53个文件复用已完成覆盖。当前7项必需CI均成功;[CPU attempt 1](https://github.com/redai-studio/Relax/actions/runs/43840788751/job/133208744256)为9853 passed、155 skipped、3 subtests passed,三个接管时序回归节点均通过。
深度审查 ✅ 已完成 已核对重启锁与pending锁的现有顺序:接管先发生则拒绝提交,登记先发生则取消快照能看到Future,真正等待位于锁外;正常drain与活跃恢复线程退出保护保留。新增回归执行真实Controller路径并控制三种时序,RPC、judge、全局资源重建及退出由替身隔离。未重复旧复现,未运行本地测试、真实Ray/GPU故障注入、多节点或checkpoint续训。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 High severity 确认全部替换引擎接管权重后再恢复 ✅ 已解决 恢复流程:当前权重接管后再恢复
F2 Medium severity 补全取消生成用例的准入依赖 ✅ 已解决 —
F3 Medium severity 将评测收尾等待的登记与全局接管互斥 ✅ 已解决 —
提交范围 · 接收 55 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
docs/.vitepress/config.mts
docs/en/guide/configuration.md
docs/en/guide/health-check-manager.md
docs/en/guide/inference-recovery.md
docs/zh/guide/configuration.md
docs/zh/guide/health-check-manager.md
docs/zh/guide/inference-recovery.md
接收 Bilingual recovery documentation and navigation remain in the established user documentation tree. PR requirements define recovery defaults, supported modes, failure and data-loss boundaries. Keep both language guides and their navigation together under docs/.
relax/backends/megatron/actor.py
relax/backends/megatron/weight_update/update_weight_from_tensor.py
relax/backends/sglang/sglang_engine.py
relax/components/actor.py
relax/components/actor_fwd.py
relax/components/advantages.py
relax/components/rollout.py
relax/core/controller.py
relax/core/inference_recovery.py
relax/core/inference_recovery_executor.py
relax/core/service.py
relax/distributed/checkpoint_service/backends/device_direct.py
relax/distributed/checkpoint_service/client/engine.py
relax/distributed/ray/actor_group.py
relax/distributed/ray/rollout.py
relax/engine/rollout/data_source.py
relax/engine/rollout/sglang_rollout.py
relax/utils/env.py
relax/utils/tq/recovery_storage.py
relax/utils/training/data_fields.py
接收 Local recovery belongs to existing orchestration, component, backend, transport and data owners. Required behavior preserves training state while draining, rebuilding, resynchronizing and resuming inference with bounded global fallback. Keep shared orchestration in core and role-specific state in its existing subsystem.
tests/cpu/backends/megatron/test_actor_http_timeout.py
tests/cpu/backends/megatron/test_hybrid_weight_sync_lifecycle.py
tests/cpu/backends/megatron/test_simple_inference_recovery.py
tests/cpu/backends/megatron/weight_update/test_routed_weight_update.py
tests/cpu/components/test_component_background_loop.py
tests/cpu/components/test_simple_inference_components.py
tests/cpu/core/test_controller_global_restart.py
tests/cpu/core/test_controller_s3_model_cleanup.py
tests/cpu/core/test_fault_global_recovery_cpu.py
tests/cpu/core/test_fault_local_recovery_cpu.py
tests/cpu/core/test_inference_recovery_global_restart.py
tests/cpu/core/test_initial_weight_sync.py
tests/cpu/core/test_rollout_recovery_policy.py
tests/cpu/core/test_simple_inference_recovery.py
tests/cpu/core/test_training_failure_recovery.py
tests/cpu/distributed/checkpoint_service/test_simple_inference_transport_reset.py
tests/cpu/distributed/ray/conftest.py
tests/cpu/distributed/ray/test_engine_metadata.py
tests/cpu/distributed/ray/test_recovered_engine_registration.py
tests/cpu/distributed/ray/test_scale_out_registration_order.py
tests/cpu/distributed/ray/test_simple_inference_children.py
tests/cpu/entrypoints/test_startup_failure.py
tests/cpu/utils/test_fault_receipts.py
tests/cpu/utils/test_tq_dataplane_behavior.py
tests/distributed/ray/test_scale_weight_sync_precheck.py
tests/cpu/core/fault_event_support.py
tests/cpu/test_agentic_observability.py
tests/cpu/backends/megatron/test_sft_train_data_fields.py
接收 Durable recovery and lifecycle regressions, including rebased fixtures, belong beside the tested module contracts. Existing recovery acceptance criteria and startup/fault lifecycle contracts require these CPU and distributed regression locations. Keep focused production-path tests in existing module-level test files rather than standalone probes.
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.

审查结论:COMMENT

已审查当前 head 4f4ec202d2b1ea60e14ebb7585c3d1236dfdad8b 的 50 个变更文件,重点核对了局部恢复准入与累计预算、Controller 监督和全局回退、Service 重建、ActorFwd 注销与传输重置、权重同步、pending 数据清理及中英文配置说明。未发现可复现的新增缺陷,也没有需要发布为行级意见的问题。

Nyanpasu 审查看板记录了审查范围、结论和当前拆分分析状态。

验证限制:当前未重复运行整套测试;本地审查未覆盖多节点 GPU、Ray Serve/SGLang 实例重建和真实 NCCL 权重接管。当前 PR 检查未显示失败项,仍应以维护者的远端 GPU 回测完成情况作为这些边界的最终验证。

拆分分析子任务返回了与当前 head/inventory 不匹配的 source,结果已丢弃并在 dashboard 中标记为未完成,不影响上述代码结论。

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

@RexFlux
RexFlux force-pushed the feat/recovery-phase1-04-rollout-restart branch from 4f4ec20 to ee5b31d Compare November 10, 2026 14:11

@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

已完成 ee5b31d8 的增量审查,确认一处恢复完成契约缺陷,需在合入前修复。依据为生产调用链、受限 CPU 控制流验证及独立复核;未运行 pytest,真实 Ray/SGLang、GPU/NCCL 权重接管仍未验证。

审查看板记录问题及非阻塞拆分建议。

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

@RexFlux

RexFlux commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator Author

/review

请复核当前提交 473109385363c889510618b814531473995eb339 对“全部替换引擎接管权重后再恢复”P1 的修复。具体处理与回归范围已在原线程回复:#548 (comment) 。全量 pre-commit 和独立只读审查通过,新提交 CI 正在运行。

This comment is replied by codex (GPT-6)

@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.

审查结论:APPROVE

已完成 473109385363c889510618b814531473995eb339 的增量审查。F1 接收端覆盖问题已确认修复并在原讨论回复确认,CPU 测试夹具调整与生产初始化一致,未发现其他需要修改的问题。

审查看板保留问题历史及非阻塞拆分建议。

验证限制:本轮检查了源码与回归用例,未运行 pytest;真实 Ray/SGLang、GPU/NCCL 的恢复及故障注入仍待远程验证。

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.

审查结论:APPROVE

已核对 0a9acde463148b82659f86c31264be62b799b00e:本轮仅补齐 CPU 测试 fixture 的 time / monotonic,保留原行为断言。生产代码及文档与已批准的 47310938 完全一致,F1 修复结论继续适用。

审查看板已保留审查范围、问题历史与拆分建议。本轮未运行 pytest,真实 GPU/NCCL 故障注入仍待验证。

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

@RexFlux

RexFlux commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

针对机器人提出的 A/B/C 拆分建议,本次决定保留单个 PR。我们认可这三个功能边界,保留单 PR 的理由是:

  1. 主要复杂度集中在共同的恢复闭环。 即使 A 只支持 fully-async/hybrid Rollout 恢复,也必须包含训练准入、暂停与排空、健康 ActorFwd 的收权握手、DCS 重置、全部替换接收方校验、数据清理、累计预算及全局回退。不能把健康 ActorFwd 的协议配合全部后移到“ActorFwd 故障自愈”PR,否则 Rollout 恢复本身就不完整。
  2. 三拆对最大一份的缩减有限。 当前 0d38baad...3eaadd2e 的生产代码仅 relax/ 20 个文件、+1360/-218,累计改动 1578 行,净增 1142 行。整个 PR 的 4288 行中,测试为 2490 行、文档为 220 行。按现有函数和测试职责估算,A 仍需约 1300–1400 行生产代码,B(colocate)约 150–200 行,C(独立 ActorFwd 故障重建)约 60–100 行;这些是尚未实际拆分的估算,A 仍占八成以上。
  3. 拆分会引入需要重新确认的中间版本。 A 必须先拒绝尚未实现的 colocate 显式启用,并仅对 Rollout 开启局部监督;B/C 再分别开放相应能力。它们还修改共享的配置、executor 和 transport reset 分支,不能机械按文件或已有 commit 切开。当前完整组合已在 3eaadd2e 完成真实 GPU 功能回测与独立复核;该证据不能直接宣称拆分后的每个中间版本都已通过。

因此本次保持同一恢复契约、实现及对应测试/文档一起交付,并在 PR 说明中突出生产代码的实际改动量。审查仍可按“共享机制与异步/hybrid Rollout → colocate 扩展 → ActorFwd 故障扩展”的顺序进行。如果维护者需要分阶段上线这些能力,我们可以再按 A → B、A → C 的边界拆分;本次不为减少表面行数单独拆出基础设施或测试 PR。

本轮 GPU 回测包括 colocate、fully-async/ActorFwd 共享累计预算、hybrid DCS 自愈,以及真实 NCCL 部分接收成功后的集体拒绝与全局回退。恢复测试使用训练 TP2、推理 TP1、NVLS=0;推理 TP2 恢复仍未完成验收,未验证 checkpoint 续训或性能。详细结果及版本边界已同步到 PR 的 Testing 部分。

This comment is replied by codex (GPT-6)

@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.

审查结论:APPROVE

已完成 077e9ac005d7ed31de1c0010c42dbe870889c34e 的测试精简复核。生产代码和文档与已审 3eaadd2e 相同;关键恢复断言已合并到保留用例,未发现需调整的问题。

审查看板已记录覆盖和验证边界。本轮未运行本地测试;GPU 报告仍绑定 3eaadd2e,原始日志未独立核对。

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.

审查结论:APPROVE

已完成 c78d6cc0676ffaa3a3d206ba8aff325e5c49f759 合入 main 后的复核。S3 缓存清理的启动顺序、局部/全局恢复边界及冲突解决后的关键回归均保留,未发现需调整的问题。

审查看板已记录覆盖和验证边界。本轮未运行本地测试;旧 GPU 报告仍保留原提交边界,未独立验证当前版本的真实 S3/Ray/GPU 恢复。

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

@RexFlux
RexFlux force-pushed the feat/recovery-phase1-04-rollout-restart branch 2 times, most recently from 194d2cb to 90dddd4 Compare November 12, 2026 11:53

@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.

审查结论:APPROVE

已完成 90dddd43a51eec92f587542165d0ecdc9a239673 重放后的复核。启动与故障凭据接口保留实际同步等待,局部恢复仍在全部替换引擎接权后才恢复并发布任务,未发现需调整的问题。

审查看板已记录覆盖与验证边界。本轮未运行本地测试;当前版本的真实 Ray/GPU/NCCL 恢复及 OTLP 导出未独立验证。

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.

复核完成

生产恢复链与新 main 的 LoRA 发布分支未发现新增集成问题;已确认一处取消生成回归测试的 fixture 缺少依赖,当前 CPU CI 在该处失败。建议补全后复核该节点;本轮未运行本地测试或 GPU 故障注入。

审查看板

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

manager.data_source = object()
manager.data_system_client = object()
entered, release = threading.Event(), threading.Event()
generate = _method("rollout.py", "RolloutManager", "generate")

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.

Medium severity P2 · 补全取消生成用例的准入依赖

合入 main 后,generate() 首先调用 _begin_generation(),但这里仅提取 generate 方法,_manager() 返回的隔离对象没有该依赖。任务会在启动 _generate_batch 前失败,entered 不会置位;当前 CPU attempt 1已在第153行等待失败,取消及线程终态断言均未执行。请为这个非被测准入调用提供替身,或绑定真实 hook 及其状态,并保留现有取消/活跃标记断言。

Suggested change
generate = _method("rollout.py", "RolloutManager", "generate")
manager._begin_generation = Mock()
generate = _method("rollout.py", "RolloutManager", "generate")

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.

已核对 7f41270f05099d21c7383277ee6c6c77c62fdce9:用例绑定真实 _begin_generation 并提供 RLock,原有3秒等待、取消异常、线程活跃与终态断言均保留。当前 CPU attempt 1中该节点已通过,确认此问题已修复。

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

@RexFlux
RexFlux force-pushed the feat/recovery-phase1-04-rollout-restart branch from 8884516 to 7f41270 Compare November 16, 2026 07:04

@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.

复核通过

已核验取消生成用例的修复,本次 rebase 的共享字段、teacher PG 与 NEXTN 同步交互未发现新增问题。当前必需 CI 全部通过;未重跑 GPU 故障注入、多节点或 checkpoint 续训。

审查看板

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

@RexFlux RexFlux self-assigned this Nov 16, 2026
RexFlux and others added 6 commits November 16, 2026 15:43
Recover existing inference services at complete-batch boundaries while keeping training state. Preserve the current background-loop, startup synchronization and global restart lifecycle. Adapt hybrid recovery to the tensor weight updater and place CPU coverage in the current test layout.

Co-authored-by: Codex <[email protected]>
Name the global restart request consistently without changing the current restart ownership and error handling.

Co-authored-by: Codex <[email protected]>
Make the shared cumulative inference recovery budget configurable, preserving the default of three attempts.

Co-authored-by: Codex <[email protected]>
Document recovery controls, supported role layouts, cumulative budgets and data-loss boundaries in both languages.

Co-authored-by: Codex <[email protected]>
Use the inference recovery environment switch consistently across implementation, tests and user documentation.

Co-authored-by: Codex <[email protected]>
Clarify discarded rollout data and the resulting off-policy boundary before users enable recovery.

Co-authored-by: Codex <[email protected]>
RexFlux and others added 15 commits November 16, 2026 15:43
Retain every server handle so inference teardown also closes non-head server processes.

Co-authored-by: Codex <[email protected]>
Guard final rollout data while preserving the recovery admission and completion boundaries.

Co-authored-by: Codex <[email protected]>
Centralize recovery environment definitions in the standard typed registry and document accepted values.

Co-authored-by: Codex <[email protected]>
Use the real disabled recovery gate in lightweight component fixtures, bind the current restart wrapper and drain boundaries, and retain initial weight response and non-head process teardown coverage in the CPU suite.

Co-authored-by: Codex <[email protected]>
Extract one training step so the background loop keeps recovery admission,
failure reporting and release in one place. Use a narrowly scoped suppress
context for best-effort heartbeat submission while preserving training and
partition-cleanup failures, health-report acknowledgement and step ordering.

Adapt existing AST fixtures to load the extracted helper. Relevant CPU
regressions pass without adding duplicate tests.

Co-authored-by: Codex <[email protected]>
Move local inference drain, data cleanup and weight restoration into an
executor while Controller keeps worker supervision and publishes replacement
tasks on the original async loop under its restart lock.

Let the checkpoint client own strict forward unregistration without changing
best-effort shutdown semantics, and place the SimpleStorage recovery adapter
under TransferQueue utilities. Adapt existing regressions to the new owners.

Co-authored-by: Codex <[email protected]>
After rebasing onto Hybrid DCS, reset the idle inference transport and
resynchronize the replacement through the existing DCS sender. Remove the
obsolete tensor updater recovery entry point and extend the activation
regression to cover Hybrid without a standalone ActorFwd.

Preserve upstream's completed-partition guard in the recovery-aware
Advantages loop so an Actor deleting a finished partition cannot strand
its consumer.

Co-authored-by: Codex <[email protected]>
Capture the replacement Rollout engine identities and require DCS to confirm
that every receiver completed weight synchronization before resuming. Share
any mismatch with all training ranks before raising and keep the ordinary
elastic weight-sync pruning behavior unchanged.

Cover partial synchronization, empty and unexpected recipient sets, sender
error propagation, and failure before recovery publication. Adapt recovery
fixtures and fault-event assertions to the rebased main contracts.

Co-authored-by: Codex <[email protected]>
The extracted Controller now uses a monotonic drain deadline before global
restart. Supply the real time module to the AST fixture and preserve
monotonic in the fake clock used by the teardown test.

Co-authored-by: Codex <[email protected]>
Consolidate restart signalling and cancellation checks into stronger existing
cases, retain global reinitialization arguments and process-tree cleanup
assertions, and merge default/custom recovery budget coverage.

Remove an unrelated shutdown test and revert unnecessary affinity fixture
rewrites. Fix the health-report fixture so it exercises the acknowledged
report and wait path instead of an accidental missing-ray exception.

Co-authored-by: Codex <[email protected]>
Accept upstream recovery tokens in initial-sync regression tests.
Adapt global-startup and receipt fixtures to the existing recovery guard
and real worker completion, without changing their assertions.
Apply required formatting to the combined receipt and strict-sync path.

Co-authored-by: Codex <[email protected]>
Provide the extracted Controller namespace and component recovery state
required after rebasing on main. Preserve the existing real Ray/Serve
global recovery assertions and disable local recovery in these fixtures.

Validated the three failing cases on the remote CPU Ray environment.
No production code changes.

Co-authored-by: Codex <[email protected]>
Wait for a FIFO writer barrier before checking the live appender limit
and persisted stage records. The test must not rely on completing all
I/O within the production close deadline, which can discard queued work.
Preserve the descriptor bound and every record/content assertion.

Co-authored-by: Codex <[email protected]>
Bind the real generation admission method and lifecycle lock in the
thread cancellation fixture so it reaches the generation thread.
Preserve the timeout, cancellation and worker-idle assertions.

Extend the existing score-centering field cases to cover fully-async
training and the upstream support-complete field.

Co-authored-by: Codex <[email protected]>
Provide a completed thread-safe drain future in the recovery fixture,
matching the main global-recovery fixture and new training completion
contract. Preserve the recovery, cancellation and cleanup assertions.

Co-authored-by: Codex <[email protected]>
@RexFlux
RexFlux force-pushed the feat/recovery-phase1-04-rollout-restart branch from 7f41270 to ef0022c Compare November 16, 2026 07:47

@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.

复核完成

本轮确认一处评测收尾与全局接管的竞态,详见行内评论。已核验当前 CPU CI 与受控 Controller 调度复现;未进行真实 Ray/GPU 故障注入、多节点或 checkpoint 续训。

审查看板

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

Comment thread relax/core/controller.py
Comment on lines +1813 to +1818
self._cancel_pending_tasks()
if (worker is not None and worker.is_alive()) or not self._training_wait_done.wait(
max(0, deadline - time.monotonic())
):
logger.error("Old recovery or service waiter did not exit; refusing overlapping deployments")
os._exit(1)

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.

Medium severity P2 · 将评测收尾等待的登记与全局接管互斥

这里新增的退出屏障与上游评测收尾存在竞态:所有服务返回后,run_all_services 会先 await get_rollout_manager(),再登记 drain_future。若健康检查线程在这个 await 期间接管并执行这里的一次性取消,查询返回后仍会登记新的等待;它不在取消快照内,_training_wait_done 就无法置位。慢 judge 超过默认 180 秒后会在下方 os._exit(1),尚未走到原有 Manager 清理和全局重建。

可达场景是开启健康检查、关闭局部恢复时,末尾 Rollout 数据保存报错后返回,而 Actor 已消费完最后一批;独立 HTTP 评测仍在重试。真实 Controller 方法的两种 CPU 时序复现了这个差异:先登记再取消可退出,先取消再登记则请求进程退出;RPC、judge 与进程退出均由替身隔离,未做真实 Ray 故障注入。

请沿用 _activate_inference_recovery 的接管锁纪律,在查询返回后将“检查本代未被接管、提交并登记收尾 Future”与重启取消互斥;接管后不要再创建新等待。保留正常评测 drain 和活跃恢复线程的退出保护,并覆盖延迟查询后登记的时序。

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

@RexFlux RexFlux Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

这条 P2 成立,已在 0ab3d29ad44f7fee7366ef675a2d710d83a63fda 做最小修复。

Manager 查询仍在锁外;查询返回后,在同一个 _restart_lock 临界区内检查 _restarting、提交 drain RPC 并登记其线程安全 Future。接管先发生则不再提交新 drain;登记先发生则重启取消快照能看到该 Future。真正的 drain 等待仍在锁外,正常评测收尾、活跃恢复线程退出保护和训练 waiter 屏障都保留,没有延长超时或跳过清理。

新增一个三时序参数化回归,覆盖正常慢 drain、先登记后接管,以及查询延迟导致先取消后返回。远端 CPU 对照中,旧代码为 2 passed / 1 failed,最后一种时序触发 os._exit(1) 替身;修复后四个相关 CPU 测试文件共 116 passed、0 failed、0 skipped,包括真实 CPU Ray/Serve 回归。RPC、judge 与进程退出仍由替身隔离,不将其声称为真实 GPU 故障注入。

全量 pre-commit 与独立只读复核通过。当前提交的必需 GitHub CI 已全部通过:CPU 为 9853 passed、0 failed、155 skipped,另有 3 个 subtests passed;H20 单卡/四卡单测和三项 GPU/NPU 集成测试均通过。单测运行记录,集成测试。

This comment is replied by codex (GPT-6)

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.

已核对 0ab3d29ad44f7fee7366ef675a2d710d83a63fda:接管检查、drain 提交及 Future 登记位于同一个 _restart_lock 临界区,等待在锁外;原先已取消后再登记的窗口已关闭,正常 drain 和活跃线程退出保护保留。

当前 CPU attempt 1中,正常慢 drain、查询期间接管、登记后接管三个回归节点均通过。RPC、judge 和进程退出由替身隔离,未将其视为真实 Ray/GPU 故障注入。源码修复已确认。

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

RexFlux and others added 2 commits November 16, 2026 17:17
Guard eval drain submission and pending-future registration with the
restart lock, rejecting new waits after takeover. Keep the manager
lookup and drain wait outside the critical section.

Cover normal completion, cancellation after registration, and a delayed
manager lookup that returns after the cancellation snapshot. The latter
reproduces the old forced-exit path; all 116 related remote CPU tests
pass with the fix, including real Ray/Serve recovery cases.

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.

复核通过

已核验 0ab3d29a 的接管锁修复和对应 CPU 回归,未发现剩余审查问题。未进行真实 Ray/GPU 故障注入、多节点或 checkpoint 续训。

审查看板

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

Yangruipis added a commit that referenced this pull request Nov 18, 2026
## What

新增只读架构专家,并接入仓库的专家入口与 code-review skill。包含专家定义、加载入口、review
skill,以及直接写入专家正文的架构案例。

## Why

功能测试通过无法说明代码职责归属合理。架构评审需要判断代码放置、模块边界、依赖方向,以及新增抽象是否必要,避免只修局部故障或移动同一份耦合。

## How

- `arch-expert.md` 提供完整专家指引;复用现有 `.codex/agents`、`.claude/agents` 到
`.opencode/agents` 的链接。
- `arch-expert.toml` 定义 Codex 自定义代理 `arch_expert`,要求先完整读取
Markdown,并保持只读。
- `AGENTS.md` 增加架构任务触发入口及不同工具中的代理名称。
- code-review skill 要求审视完整职责链,并单独给出设计合理性与简洁性的结论。
- `.codex/agents/arch-expert.md` 正文内直接记录 #548 → #705
的职责优化案例:组件统一编排、Controller 协调恢复、资源操作归拥有者,并删除内部兼容双路径。案例随完整专家指引一起读取,无独立
reference 文件。

不包含 recovery 实现、实验记录或 RSI 专用回执/等待流程。

### 专家如何产出:以真实改动驱动指引迭代

这份专家指引通过 DeepSeek 与 Codex 分工的 RSI 迭代形成:DeepSeek 负责生成和改进
`arch-expert.md`,独立 Codex 将指引用于真实 PR
的架构评审与修改,主评审根据代码结果给出反馈。迭代对象是可复用的架构判断方法,代码改动则用于检验指引是否能落实到职责、边界和调用关系上。

```mermaid
flowchart TD
    A["真实任务:评审 PR548 的恢复架构"] --> B["DeepSeek 生成或改进专家指引"]
    B --> C["固定本轮 MD 与代码起点版本"]
    C --> D["新开独立 Codex 会话<br/>不继承上轮对话,完整读取专家指引"]
    D --> E["检查相对 main 的完整 diff<br/>优化架构并验证行为"]
    E --> F["主评审独立评估代码结果<br/>按固定标准评分"]
    F --> G{"是否继续迭代?"}
    G -->|"未达预期且未到上限"| H["向 DeepSeek 返回分数与概括评语<br/>不提供评分细则或具体修复方案"]
    H --> B
    G -->|"符合预期或达到轮次上限"| I["整理专家指引、代码结果与验证结论"]
    I --> J["通用专家进入 PR706<br/>架构实践与案例见 PR705"]
```

流程设置最多 10
轮,以架构评审结论决定是否继续。评测侧关注职责归属、模块位置、依赖方向、抽象必要性及行为保持;反馈给指引生成侧时仅保留分数与概括评语,避免把具体修复答案写进专家规则。独立会话及显式加载用于减少历史上下文干扰;功能测试用于验证行为保持,架构合理性由完整职责链的评审判断。过程中结合维护者反馈校准架构目标,最终将实践经验整理为通用指引。

### 实践案例:从 PR548 到 PR705 的推理恢复职责优化

[PR548](#548)
提供真实恢复场景,[PR705](#705)
展示后续完成的职责重构。关键问题是训练后端同时承担服务握手、恢复准入和 RL HTTP 评估,而独立 Executor 又借用
Controller 的状态进行恢复编排。优化围绕“控制决策归编排者,资源操作归拥有者”展开,范围为 Megatron 路径。

```mermaid
flowchart TB
    subgraph Before["原实现 PR548"]
        BC["组件"] --> BT["训练 rank<br/>计算、恢复准入、服务握手、同步与评估"]
        BX["独立恢复 Executor"] --> BS["借用 Controller 的服务集合与状态"]
    end
    subgraph After["职责重构 PR705"]
        AC["组件<br/>阶段编排与 RecoveryGate"] --> AT["训练后端<br/>计算、模型状态与通信操作"]
        AC --> AS["同步协调模块<br/>服务握手、接收方选择与 RL 评估"]
        CT["Controller<br/>恢复流程编排"] --> OW["Service / Rollout / updater / DCS<br/>各自管理资源、清理与接收确认"]
    end
```

- 组件统一执行训练、同步、评估阶段;恢复开关控制准入与失败处理,收敛内部兼容双路径。
- 跨服务握手和 RL HTTP 评估从训练 rank 移到同步协调模块;后端保留模型、CPU 快照、通信操作与本地离线评估。
- 没有独立资源或生命周期的 Executor 收回 Controller;生成窗口清理由 Rollout 封装,传输资源与完整接收确认由
updater/DCS 管理。

这些调整减少跨层状态依赖和重复路径,保持用户可见的训练与恢复语义。案例已直接写入 `.codex/agents/arch-expert.md`
正文,供后续评审参考职责判断方法;具体目录与抽象仍需依据实际调用链决定。

## Testing

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

- 全量 pre-commit 检查通过。
- skill validator 与 TOML 解析通过,确认共享 Markdown 链接可解析。
- 原提交 `6ad2f58` 已通过 Codex CLI 0.167.1 新会话启动 `arch_expert`
的加载检查,子代理不继承历史,返回的专家文件 SHA-256 与该版本一致,并确认只读角色及正文规则。
- 已将案例并入专家正文,删除独立 reference 文件及跳转;确认 `.codex/agents`、`.claude/agents` 与
`.opencode/agents` 入口内容一致。合并后未重跑子代理加载实验。
- 未运行训练测试:本 PR 只改变开发代理配置与工作指引,不修改训练实现。加载检查不等于架构判断质量评测。

## 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)
- [x] Documentation update
- [ ] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

无需截图。加载检查在临时目录执行,未将实验产物加入仓库。

---------

Co-authored-by: Yangruipis <[email protected]>
RexFlux pushed a commit that referenced this pull request Nov 25, 2026
## What

#791 已合入 `main`。本 PR 以 `main` 为基线,Files changed 展示 Rollout 和 ActorFwd
局部恢复的增量。

这个 PR 让 Controller 在支持的训练配置下局部重建失败的 Rollout 或 ActorFwd,并保留原训练
Actor、优化器与调度器。恢复时先停止准入,等待旧操作结束,再清理未训练分区、重建推理资源、确认权重完整接收并继续训练。无法确认安全时转入全局重启。

## Why

单个推理服务故障也可能触发整个训练作业重启。局部恢复需要确定旧服务已交还共享资源、训练进度可续接,以及替换实例拿到了完整权重。

## How

- Controller 仲裁局部恢复与全局重启。各组件负责训练批次准入、权重发布和故障上报。
- Rollout
负责在重建前排空评估、关闭旧引擎和路由进程。训练侧检查每个流水线阶段的接收者。评估插件明确上报的评分错误在恢复期间仍会终止作业。
- 默认的 Rollout 缓冲数据源清空待处理样本并保留读取游标。自定义 `--data-source-path` 需实现
`discard_pending()`,清空待处理样本并保留游标。缺少该方法或调用抛错时,Controller 会转入全局重启。
- 包含相应的 CPU 回归和中英文恢复指南。生产代码相对新基线为 25 个文件,新增 1,678 行、删除 262 行。

## Testing

在单机 H800、CUDA 12 上,用 Qwen2.5-1.5B-Instruct 和 GSM8K 跑 Megatron + SGLang 的
GRPO 训练。前三组从 `a091790c` 的干净归档启动,第四组直接从 PR 最新提交 `1e6e9c09`
的干净归档启动。两版只差中英文指南,`relax/` 的 Git tree 均为 `02e41bd1`。

| 真实运行中注入的故障 | 实际恢复结果 |
| --- | --- |
| Colocate、4 张卡。完成前两步后让 Rollout 生成调用抛出异常 | 115 秒完成一次局部恢复。原 4 个训练 rank
各跑完第 0–5 步,模型、优化器和调度器对象均保留。4 个新 SGLang 引擎的权重版本均为发送端的 `4`。 |
| Fully async、6 张卡。让两个 ActorFwd rank 在第 2 步抛出异常并保持存活 | 79
秒完成一次局部恢复。原训练进程跑完第 0–7 步。恢复放行前,分别比较每个 TP 分片的全部 198 个具名参数,每个分片
1,543,801,856 字节,发送方与新 ActorFwd 的 SHA-256 逐分片一致。 |
| Fully async、6 张卡。让两个 ActorFwd rank 在第 2 步通过 `os._exit(86)` 退出 | Ray 报告
`ActorDiedError`,Controller 判定局部恢复不安全,执行一次全局重启。此配置未保存
checkpoint,新训练进程从初始模型重跑第 0–7 步。 |
| Hybrid、6 张卡。重建 Rollout 后,从实际权重广播组中移除两个替代引擎中的一台 | 一台引擎收到更新并升至版本
`3`,另一台没有收到更新。4 个原训练 rank 各自上报缺少同一接收方,Ray 独立记录了 4 个失败任务。局部恢复被拒,原训练 rank
停在第 1 步。全局重启一次,4 个新 rank 均重跑完第 0–5 步。 |

四组训练作业的退出码均为 0。本轮故障注入使用单机。

另在 `1e6e9c09` 的隔离 CPU Ray/Serve 作业中加载了缺少 `discard_pending()` 的自定义数据源。第 0
步训练结束后杀掉推理子进程,生产 Rollout 清理待处理样本时抛出 `AttributeError`,Controller 进入第 1
次全局重启。本组用轻量训练和队列替身,观察至全局重启入口。

- `a091790c` 基于 `main@7354e4f`。在指定 CU12 镜像上从该提交导出的干净代码复跑了 13 个相关文件,393
项全部通过。切换前后的完整 Git 补丁经逐字节比对相同,共 69 个文件,新增 5,676 行、删除 403 行。
- 在 CU12 镜像中隐藏 GPU,在拆分时运行 14 个文件的定向测试,337 项通过。涵盖 Controller
局部与全局重启、Rollout/ActorFwd 重建、权重接收确认和评估异常传播。
- 拆分完成时的 `b3a8059e` 与将原获批版本 `051bb106` 合到 `main@b9142f9`
的文件树相同。之后的前置复审修复已同步到 `d48ea79a`。此提交在 CU12 运行 13 个 CPU 文件,393
项通过,覆盖故障恢复、权重同步、评估和计时。此次未重跑多节点 GPU 故障注入。
- 双 rank 真实 Ray 实验覆盖两种权重更新入口。两个 rank 都结束后才开始评估。一个 rank 明确失败时等待其余 rank
结束,再返回原始错误;另一个 rank 超时未结束时返回 `UnsafeInferenceError`。

- [ ] `pre-commit run --all-files` passes
- [x] Tests pass (targeted suite above)
- [x] New tests added (if applicable)
- [x] 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)
- [x] Documentation update
- [ ] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

前置编排及该版本的独立验证见 #791。下方保留此前 #705 的完整范围、复跑命令与逐版验证记录。

<details>
<summary>拆分前的背景与验证记录(截至 051bb10)</summary>

## What

基于 [#548](#548) 的独立实现修订稿,面向
`main`。保留局部推理恢复功能与中英文文档,重新划分恢复、同步和训练职责。

- Rollout 或独立 ActorFwd 明确失败时,在共享累计预算内局部重建;保留原训练 Actor、optimizer 和
scheduler。排空旧工作后丢弃未训练半成品,输入 cursor 不回退;无法安全恢复时转全局重启。
- Controller 直接编排跨服务恢复,删除无状态的 `core/inference_recovery_executor.py`
包装层。组件拥有恢复准入与训练/推理阶段边界,Ray 组级协调负责服务握手和权重派发,训练 rank 不读取共享恢复状态或决定恢复策略。
- Rollout 管理恢复窗口及替换实例的 router 地址;Megatron 保留本地训练状态和 CPU 快照导出;updater、DCS
分别负责传输资源和完整接收确认。
- 组件始终编排训练、同步和评估,删除后端 defer 参数与旧整步兼容路径;recovery 开关只控制准入和失败处理。hybrid
的训练指标在评估请求之后刷新,具体时序见下文。FSDP 实现保持原有行为。

仅包含 recovery 生产代码、测试和文档,不包含 agent、skill、加载配置或实验产物。

## Why

原实现让训练 Actor 感知推理服务的恢复准入、生命周期与握手时序。只移动 helper
不能解除职责耦合;引入无实际职责的中间执行器也增加追踪成本。此次让既有资源所有者承担相应职责,并在真实训练中验证行为。

## How

### 架构对照与范围

对照原作者 #548 接手时的 `0ab3d29a` 与当前实现 `2ee4ffc`,主要针对 Megatron。FSDP
实现保持原有契约;此次调整未扩展到整个后端体系。

原作者实现中,组件已有任务准入,但训练 rank 内仍包含同步准入、服务握手和 RL HTTP 评估:

```text
Controller
    |
    +--> Actor 组件 -> RayTrainGroup -> Megatron Actor(每个 rank)
    |                                   |
    |                                   +-- 模型训练
    |                                   +-- 读取共享恢复状态
    |                                   +-- _begin_inference_sync()
    |                                   +-- 等待 eval、探测 Rollout / ActorFwd
    |                                   +-- 选择接收方、发送权重、请求 RL eval
    |                                   '-- _end_inference_sync()
    |
    '--> InferenceRecoveryExecutor
             +-- 清理 TQ、直接操作 Rollout 内部对象
             +-- 调用 Service 重建
             '--> 训练 Actor 的恢复方法
                      +-- 操作 updater 内部资源
                      '-- 调用 Rollout 权重 / KV onload
```

### 当前正常训练路径

组件决定阶段时序,训练后端执行持有模型与通信资源的具体操作:

```text
Actor 组件
    |
    +-- 1. RayTrainGroup -> 所有 Megatron rank 执行训练
    |                         +-- 模型 / optimizer 更新
    |                         +-- 保存、备份、训练状态驻留管理
    |                         '-- 返回
    |
    +-- 2. RecoveryGate:决定是否允许进入同步
    |
    +-- 3. inference_sync:跨服务协调
    |          +-- 等待上一轮 eval
    |          +-- 与 Rollout / ActorFwd 握手、选择接收方
    |          +-- 派发各 rank 的权重发送操作
    |          '-- 请求 RL eval、结束握手
    |
    '-- 4. 完成指标收尾、保存及训练步提交
```

开启和关闭 recovery 都由组件编排这条正常路径;开关只控制准入、排空和失败处理,不再选择编排发生在哪一层。删除
`defer_inference` / `defer_weight_receive` 双路径。

Colocate 发送权重后刷新训练指标,再请求评估。full-async 在推理阶段之后刷新。主线 hybrid
在发送权重后、请求评估前刷新,本 PR 的 hybrid 在请求评估并完成 Rollout
释放握手后刷新,最后一步还会先等评估结束。已验证调用顺序和刷新所用的训练步编号;未在相同训练输入上逐项对比两版上报的指标值或上报时间。离线训练保留所有模型
rank 参与的本地评估/predict,不进入普通 RL 服务握手。ActorFwd 和 reference 均由组件显式调用:

```text
前向组件 -> 后端 compute -> 后端 receive weights -> 后端 finish metrics
```

### 当前故障恢复路径

```text
Rollout / ActorFwd 明确异常
              |
              v
         Controller
              +-- State:检查共享累计预算、暂停新准入
              +-- 等待旧操作结束
              +-- TQ 存储层:清理未训练分区
              +-- Rollout 组件:丢弃未完成生成窗口
              +-- Service:确认旧子进程退出、重建失败服务
              |
              +-- 同步替代实例
              |      +-- 训练后端:提供当前权重 / CPU 快照
              |      +-- updater / DCS:准备传输、确认接收完整
              |      '-- Colocate Manager:恢复权重和 KV 显存
              |
              '-- 恢复准入、启动并登记替代任务

预算耗尽 / 无法安全完成 -> Controller 原有全局重启
```

发送和接收两端使用明确且一致的 `sync_step`,避免从 checkpoint 启动时使用尚未对齐的组件 step
推导接收集合。保持原训练 Actor、optimizer 和 scheduler 的局部恢复语义;全局重启仍遵循原有重建路径。

### 职责归属变化及理由

| 职责 | 原作者 #548 | 当前 #705 |
| --- | --- | --- |
| 同步阶段准入 | 训练 rank 读取恢复 State,再广播决定 | 组件层 RecoveryGate 决定 |
| 服务探测、等待、接收方选择 | Megatron Actor 内 | inference_sync |
| RL HTTP 评估 | Megatron Actor 内 | inference_sync |
| 恢复窗口清理 | Executor 直接访问 datasource、manager | Rollout 组件封装自身清理 |
| 恢复时传输资源准备 | Actor 操作 updater 内部字段 | updater / DCS 处理 |
| 跨服务恢复流程 | Controller → Executor | Controller 直接编排 |
| 恢复策略与通用等待逻辑 | 混在 core/inference_recovery.py | components/recovery.py 与
distributed/settlement.py 分别承担 |

Controller 已拥有服务集合、恢复任务和全局接管约束,因此将没有独立资源或生命周期的 Executor
收回其私有恢复流程。Rollout、Service、updater/DCS 管理自己的状态和资源,减少外部调用方穿透内部实现。

训练后端仍保留权重发送、CPU 快照、通信客户端重置和本地离线评估等操作,因为模型与相应资源实际驻留于各
rank。此次迁移的重点是服务级决策和编排;用户可观察的行为契约需要保持,旧私有调用形态不自动构成兼容要求。

### 容错配置

SFT、DPO、RM 等离线模式通过共享的 `is_offline_mode()` 判定排除组件级恢复,不创建 RecoveryGate
的恢复状态;保留用户的 `use_fault_tolerance` 配置及既有离线训练路径,避免等待 RL 的 `train_<step>`
分区。

统一使用 `--use-fault-tolerance` 开启容错,默认关闭。支持组件级恢复的配置使用 Controller
恢复流程,并停用旧引擎监控、自动重建和旧 CI 注入;其他配置保留原有引擎级容错。同步暂停握手保留,新旧恢复互斥。

删除 `RELAX_ENABLE_INFERENCE_RECOVERY`;保留
`RELAX_INFERENCE_RECOVERY_MAX_ATTEMPTS` 与
`RELAX_INFERENCE_RECOVERY_DRAIN_TIMEOUT`。局部尝试预算与 `--max-global-restart`
仍分别计数。

## Testing

`051bb106` 的 8 项必需检查全部通过。[CPU 和 H20
单卡、四卡单测](https://github.com/redai-studio/Relax/actions/runs/45560407513)中,CPU
为 10,948 项通过、115 项跳过,另有 31 个子用例通过。[双卡 GPU 多模态、四卡 GPU 异步、四卡 NPU
异步集成](https://github.com/redai-studio/Relax/actions/runs/45560407572)、[文档构建](https://github.com/redai-studio/Relax/actions/runs/45560407476)和[静态检查](https://github.com/redai-studio/Relax/actions/runs/45560407503)均通过。本轮在指定
CU12 镜像单独运行 207 项相关回归,包含恢复排空、评分插件回退和数据集自定义生成器的显式评分异常。本轮没有运行多节点 GPU 故障注入。

### 自定义评分回退


[复审](#705 (review))
确认前次五项反馈已修复,并指出自定义 reward
内部回退成功后仍可能误报终止错误。[b0ac3ca](b0ac3ca)
保留插件捕获的原始异常类型,只登记实际退出评估任务的评分失败。指定镜像中验证了普通打分和分组打分、内联和后台评分。插件返回有效分数时训练会保留该分数。同批另有生成失败时,训练收到原生成错误。插件未处理的评分失败仍以
`EvalJudgeError` 传回。


[7828ff9](7828ff9)
修复了任务组中未处理的评分错误在恢复排空时被丢弃的问题。[051bb10](051bb10)
修复了[复审发现的另一种包装方式](https://github.com/redai-studio/Relax/pull/705#discussion_r4691152265)。插件用
`raise ... from exc` 给同一评分失败补充说明时,Manager
的评估和恢复排空都会报告评分错误,并保留插件说明。插件已处理评分失败、后备生成请求自身失败时,评估仍报告生成错误。

**自定义评分回退(CPU,验证镜像 `qs-20261124-447fe38f-cu12`)**

- **仓库回归**。SGLang 的单样本内联用例在同批注入生成失败。自定义评分捕获 `ValueError` 后,评估报告生成的
`ConnectionError`。放行评分异常时,评估报告
`EvalJudgeError`。后台评分和同步评分各有一个单样本用例,在测试进程直接调用 `EvalJudgeWorker.score` 和
`RewardWorker.compute_custom`,均断言得分 4.5。
- **分组评分**。额外的同进程 `RolloutManager.eval → SGLang → RewardExecutor` 探针开启
`group_rm=True`,每个 prompt 生成一条。组评分捕获原始异常后得到 `[4.5]`。同批再注入一个生成失败时,Manager
抛出 `ConnectionError`,记录的评分错误数为 0。单独直接调用后台
`EvalJudgeWorker.score`,单样本和分组请求也都得到 `[4.5]`。
- **真实 Ray RPC**。额外启动本地 Ray,向独立进程中的同步 `RewardWorker` 发起单样本
`compute_custom.remote`。局部恢复关闭、开启各一次,插件均捕获原始 `ValueError` 并返回
4.5。仓库里另有两个 RPC 用例分别核对独立 worker PID,以及三条样本的批量返回顺序和数量。

<details>
<summary>从 checkout 根目录复跑仓库用例</summary>

```bash
T=tests/cpu/engine/rollout/test_weight_sync_499.py
R=tests/cpu/engine/rewards/test_custom_reward_worker.py::TestCustomRewardDispatch
python -m pytest -q \
  "$T::test_eval_only_prioritizes_unhandled_custom_reward_errors" \
  "$T::test_deferred_judge_records_custom_reward_fallback" \
  "$T::test_sync_reward_worker_preserves_custom_reward_fallback" \
  "$R::test_sync_reward_runs_in_worker_without_blocking_event_loop" \
  "$R::test_batched_sync_custom_reward_keeps_payload_contract"
```

</details>

<details>
<summary>复跑额外的 SGLang 分组评分和同步 RewardWorker RPC</summary>

第一条命令复用单样本用例的故障注入和断言,将评分切到 `group_rm=True`。同批含一条生成失败,分别检查评分回退成功和未回退时的错误。

```bash
probe_dir=$(mktemp -d)
cat > "$probe_dir/test_pr705_group.py" <<'PY'
import pytest
from test_weight_sync_499 import (
    _reward_with_fallback, native_eval, nested_eval_reward, sglang_rollout,
    test_eval_only_prioritizes_unhandled_custom_reward_errors as single_case,
)

async def group_reward(args, group, *, evaluation):
    assert isinstance(group, list)
    return [await _reward_with_fallback(args, s, evaluation=evaluation) for s in group]

@pytest.mark.asyncio
@pytest.mark.parametrize("fallback", [True, False])
async def test_group(monkeypatch, nested_eval_reward, fallback):
    args, _, _ = nested_eval_reward
    args.group_rm = True
    args.custom_rm_path = f"{__name__}.group_reward"
    sglang_rollout.GenerateState(args).aborted = False
    await single_case(monkeypatch, nested_eval_reward, fallback)
PY
PYTHONPATH="$PWD/tests/cpu/engine/rollout:$PWD:${PYTHONPATH:-}" \
    python -m pytest -q "$probe_dir/test_pr705_group.py"
```

第二条命令在独立的 Ray worker 注册故障评分器,调用仓库的同步回退插件。

```bash
PYTHONPATH="$PWD/tests/cpu/engine/rollout:$PWD:${PYTHONPATH:-}" python - <<'PY'
from argparse import Namespace
import ray
from relax.engine.rewards import RewardWorker
from relax.utils.types import Sample

def register_failing_reward():
    from relax.engine.rewards import register_reward
    async def fail(args, sample):
        raise ValueError("injected")
    register_reward("probe_invalid", fail, mode="async")

ray.init(address="local", num_cpus=2, num_gpus=0, include_dashboard=False,
         runtime_env={"worker_process_setup_hook": register_failing_reward})
try:
    worker = RewardWorker.remote()
    path = "test_weight_sync_499._sync_reward_with_fallback"
    for recovery in (False, True):
        args = Namespace(inference_recovery=recovery, custom_rm_path=path, rm_type="probe_invalid",
                         allow_reward_fallback=True, eval_reward_key="score")
        ref = worker.compute_custom.remote(path, args, Sample(prompt="x"), {"evaluation": True})
        assert ray.get(ref, timeout=60) == {"score": 4.5}
finally:
    ray.shutdown()
PY
```

</details>

### 健康回调与并发评估错误

[修复提交
14fbf5d](14fbf5d)
将同角色健康回调的检查放在认领重启的锁内。正常训练收尾时,已知的评分或上报错误优先。只有生成失败时,仍会及时报错。原生 SGLang 评估将缺少
reward 字段识别为评分失败,并在同一请求的并发数据集和样本间保留已观察到的评分错误。

指定 CU12 镜像的 127 项定向测试通过。真实 CPU Ray/Serve
对照中,同一个评分响应缺少配置字段时,前一提交清理了训练分区一次,修复后 Controller 收到带字段名的
`EvalJudgeError`,分区清理次数为零。另验证了后台评分卡住、指标写入失败与 RPC
延迟返回的情况。中英文站点构建通过。本机未运行多节点故障注入。

该提交的 8 项必需检查均已通过。CPU 为 10,941 项通过、115 项跳过,另有 31 个子用例通过。H20 单卡、四卡单测以及两项
GPU 和一项 NPU
集成均通过。[单元测试](https://github.com/redai-studio/Relax/actions/runs/45553981925)
· [集成测试](https://github.com/redai-studio/Relax/actions/runs/45553982024)

### 并发评估与恢复

[行为修复
b71dd88](b71dd88)
处理了 2 个 P1 和 2 个
P2。局部恢复等待旧操作、评估提交和评分共用同一截止时间。恢复线程在退出前记录终止性的评分错误,防止后续健康回调将其覆盖。旧 Rollout
在排空前关闭评估入口,并跟踪每个已受理请求的生成、评分和上报。

- 在 CU12 训练镜像中,该提交通过 1,275 项 CPU 回归和 10 个子用例。
- [后续修复
bda8ba6](bda8ba6)
修正 OpenAPI 构建时意外导入评分运行时依赖的问题,并修正 docstring 格式。该版本在镜像中复跑 59
项定向回归,全部通过。在仅安装 FastAPI、Pydantic 及其依赖的环境中,四份 OpenAPI 和中英文站点成功生成。
- 在该版本的真实 CPU Ray/Serve 进程中,较晚请求先完成时查询返回 `done=false`,排空后的新请求返回 HTTP
503。内联结果写入失败以及另一请求仍卡在生成时的后台评分失败都能传回。将恢复预算设为 1 秒并让评估卡住,Controller 在 1.001
秒后超时,清理训练分区调用次数为 0。本机未运行 GPU 或多节点故障注入。


最终提交的[远端单测](https://github.com/redai-studio/Relax/actions/runs/45549625308)全部通过。CPU
为 10,931 项通过、115 项跳过,另有 31 个子用例通过。H20 单卡、四卡单测以及 [Qwen3.5 双卡视觉语言、四卡 GPU
异步、四卡 NPU
异步集成测试](https://github.com/redai-studio/Relax/actions/runs/45549625344)均通过。

**前次复审修复**


[415fc62](415fc62)
修复了四种恢复场景。

- 在 fully-async 和 hybrid 下,如果 Actor 已提交最后一步,或重建未训练分区所需的消费者已经退出,Rollout
故障会在清理分区前转全局重启。
- hybrid 和 colocate 启用 `--keep-old-actor` 时使用引擎级容错,保证旧策略快照按原训练流程轮转。纯
fully-async 仍支持组件级恢复。
- 替换 Rollout 前等待旧实例完成已提交的异步评分和上报。评分失败会传回训练入口,全局重启也可以接管仍在等待评分的局部恢复。
- 从 checkpoint 加载游标遇到数据集指纹不匹配时,训练直接报告原始错误,保留推理恢复预算。

在 cu12 训练镜像中运行了 34 个相关 CPU 测试文件,1072 项测试和 10 个子测试全部通过。真实 CPU Ray/Serve
进程验证了游标和评分错误能跨进程传回 Controller。另用实际参数解析器验证了 hybrid 的旧策略准入,用实际 Advantages
循环验证了末步回退保留分区。中英文文档构建通过。本轮未在本机运行 GPU 或多节点故障注入。


复审修复
[`5a189bf6`](5a189bf)
将组件恢复限定在启动时的引擎池,原生和外部扩容均在创建请求前返回 HTTP
409。测试使用公开请求列表确认队列为空,并确认执行入口未被调用。扩缩容相关 107 项测试通过,中英文文档构建通过。

复审修复
[`7d36a1ef`](7d36a1e)
恢复训练后权重传输的 600 秒等待上限。开启组件恢复时,如有权重 rank 始终 pending,Actor
保留同步预约与训练分区,交给全局重启。正常训练和前向计算继续等待各 rank 自然完成。新增 pending rank
用例在旧代码上失败,修复后两个相关 CPU 测试文件共 59 项通过。 真实 Ray CPU 对照把等待上限缩短到 0.6 秒。旧实现超过
1.2 秒仍卡住,新实现在 0.604 秒报错;Ray 此时仍有 1 个 pending rank,训练步和分区均保留。

复审修复
[`1ce96532`](https://github.com/redai-studio/Relax/commit/1ce9653229c2563b598eb8562f2f07259f2b22e8):

- Controller 在 TQ 初始化及集群 attach 检查结束后选择恢复模式。实际使用 MooncakeStore
时保留引擎级容错,auto 回退 SimpleStorage 时可以启用组件恢复。全局重启复用配置时,先移除旧 Ray
句柄,再启动节点缓存清理。
- 组件恢复模式拒绝外部引擎扩容和手动引擎恢复,两个 HTTP 入口均返回 409。回归覆盖未登记、未派发请求以及原有成功路径。
- 在隔离 CPU Ray 环境复现了从旧会话序列化恢复句柄导致的原生错误,并验证清除旧句柄后节点 RPC 成功。中英文文档构建通过。

本轮复审
[`468de314`](468de31)
修复了 full-async/hybrid 权重握手和同步非共置的恢复选择。修复前,Rollout 准备、ActorFwd 探测和
Rollout 释放三处连接异常均被吞掉。修复后,三个回归均验证 Actor 保留同步预约和原训练分区,训练步不会前进。准入测试使用真实 CPU
状态矩阵,反转就绪值的对照会失败。

验证结果:34 个相关 CPU 测试文件共 1055 项通过,另有 10 个子测试通过。最终使用 CPU Torch
张量的准入测试文件另行复跑,21 项通过。隔离的 CPU Ray Serve 烟测确认关闭健康检查后,训练入口以错误码 1
退出,等待中的接收副本和其子 rank 在 Ray 关闭前已终止。完整文档构建通过。本轮未运行 GPU 或多节点故障注入。


本轮复审修复
[`aaf4d1d7`](https://github.com/redai-studio/Relax/commit/aaf4d1d79efebb7fdc4ccec4a72758ed674d8dcf):

- 正常训练与前向等待全部 rank 完成。启用局部恢复时,单个 rank 失败后限时排空其他
rank,启动与恢复阶段的权重同步也保留时限。CPU 容器中 34 个相关测试文件共 1050 项通过,另有 10 个子测试通过。独立的真实
Ray CPU 烟测以缩短的恢复时限覆盖慢 rank 正常完成、维护超时、故障后其余 rank 未完成及全部结束后的错误传播。
- 直接验证严格清理等待最后一个存储 ACK。全部 ACK 成功才释放 Controller
索引,任一失败都保留索引。在进程内把清理改为首次失败即返回,新增回归能捕获提前返回。
- 修复离线 OpenAPI 生成器对运行时模块的导入。仅安装 FastAPI 和 Pydantic 及其依赖即可生成四份服务规范;完整
`npm run docs:build` 通过。本轮未重跑 GPU 或多节点训练。

最终提交
[`e97938f3`](e97938f)
按 CI 要求调整两处 docstring 的换行,18 项定向回归复跑通过。

### 历史版本的验证记录

当前 CPU CI 修复版本:`f95759d61db7f4f529eeba1896a47f8d96ac2ee9`,合入
`main@c75b0a1` 对齐 CI 的合并测试版本。两个跳过构造函数的 Rollout 测试对象补齐
`_resume_data_source` 和真实 `RecoveryGate` 初始化,仅增加 3 行,不新增用例或生产兜底。原 7
项失败已在本机复现,修复后相关 98 项 CPU 测试通过。新版本远端 pre-commit 已通过,CPU 单测等待 runner:[本轮
Unit
Tests](https://github.com/redai-studio/Relax/actions/runs/44265897436)。


当前修复版本:`54fa2be7d7c8ed6c89041611d048456fbed0a260`。离线准入三模式回归在修复前全部失败、修复后通过;相关恢复测试
83 项、离线运行时与 Actor 分区测试 71 项通过,共 154 项。全量 pre-commit 通过,独立复核未发现阻塞问题。本轮未运行
GPU/多节点训练,以下历史硬件证据仍仅对应各自注明版本。

此前验证版本:`02bbea180f325e084f4ac4c0a120db6c77289255`。本轮 80 项相关 CPU 测试通过,全量
pre-commit 通过;未重跑 GPU/多节点训练。以下既有验证记录仍对应各自注明版本。

本次冲突处理:`975194876d24f0ff633dc94dc7c9c077f28675bd` 合入
`main@d0e00f3`。Controller 同时保留启动同步失败时取消其余任务,以及 recovery
准入和成功后的解锁;同步适配旧测试桩的 `rollout_only` 参数。

本轮验证:本机 387 项 CPU 测试及 10 个子用例通过;此前指定镜像内 39 项后端/恢复/LoRA 同步 CPU 测试通过,合计
426 项及 10 个子用例;冲突文件 Ruff 检查通过。本轮未重跑 GPU/多节点训练,以下 GPU
证据仍对应原注明版本,不能视为本次合并版本的 GPU 验证。

此前验证实现:`2ee4ffc6d63bb`(生产tree
`1e149bbe234527970c2f65416fa7cf8d12a8cbaf`)。本轮只调整7个已有生产模块,未修改FSDP实现、CLI或agent/skill。GPU固定源码与提交仅有两处新增docstring的自动换行差异,无行为改动;最后一个提交仅适配测试夹具,生产tree与`7caada8`相同。

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

**CPU**:当前提交的[全量CPU
CI](https://github.com/redai-studio/Relax/actions/runs/43924264792/job/133499564023)为
**9909 passed、0 failed、155 skipped,另有3个subtests
passed**。跳过项未计通过。原11项失败均为初始化测试手工构造配置缺少backend字段及manager配置响应,已只改夹具并保留原有断言。


本机相关套件分别1077项、真实Ray/Serve全局恢复及收发回执206项、CI夹具文件23项通过;本机21项既有tokenizer前置条件skip未计通过。最终等待策略变更后另有86项关键回归及3个subtests复跑通过。未手动运行未分组的全仓`pytest
tests/`。

**本轮GPU四项均正常退出并通过独立审计**。使用目标训练镜像(ID
`sha256:7be0cf58e0007e1d6d06eb233d62d4cb8efcf5294e6c10e6fce94a99b95cda1b`)、已有Qwen2.5-1.5B-Instruct+GSM8K资产、单节点H800、训练TP2/推理TP1、非零有限梯度及decode
CUDA graph。

| 场景 | 实测结果 |
| --- | --- |
| 关闭recovery的统一编排基线 | 4rank均完整完成rollout 0..1,无故障注入或恢复,exit0 |
| Colocate Rollout局部恢复 |
4rank完成0..5;local1/global0,训练对象和CPU快照身份保持,4个旧引擎进程树退出,4个替代引擎版本4匹配sender4,exit0
|
| Fully-async跨角色共享累计预算 | Rollout/Fwd/Rollout三次local后两个原Actor
rank均继续训练,attempt1/2/3不清零;第四次Fwd异常在sync=False/unsafe=False时原生报budget(3)
exhausted、attempt4;global恰1次后新2rank完整0..15,exit0;严格17项检查全通过 |
| Hybrid Rollout局部恢复 |
4rank完成0..5;local1/global0;训练实例、model/optimizer/scheduler保持并继续推进,DCS实际接收方等于两个替代引擎的预期集合,exit0
|

四项均验证真实恢复和后续训练,不以服务启动状态代替通过。完整日志、argv、原始观察和审计保留在本机,实验产物未加入源码。


**历史GPU边界**:`d16fbf9`还实测通过DCS部分接收拒绝与全局回退、HealthChecker全局恢复及原生token回执链。这两项未在本轮新编排上重新运行GPU;本轮真实Ray/Serve和回执CPU回归覆盖了对应控制链,不冒充GPU重测。


边界:Ray按仓库本机入口提前启动;未验证多节点、推理TP2、长期收敛、吞吐等价、GPU/节点丢失或hung检测。全局重启从HF重建,不承诺跨global保留optimizer。对象身份/版本不等于逐字节数值等价。此前提交通过的远端检查包括:pre-commit、CPU全量、H20单卡/四卡单测、多模态GPU集成、全异步GPU集成及全异步NPU集成。

## Type of Change

- [x] 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)
- [x] Documentation update
- [x] Refactoring (no functional changes)
- [ ] Performance improvement
- [ ] CI/CD or build changes

## Screenshots / Logs

上表只记录本版本实际执行的测试;每个训练用例保留独立 driver/Ray 日志、argv、原始观察与审计结果。

</details>

---------

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

This branch has not been deployed

No deployments
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.

2 participants