Repository navigation
【No.3】feat(inference): Unified Inference Service - #381
leelingrui wants to merge 16 commits into
Conversation
Nyanpasu 审查看板审查状态: ✅ 已通过 审查版本: e29cc71 目标分支: main e29cc71 复核完成,已[审查通过](https://github.com/redai-studio/Relax/pull/381#pullrequestreview-5574200032)。示例资源改为受支持的 4+4 split,参数/放置/即时评分接线一致;相关迁移说明已核对,无新增可操作问题。此前发现状态保留。
审查发现待处理
已解决或已取代提交范围 · 接收 153 · 建议移出 0 · 待确认 0接收 153 个文件 · 建议移出 0 个文件 · 待确认 0 个文件。移出与待确认部分暂停深审,不代表审查通过。
精简审查与验证依据
生产代码的必要性与替代方案
测试的必要性与替代方案
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
审查结论:需要修改
按 head ec525966 完成常规审查(97 个变更文件全部纳入,范围裁定与进度见审查看板)。控制面设计总体扎实:准入/放置/生命周期不变量、publish 校验(READY 需 Router、权重版本一致)、失败时保守保留 GPU 与 slice、discovery v2/v1 双投影等均验证无误;本地可运行的 305 个单测全部通过(其余因审查环境缺 numpy/torch/GPU 无法执行,已记录为 gap)。但发现 1 个阻塞性回归与 2 个边界缺陷:
P1:diffusion 训练路径(--rollout-function-path relax.engine.rollout.native_generation.generate_rollout)随宿主 actor 迁移到RolloutWorker后,native_generation._get_engines仍在当前 actor 上调用已不存在的get_rollout_engines_and_lock,首个 generate 即AttributeError(仓库自带脚本scripts/training/diffusion/run-qwen-image-t2i-8xgpu.sh即受影响)。 P2:_run_global_restart中shutdown_all是唯一未包 try/except 的清理步骤,单个卡死引擎或 manager actor 死亡会把本可恢复的全局重启变成任务终止。 P2:--defer-reward-to-post-process在 GenRM 不共享 rollout bundle 的布局(fully-async / colocate-split)下通过启动校验,但首个 TQ publish 处以No role takes turns in phase 'genrm'崩溃。
另有若干 P3(网关 1800s 读超时作用于 /evaluate 控制面、rollout 网关对 OpenAI model 名收紧为 400、deferred publish 闭包的 rollout_id 晚绑定、空展开批次静默丢弃 is_last、teacher colocate 校验的 critic 算术不一致),见行级评论。
非行级(文档与 PR 说明):本 PR 删除了 RolloutManager/GenRMManager/TeacherManager 等公开类并使 /rollout/engines 默认返回 v2 schema,但 docs/{en,zh}/guide/architecture.md、docs/{en,zh}/api/rollout.md、docs/{en,zh}/guide/elastic-rollout.md、docs/{en,zh}/guide/autoscaler-k8s-keda.md、docs/public/openapi/rollout.json、README.md/README_zh.md 及 skills/opd-tuning/references/ 仍描述旧类名与旧 /engines 结构。建议在本 PR 或紧随的 PR 中更新(legacy 视图可用 ?schema_version=1 过渡)。
深度审查(独立设计对比 + 测试审计)仍在进行,结论将在看板补充。
There was a problem hiding this comment.
深度审查补充(常规审查结论不变)
深度审查已完成,证据与逐项裁定见审查看板。要点:
- 独立设计对比:仅从 RFC #71 与 base 出发的独立参考设计(独立性 clean,三个可执行实验全过)与本实现在关键机制上收敛:六态生命周期、
topology_revision原子发布、head-only 副本暴露、weight_source结构性门控 DCS 注册(关闭了参考设计识别出的"删除 GenRMEngine 后 fully-async 下 GenRM 静默注册 DCS"陷阱)、503-never-wake。差异点(集中式LifecycleCoordinatorvs actor 侧排序、网关独立 Serve 部署 vs 挂载现有 ingress)经调用链核对均有成立理由,未发现应删除的多余机制;一个无生产消费者的投机开关列为非阻塞精简建议。 - 测试审计:本地可运行的 305 个单测全部通过;三个定向变异实验中两个被正确检出(放置重叠删除、网关准入绕过),一个存活(
publish写侧 READY-准入不变量无专属测试,已列为 P3 测试缺口)。GPU/多节点与 numpy/torch 依赖族的运行验证为环境 gap;测试审计子任务一次运行超时失败,父任务完成了有界审计并在看板披露限制。 - CI 状态:本 head 上
Tests (Python 3.10/3.11/3.12)与Qwen3-4B-4xnpu-async失败(main 全绿)——分别对应新测试缺少 sglang 守卫(P2)与 NPU fully-async 启动链路在初始权重同步后副本 DEAD(P2),详见行级评论。
新增发现:2 个 P2(CI 回归 ×2)、1 个 P3 测试缺口、1 个 P3 非阻塞精简建议,见行级评论。此前 REQUEST_CHANGES 所依据的 P1(diffusion 路径回归)仍未解决,审查结论保持需要修改。
49100f8 to
5691b9a
Compare
There was a problem hiding this comment.
审查结论:无阻塞项(有补充意见)
两个修复轮(49100f8f、5691b9aa)已逐项验证,此前的 13 项发现处理情况如下:
- 已解决(12 项):P1 的 diffusion 路径回归(F1,改走
get_local_inference_manager+rollout_operation)、全局重启异常包裹(F2)、defer GenRM 布局判定对齐(F3)、网关超时与 OpenAI model 名兼容(F5/F6)、deferred OPD 闭包绑定与空批次is_last(F7/F8)、teacher colocate 校验统一(F9)、测试守卫与写侧不变量测试(F10/F12)、expose_engine_urls投机开关移除(F13,本 head 干净删除、无残留引用)。多数修复伴随了针对性的新测试,本地可运行用例全部通过。 - 待 CI 确认(F11,代码级已修复):NPU 回退的根因(
/get_weight_version在 NPU 构建上 404 → 观测探针失败 → 副本被标 DEAD)与日志症状完全吻合,/model_info替换合理;但两个 head 的 CI 工作流目前均处于action_required(等待批准),CPU 三套件与 NPU 集成通过后即可关闭。建议批准并重跑这两个工作流。 - 遗留非阻塞(F4):
docs/{en,zh}的 architecture/api/elastic-rollout/autoscaler 页面、docs/public/openapi/rollout.json、README 与skills/opd-tuning/references/仍描述已删除的RolloutManager/GenRMManager等类与旧/engines结构,建议在本 PR 或紧随的 docs PR 中同步(legacy 视图可用?schema_version=1)。
F4 与 F11 的 CI 确认不构成合并阻塞。整体设计经独立参考对比验证无多余核心机制,修复质量良好。
完整证据、逐项裁定与范围决策见审查看板。
There was a problem hiding this comment.
CI 结果跟进:NPU 已确认通过,CPU 套件仍有一处新失败
5691b9a 的 CI 工作流批准后已运行完毕,结果:
- ✅
Qwen3-4B-4xnpu-async通过——F11(NPU 回退)随/model_info修复正式关闭;GPU 单测、4xgpu/VL 集成、Pre-commit 均绿。 - ❌
Tests (Python 3.10/3.11/3.12)仍为红:test_control_plane_affinity.py::test_task_inference_manager_keeps_head_affinity_and_requests_stable_cpu在 CPU runner 上因create_inference_manager → validate_task_layout → rollout.py:22的模块级 sglang 导入链抛ModuleNotFoundError。此前它被test_checkpoint_prefetch的收集错误掩盖,守卫修复后才暴露——属 F10 同类的第二处(新行级评论,P2),修复选项见评论。
结论不变:无阻塞的代码缺陷;剩余为 F14(本条 CPU CI 修复项)与 F4(docs 同步,非阻塞)。完整状态见审查看板。
rai-studio-bot
left a comment
There was a problem hiding this comment.
审查结论:通过 ✅
5e7a2266 完成最终验证,此前全部 14 项发现均已解决:
- P1(1 项):diffusion/native rollout 路径回归——已改走
get_local_inference_manager+rollout_operation,附回归测试。 - P2(5 项):全局重启异常包裹、defer GenRM 布局判定对齐、CPU CI 两处 sglang 导入链(
test_checkpoint_prefetch守卫 +test_control_plane_affinity等 monkeypatch 修复)、NPU 回退(/model_info)——CI 实测确认。 - P3(8 项):网关超时与 OpenAI model 名兼容、deferred OPD 闭包绑定与空批次
is_last、teacher colocate 校验统一、publish 不变量测试、expose_engine_urls移除、docs/skills 全量同步(无残留已删除类引用;v2 discovery 与?schema_version=1逃生口均已记录)。
CI:8 项检查全绿(Pre-commit、CPU 三套件 Tests 3.10/3.11/3.12、GPU 单测、4xgpu/VL 集成、NPU 集成)。
深度审查:独立参考设计对比收敛(六态生命周期、原子 topology_revision、head-only 副本、weight_source 门控 DCS、503-never-wake),生产/测试必要性审计完成,无多余核心机制;唯一精简建议(投机开关)已由作者采纳。
感谢高质量的修复协作。完整逐项证据见审查看板。
rai-studio-bot
left a comment
There was a problem hiding this comment.
审查结论:通过 ✅(merge 轮复核)
614466e6(merge main into rfc-71-unified-inference)已复核:
- 合并交叠验证:main 侧与分支重写路径的三个交叠文件(
megatron/actor.py、train_actor.py、checkpoint_write_patch.py)合并干净——分支侧逻辑(deferred_genrm_enabled谓词、genrm manager 句柄、权重同步路径)完整保留,main 侧变更仅为 device 重构的机械改名(device_utils.*→device_module.*)。 - 修复位点完好:此前 14 项发现的全部修复位置(
native_generation、phase_plans、controller重启包裹、sglang_engine的/model_info、网关兼容、deferred OPD、docs 等)均不在合并增量内,逐点确认未受影响。 - 兼容性:
device.py重构保留分支使用的模块 API;本地可运行测试 116 项全部通过。
一点提醒:该 head 的 CI 工作流目前仍处 action_required(等待批准)。5e7a2266 基线为 8/8 全绿,且本合并增量不触及任何修复位点,但建议在合并前批准并跑完 CPU 三套件与 GPU/NPU 集成,由分支保护做最终把关。
完整记录见审查看板。
|
辛苦解决下冲突~ |
|
另外这个 PR 也没提交 review 请求哦,解决完冲突如果觉得没问题了可以在 PR 里 @ 我一下 |
rai-studio-bot
left a comment
There was a problem hiding this comment.
结论:APPROVE
main 同步轮(合并 d8270bc、3740bea5)按新锚点 3740bea5@815de3aa 重新核对:有效 diff 与已审范围逐文件一致(120 路径、逐文件增删行数零差异),前轮审查结论直接适用——与 main 侧新特性(DPO/RM/零 token 步/KK 重打包等)交叠的 14 个文件合并干净,无冲突标记、无悬空引用(is_sft_mode→is_offline_mode 全量迁移、validate_opd_args 调用点适配、affinity 测试参数化并入新 API),此前记录的 14 项发现全部解决且修复位点完好;本地可运行测试 913 通过 / 6 跳过 / 0 失败,CI 无失败。生产与测试必要性审计结论经逐文件一致性验证后按新 inventory 沿用记录。
详情与发现索引见审查看板。
Yangruipis
left a comment
There was a problem hiding this comment.
这版实现已经形成较完整的统一推理架构:任务级 Manager 集中管理引擎所有权与资源状态,三个角色共用 Gateway,Rollout 业务也从引擎管理中独立出来,整体职责划分清晰,符合 RFC 的主要方向。
当前需要补齐的是这些边界上的行为一致性,尤其是请求准入、排空、卸载与健康观测之间的不变量;同时应收敛重复的请求执行路径,完善实际资源绑定校验、数据发布契约和接口迁移说明。
建议先修复已确认的正确性问题并加入并发回归,再逐项处理设计与验收建议,明确已有测试证据及尚未覆盖的场景,使架构上的统一落实为可验证、可维护的运行行为。
| return | ||
| self.set_state(role, model_id, LifecycleState.DRAINING) | ||
| try: | ||
| entry.pool.offload() |
There was a problem hiding this comment.
[P1|已复现] 所有卸载入口都必须先关闭准入并排空,不能只依赖 phase switch 调用 drain
这里设置 DRAINING 后立即调用 pool.offload(),没有等待 Manager 已登记的请求完成。生产路径 components/rollout.py:462–464 会直接调用 deactivate,因此仅在 LifecycleCoordinator._switch() 中先 drain 不能覆盖普通 rollout 收尾。请求已经获准、但仍在 tokenize/排队/准备 HTTP 转发时,引擎可以先被卸载,之后请求才到达引擎。
在当前 HEAD 3740bea 上,使用真实 InferenceManager 和 fake pool 的 CPU 复现:先 admit 一个请求,再 deactivate;pool.offload() 被调用时 _inflight 仍有该请求,随后模型已被发布为 SLEEPING。这里证明的是卸载早于已准入请求完成,尚未证明 GPU OOM 或训练数据损坏。
建议把“关闭准入 → 等待已获准请求终止 → 后端排空/卸载确认 → 发布 SLEEPING”做成 Manager 的统一生命周期操作。普通 deactivate、phase switch、shutdown、scale-in 等入口应复用它;仅限失败补偿且能证明没有请求的路径才允许使用明确命名的内部 primitive。等待期间不能持有 complete_request 必须获取的锁;超时应保留 residency/资源 fence,不能直接允许冲突角色激活。
回归建议:用同步屏障将请求停在“准入成功、尚未转发”,并发触发普通 rollout offload;断言 offload 在请求完成/被确认终止前不会执行,新请求被拒绝,释放失败时下一角色不能 onload。应覆盖实际 Rollout 服务入口,而不只测 coordinator 的顺序调用。
There was a problem hiding this comment.
已经修复,此外额外添加排空超时强制终止参数,当force_abort参数为True时,若抵达设定的超时时间将会强制终止在引擎上正在生成的请求。若force_abort为false,则周期性打印警告,周期为所设定的超时时间。
scale-in未复用Manager的统一生命周期操作主要有以下两个原因:
- Manager 关闭的是整个模型的准入,复用的话,scale-in 期间该模型所有副本都会停止接收请求;而 scale-in 只是摘掉其中几个副本,其余副本需要继续服务。
- 这里要防的风险是:offload 之后进程还活着、显存已经释放,请求却仍然到达引擎。scale-in 不存在这种状态。它先把副本从 Router 注销,之后不会再有新请求路由过去;并在宽限期结束后直接 kill
| if not isinstance(response, StreamingResponse): | ||
| if not finished: | ||
| await self._abort_upstream(target, rid) | ||
| await self._manager_call("complete_request", request_id) |
There was a problem hiding this comment.
[P2|生命周期契约与验证缺口] 请求登记清除不应被当作后端已经排空的充分证据
非流式异常路径在尝试 _abort_upstream() 后就 complete_request;流式清理也需要遵守同样的资源安全边界。_abort_upstream 自己的注释已说明 ACK 只证明 scheduler 收到请求,不证明生成已离开 running batch,且 abort 失败会记录日志后返回。因此 Manager inflight 归零最多证明网关侧处理结束,不能单独证明共享 GPU 已可以交给下一角色。PR desc 已诚实说明这一限制,需要将它落实为可验证的生命周期契约。
建议明确区分“网关请求关闭”和“backend 已确认排空/停止”,在统一卸载路径中补充引擎侧 ingress fencing 以及 pause/abort/flush/drain 的确认;只有后端确认与卸载成功后才清除 residency、释放 slice/lease。若确认超时或结果不明,保留资源 fence 并失败退出/受控重试,不要因为 complete_request 被调用而宣告可复用。可参考 engine-head gate 的做法,但不要求照搬一套代理;也不要无限保留所有请求 token 代替后端清理协议。
请用“HTTP 已断开,但 fake/真实引擎仍运行”的测试验证下一角色不能激活,补 abort ACK 后延迟退出、abort 失败和取消发生在评分阶段切换中的分支。本条是安全契约和证据缺口,尚未据此证明实际 OOM;与已复现的 Manager drain 竞态分别处理。
There was a problem hiding this comment.
现在 GPU 交接要两份证据,缺一不可(inference_manager.py 模块 docstring 写明了这一契约):
- 网关侧:
_drain_models关准入并等 permit 账本清空。 - 引擎侧:
pool.offload()→SGLangEngine.release_memory_occupation():先pause_generation(不是 best-effort)、从 Router 注销并确认移除,再循环 abort 直到/flush_cache报告空闲,最后发送需确认的release_memory_occupation。任何一步无法确认就抛错。
There was a problem hiding this comment.
offload 抛错时模型被置为 DEAD 且 resident=True,冲突角色的租约拿不到时不会 onload;shutdown 在宽限期后强制 abort 再停引擎,停不掉的模型保持注册状态以便重试。
| return record.snapshot | ||
| self._advance(record, DeferredState.PUBLISHING, scored=record.batch_ref.eligible_count) | ||
| try: | ||
| await publish(record.payload, record.is_last) |
There was a problem hiding this comment.
[P2|数据交付契约与验收] 明确 TQ publish 的提交边界和部分失败行为
这里先完整评分/校验,再调用 publish,方向正确;当前审查没有证明“未评分样本已经进入训练”的缺陷。但 publish 回调抛错时只把 record 标为 FAILED,不能仅从本层判断 TQ 是否已经写入部分数据、消费者是否已经可见,以及重试会不会重复发布。相较独立 commit gate,本设计把正确性更多交给 TQ 和调用方的发布契约,需要把这部分证据补齐。
建议先确认并记录 TQ 的原子性/可见性语义:如果一个 publish 成功返回前可能部分写入且被读取,应使用 staging partition + commit marker,或在训练消费者前增加明确的 batch commit gate;评分字段、所有分块和必要的 finalizer 成功后才开放消费。若现有 TQ 已提供足够强的原子发布保证,则复用它并补合同测试,无需为了对齐其他实现再造一套 Coordinator。失败清理、重复 publish、rollout_id/batch_id 与 is_last 的幂等规则也应明确。
请用故障注入覆盖写入中途异常、写入成功但响应丢失、最后一块/最终标记失败、评分后取消、重复重试;断言不会消费半批次或缺字段数据,不会把失败批次再次发布成重复样本。保留现有样本身份、顺序、mask/字段长度校验,并覆盖 Agentic 多次 Session 导出和 student 第二次 prefill。此项是验收请求,不是已复现的数据损坏。
There was a problem hiding this comment.
核对了 TQ(SimpleStorage 后端)的实际语义,结论是:单次 async_put 本身就提供了 batch 级原子可见性,因此没有另加 staging partition / commit marker
There was a problem hiding this comment.
仍存在的边界:
- 写入成功但响应丢失:storage manager 的
notify_data_update在收不到 ACK 或通知出错时只打日志、不抛异常,controller 回success=False时 client 也不检查。因此async_put可能"返回成功",而样本实际上没有可见。后果是该 step 的样本缺失、streaming 消费者卡在等 end-of-stream,不会读到半批数据,但会挂起而不是快速失败。 - put 中途被取消:如果取消发生在 notify 已到达 controller 之后,Relax 记录为 FAILED,而 TQ 中这一批其实已经可见。step 会失败,但分区里会留下这一批;目前框架在失败路径上不清理
train_{rollout_id}。
There was a problem hiding this comment.
感谢补充具体的 TQ 语义。若单次 async_put 已保证 batch 级原子可见性,可以直接复用,不要求再加一套 staging/commit marker;原先对“可能半批可见”的担忧不能当成已确认缺陷。
但你说明的两个边界仍需闭环:notify/ACK 失败没有反馈给上层时,DeferredExecutor 可能报告 COMPLETED 而消费者一直等数据或 is_last;取消发生在已可见之后时,本层标 FAILED,分区却仍保留该批。当前 await publish 正常返回即推进 COMPLETED,也没有表达“提交结果未知”的状态。
建议先明确成功回执对应的可见性保证:通知失败必须可检测;已发送但结果未知时不要盲目重放,可使用 batch/operation identity 查询或幂等提交来收敛。若当前只支持整步失败重启,明确停止消费者、清理/隔离旧 train 分区再使用新 attempt,避免旧数据被下一次消费。不要在消费者仍运行时直接删分区。
请补通知失败、写入成功但响应丢失、已可见后取消、最后批次 is_last 失败的故障注入,断言不会误报成功、无限等待或重复训练。这是依据当前发布调用链和你给出的后端边界提出的验收要求,本轮未运行真实 TQ 分布式故障实验。
There was a problem hiding this comment.
[P2|验收覆盖] 将并发控制回归与 GPU 训练证据分开列清楚
现有正常流程和顺序状态测试不能覆盖本轮已复现的三个边界:已准入但未转发时直接卸载、drain 等待期间 health_check 重新打开准入、重复 request ID 覆盖账本。建议先为每项加可在 CPU CI 稳定执行的屏障式并发测试,避免仅用 sleep 或顺序调用碰运气;再加真实 Ray Actor + Gateway 的接线验证,确认并发组、锁、取消和完成回调与 fake 测试一致。
GPU 验收建议提供与最终提交 SHA 对应的配置、命令、日志链接和断言:正常 deferred OPD、Teacher 评分中取消/切换中取消、可选 student 二次 prefill、多 Teacher/data_source 路由、GenRM defer、split/独立资源即时评分,以及 scale/recover 与在途请求交错。重点检查释放→激活顺序及训练字段完整性,不能只看训练进程最终退出成功。
PR desc 已提供正常多轮小模型训练和 scale 测试,应计入已有证据,不需要重复宣称“未测”。但请把 CPU mock、单节点多卡、多节点 TP/PP/PD、节点故障分栏;缺硬件的场景明确 SKIP 原因。生命周期一栏建议区分“代码路径存在”和“并发语义通过验收”,这些缺陷修复前不宜笼统标完成。
另外两点描述可顺手校正:RFC 要求统一 Manager 类,没有强制一个 task Actor;当前 RFC API 允许 Router 或 DIRECT,并没有把“首版选 Router”写进 Decision 表。单 task Actor 和生产 Router 是本 PR 的合理设计选择,应作为选择说明,而不是引用成 RFC 的硬性原文。
| # same actor, so it needs several execution slots; rollout engine operations get | ||
| # their own group because a scale-out runs for minutes. | ||
| _MANAGER_CONCURRENCY = 8 | ||
| InferenceManagerActor = ray.remote(num_cpus=1, num_gpus=0, concurrency_groups={"rollout": 8})(InferenceManager) |
There was a problem hiding this comment.
[P3|架构取舍与验证] 为任务级单控制 Actor 补充容量和故障恢复边界
把三角色放进同一个 CPU Actor,使 ledger、residency 和 phase lease 的所有权清楚,这个方向可以保留。代价是 Gateway 的 snapshot/admit/complete、健康探测与生命周期操作共享控制进程;并发组和锁意味着它不是简单的串行状态机。我没有测出实际吞吐瓶颈或新的 Actor 故障 bug,因此本条属于设计/运维验收建议。
建议明确 fast-path 与长操作的隔离原则:等待 drain、健康 RPC、启动/恢复不能占住 complete_request 所需的执行能力或锁;补并发压测记录控制面 RPC 延迟、队列长度和请求完成延迟,再决定是否需要缓存纯观测、限制长操作或调整并发组,不应为了猜测中的瓶颈提前拆成多个 Manager。
同时明确 Manager Actor/engine actor 死亡、节点失联、shutdown 超时时的恢复协议。epoch 改变应使旧快照/permit 失效;新控制实例不能因旧账本消失就假定 GPU 已释放。若无法确认 SGLang 子进程或借用 PG 已清理,应保留资源 fence、阻止冲突角色重新占用,并给出人工确认清理后从 checkpoint 重启的路径。用故障注入证明不会误删 Controller/external PG、不会对未确认释放的 slice 盲目重建。
这次同时搬迁 Controller/Service、Workload 和旧 API,建议后续修复按“生命周期不变量、请求执行收敛、迁移/验证”分组提交,并在描述中给出接线与回滚索引;无需为了降低 diff 数量撤销已经成立的职责拆分。
|
辛苦处理一下 review 意见以及再解决下冲突,今天合入了一个大 PR 冲突项比较多~ |
|
Thanks for contributing to Relax, @leelingrui! 感谢你为 Relax 做出贡献! 📚 Contribution guide / 贡献指南Describe the problem, your changes, and how you validated them. Keep each PR focused and run 请说明问题、改动和验证方式,保持 PR 聚焦,并在提交前运行 🛠️ CI commands / CI 指令
Put one command on the first line of a new PR comment. Rerun/cancel require PR authorship or repository write access. 在新 PR 评论的首行写一条指令。PR 作者或有仓库写权限的贡献者可以重跑、取消 CI。 🔎 Merge requirements / 合入条件GitHub:❌ 存在冲突
|
26752a1 to
15fb9f0
Compare
…rence # Conflicts: # docs/en/guide/autoscaler-k8s-keda.md # relax/backends/megatron/actor.py # relax/distributed/ray/placement_group.py # tests/core/test_control_plane_affinity.py
…manager Admitted requests hold Manager permits that are returned only on a confirmed release, and every role drains its admitted requests before an offload. Placement verifies the node and GPU binding of each bundle. The Gateway and the GenRM backend share one request executor, calls go one way from the Manager to its pools, and the Manager runs as an async Ray actor so waiting loads hold no thread.
…rence Bring in 49 upstream commits (through dce533b) and port their engine-pool changes onto the unified inference control plane. # 🔀 Conflict Resolution ## Keep both sides where they compose - Pass `max_constructor_retry_count=1` alongside the manager handle in Service deployments - Run custom reward post-processing in the GenRM scoring phase while keeping the upstream single-return contract - Use the upstream prev/current tail split in `sglang_rollout`, published through `publish_batch` so deferred OPD still stages batches - Keep the gloo barrier before restoring rollout memory in the FSDP actor ## Port upstream engine-pool features to RolloutEnginePool - Engine init records, Ray local actor state and dead Router worker cleanup now live on the pool hosted by InferenceManager - Scale-out replicas inherit `sglang_overrides` from the template group on top of the manager-planned placement slice - `get_engines_info` keeps `status_filter` and adds the upstream observation as-is --- # ♻️ Refactor ## Drop the duplicated recovered-engine publication - Remove `register_recovered_engines`, `pending_router_registration` and the DCS recipient all-gather; `observe(ensure_router=...)` already registers a recovered engine once it holds non-default weights ## Fold upstream engine observation into observe - Reuse `_read_engine_metadata` before probing: a dead actor is DEAD and a pending init is STARTING without an RPC; a replaced slot is reported as `generation_changed` - Add `ModelSnapshot.issues` and publish `observation` in both v1 and v2 discovery; mark `topology_unsettled` until the next observation --- # ✨ Feature ## Read v2 discovery in the autoscaler and SGLang exporter - Autoscaler requests `schema_version=2` and parses both v1 and v2 with shared observation validation - The SGLang metrics exporter discovers through `rollout_gateway` v2, scraping PD workers instead of the Router --- # ✅ Tests - Adapt upstream tests to RolloutEnginePool, placement slices and the inference-manager handle - Cover v2 autoscaler parsing, v2 exporter discovery, observe issues and discovery observation round-trips
…ement Give each request its own engine rid, require a probed PlacementBinding for every placement group, repair unified inference regressions and make the weight-update lease private to the rollout pool.
…rence Resolve conflicts with upstream redai-studio#433 (managed PD), redai-studio#437 (native image OPD), redai-studio#439 (rollout utility extraction), redai-studio#361 (multinode scale-out) and the placement factory relocation, porting their intent onto InferenceManager. - Managed static PD: start_servers defers the Router until P/D engines are ready and seeds it with them; replacements still join after weight sync. - Recovery broadcasts rank-0 failures before weight sync; pool monitors stop within one shared 5s budget; Controller bounds shutdown_all to 35s. - Teacher engines get SGLANG_MM_AVOID_RETOKENIZE in config_adapters; the removed RELAX_OPD_PREEXPANDED_PATCH reference is dropped. - Drop RolloutManager/TeacherManager-only code and tests; adapt new upstream tests to EngineGroupSpec/InferenceModelSpec and the inference manager.
- Return permits whose admission reply was cancelled; publish recovered replicas only after every PP source synced them. - Abort logical rids in a per-execution namespace (input_embeds batches included, integer embeds counted as one prompt); clean the real Serve apps and engines on a failed deploy; keep a failed probe as incomplete evidence; check slot continuity against the engines' visible devices. - Wait for a role start in flight before stopping the role, and admit role starts only from the current deployment; apply the single-model alias rule in resolve_model.
…nRM mode - Hold back only replacements a fully-async DCS sync confirms (not hybrid, LoRA adapter or static weights); map the scale-out precheck's devices the way the engine is launched. - Size each role's Gateway by its configured concurrency and keep a usable class default; group the Teacher environment setting. - Remove the Shared / Co-resident GenRM sub-mode: shared rollout bundles require --defer-reward-to-post-process, refused at argument validation; docs describe Split and Defer-swap only. - Let the final stranded retry wait for a running one; name the unreachable Router when an offload fails closed; wait, bounded, for rollout READY after the initial sync. - Observe the native diffusion engine as a direct-routed replica.
…rence Conflicts (modify/delete) with redai-studio#450, which extended MultiEngineManager and TeacherManager for multi-node teacher replicas. This branch removed both: Teacher and GenRM engines now start through start_servers/EngineGroup on the InferenceManager, which already covers redai-studio#450's requirements: - multi-node replicas must use whole nodes (InferenceModelSpec.resolved, teacher_role_model); - URLs, health probes and memory operations reach replica heads only (EngineGroup.engines, RolloutServer._call_heads; followers answer health_generate locally); - a dead replica is retired as a whole (RolloutServer._retire); - one placement group per model, with the planner checking each node slot. The deletions are kept. redai-studio#450's SGLangEngine change (parent-death guard, follower process handle) merged cleanly. Its behaviours are re-covered by tests against the unified pool in test_rollout_inference_pool.py.
…dline The wait checked its 120s limit only between RPCs. A refresh observes each replica in turn with a 45s probe timeout, so three live but unresponsive engines kept one refresh busy past the limit, the Controller could not time out meanwhile, and a READY that arrived late was accepted. The whole poll (snapshot, sleep and refresh) now runs under one asyncio.wait_for; on timeout the error reports the last snapshot that arrived in time, or that none did.
83faff4 to
08e6722
Compare
|
@SigureMo 可以review了 |
The test imported sglang.srt.constants directly, so CPU CI, which runs without SGLang, failed with ModuleNotFoundError. It now provides the weights tag through a stubbed module, the way the engine reads it.
The script, its comment and the GenRM docs describe a split layout (4 GPUs for rollout, 4 for GenRM), but --resource gave rollout and GenRM all 8 GPUs, the Shared / Co-resident layout that argument validation now refuses. The example failed at launch; it now requests the 4+4 split it documents.
Yangruipis
left a comment
There was a problem hiding this comment.
感谢这轮完善,统一请求执行和生命周期管理的方向值得肯定。建议按职责拆分 InferenceManager,并明确各角色参数与共享默认值的边界,减少对全局 args 的隐式继承。具体正确性问题见代码评论。
| try: | ||
| ray.get(engine.shutdown.remote(), timeout=10) | ||
| except Exception as e: | ||
| logger.warning(f"Failed to shutdown engine {i}: {e}") | ||
| # A dead actor cannot stop its processes any more; a live | ||
| # one that failed or timed out may not have. | ||
| released = not strict or isinstance(e, ray.exceptions.RayActorError) |
There was a problem hiding this comment.
[P1|CPU 复现仍成立] Actor 暂时不可达不能作为 GPU 已释放的证据
ActorUnavailableError 属于 RayActorError,但它只表示暂时不可达,远端调用可能执行也可能未执行。这里在 strict=True 时仍设为 released=True,随后 ray.kill 返回便清空 handle;offload 的 _call_heads/_retire 降级路径也会走到这里,导致 Manager 清除 resident 或 slice。
当前 e29cc71 的 CPU 受控复现中,shutdown/释放 RPC 抛 ActorUnavailableError、ray.kill 使用替身:deactivate 后旧 slot 被清空、GenRM resident=False、Teacher 可以激活;shutdown 后原 slice 被删除。替身保留旧子进程占用标记。这证明控制面把未知释放当成功,未验证真实 GPU OOM,也不声称 ray.kill 必然遗留子进程。
建议 strict 路径对不可达、超时、结果未知保留 handle/resident/slice 并报错,通过可验证的清理再释放。即使 Actor 已死亡,也需要明确 SGLang 子进程的回收保证,不能只按异常基类认定释放。
请覆盖 ActorUnavailableError、shutdown 超时、kill 请求发出但退出未确认,验证 offload 降级、shutdown 和 scale-in 均不会向下一角色交出未确认释放的资源。
| continue | ||
| failed_field = None | ||
| for name in batch_ref.required_fields: | ||
| rows = _leading_length(getattr(sample, name, None)) |
There was a problem hiding this comment.
[P2|CPU 已复现] 评分字段校验不能只检查第一维长度
这里仅用 _leading_length() 验证字段存在且长度等于 response_length,没有校验实际数值及字段形状。当前 e29cc71 上,用真实 DeferredExecutor/seal_batch 和一个 scorer 替身返回 teacher_log_probs=[NaN, -0.1],结果为 COMPLETED,publish 确实收到该字段。正常 GPU 训练中观察到有限值,不能替代异常输出的拒绝分支。
建议在 publish 前增加按字段语义的校验:有效 response/loss-mask 位置的 logprob 必须数值合法;top-k 的 logprob 与 token-id 维度一致、索引类型/范围符合契约。对 mask 掉的位置或协议允许的哨兵值明确规则,不要简单对所有张量无差别拒绝。失败应包含 batch/sample/field 信息并阻止发布,避免异常评分进入训练后才暴露。
请补 NaN、非法 Inf、错误维度及 top-k 配对不一致的 CPU 用例,断言 publish 不调用;同时保留合法 masked 数据与空响应场景。此次只验证数据交付边界,没有运行 GPU loss。
| return record.snapshot | ||
| self._advance(record, DeferredState.PUBLISHING, scored=record.batch_ref.eligible_count) | ||
| try: | ||
| await publish(record.payload, record.is_last) |
There was a problem hiding this comment.
感谢补充具体的 TQ 语义。若单次 async_put 已保证 batch 级原子可见性,可以直接复用,不要求再加一套 staging/commit marker;原先对“可能半批可见”的担忧不能当成已确认缺陷。
但你说明的两个边界仍需闭环:notify/ACK 失败没有反馈给上层时,DeferredExecutor 可能报告 COMPLETED 而消费者一直等数据或 is_last;取消发生在已可见之后时,本层标 FAILED,分区却仍保留该批。当前 await publish 正常返回即推进 COMPLETED,也没有表达“提交结果未知”的状态。
建议先明确成功回执对应的可见性保证:通知失败必须可检测;已发送但结果未知时不要盲目重放,可使用 batch/operation identity 查询或幂等提交来收敛。若当前只支持整步失败重启,明确停止消费者、清理/隔离旧 train 分区再使用新 attempt,避免旧数据被下一次消费。不要在消费者仍运行时直接删分区。
请补通知失败、写入成功但响应丢失、已可见后取消、最后批次 is_last 失败的故障注入,断言不会误报成功、无限等待或重复训练。这是依据当前发布调用链和你给出的后端边界提出的验收要求,本轮未运行真实 TQ 分布式故障实验。
| bundles starts at bundle 0 and is only legal when it defers. | ||
| """ | ||
| region_offset = ( | ||
| 0 if args.fully_async or getattr(args, "_genrm_colocate_with_rollout", False) else args.rollout_num_gpus |
There was a problem hiding this comment.
[P2|CPU 已复现] 同步 decoupled GenRM 不应追加 rollout 区域偏移
当 fully_async=False、colocate=False 且 GenRM 使用 Service 单独创建的 PG 时,这里仍取 rollout_num_gpus 为 region_offset。独立 PG 中并没有前面的 Rollout 区域,GenRM 应从本 PG 的 0 开始。例:Rollout 4 GPU、独立 GenRM PG 2 GPU,此函数给出 offset=4;真实 PlacementPlanner 拒绝 bundles [4,6) exceed capacity 2,合法布局在启动前失败。
本轮 CPU 复现使用当前 genrm_role_models 函数体、模型 spec 构造替身和真实 Planner,未启动 Ray/GPU。Service 在没有 actor_rollout_pgs 时按自身 num_gpus 创建独立 PG,与该触发条件一致。
建议由显式布局规划结果提供 offset,只在确认共享同一 PG 且为 split 时追加 rollout 区域,独立 PG 从 0 分配;不要仅靠 fully_async 判断资源关系。回归应覆盖同步 decoupled、fully-async 独立、共享 PG split/defer,以及 Teacher+GenRM 同时存在时各区域不冲突。
|
🎉 恭喜,这次我们决定选择你的方案作为 unified inference 后续合入和演进的基础!感谢你持续投入,也感谢这几轮 review 中认真回应和推进修改 👏 我们比较看重这份实现对统一推理服务边界的梳理:将资源管理、请求准入和生命周期协调收敛到公共层,让 Rollout、Teacher、GenRM 复用基础机制,同时为各角色保留独立演进的空间。最近几轮对公共请求执行、状态管理和实际资源绑定校验的完善,也让方案更扎实了。 接下来建议先解决与主分支的冲突,再拆成几个更轻量、方便评审和验证的 PR。方向可以粗略考虑:
具体边界按依赖关系调整,重点是每一步都能独立运行和验证,必要时保留短期适配。我们内部也会配合验证,结合实际训练场景检查兼容性、稳定性和性能,一起推进问题修复。期待共同把这块基础打磨好 🚀 |



PR: 统一推理服务的控制面、路由、Placement与生命周期
背景、边界与设计决策
原有 Rollout、GenRM、SGLang Teacher 分别管理入口、引擎、GPU 偏移和上下线。共享 GPU 时,在生成请求结束前切到评分、训练,或者在卸载失败后重新分配显存,都可能破坏资源互斥;Teacher 延迟评分还需要保证样本在评分字段完整前不进入训练队列。
本设计采用每训练任务一个 CPU 推理控制面:
InferenceManager在任务内持有所有角色的模型、引擎池、拓扑快照、请求登记、GPU 分配账本和生命周期状态。LifecycleCoordinator、PlacementPlanner均在该控制域内运行;Gateway 不拥有 GPU。InferenceGateway类按 Rollout / GenRM / Teacher 分别部署 CPU Serve 实例,负责兼容 HTTP 协议、选模、准入及代理。Gateway 的观测来自 Manager,不能凭缓存的 discovery 快照自行批准请求。RolloutWorker+RolloutWorkload负责数据源、生成、评估、奖励后处理及 TransferQueue;RolloutServer/引擎池留在 Manager 侧。两侧以 Ray handle 和有限的推理端口通信。Role -> Model -> EngineGroup -> Replica;模型权重来源区分静态 checkpoint 和动态 DCS。旧 CLI 继续由适配器转换为内部 spec,不新增统一 YAML/CLI 协议。split使用互不重叠的 bundle;defer让角色分阶段复用 bundle。原 GenRM 的 Shared / Co-resident 子模式(共享 bundle、两引擎按mem_fraction_static同时驻留)已删除:共享 rollout bundle 而未开--defer-reward-to-post-process的配置在参数校验阶段即报错,create_inference_manager在引擎启动前再次校验。模块及所有权
flowchart TB Ctrl[Controller / Service] -->|创建单个任务级 actor| IM[InferenceManager - CPU] Ctrl -->|每 role 部署| GW[InferenceGateway - CPU Serve] IM --> PP[PlacementPlanner / GPU 账本] IM --> LC[LifecycleCoordinator / 阶段交接] IM -->|创建并持有| RP[RolloutServer / Rollout engine pool] IM -->|创建并持有| SP[GenRM / Teacher model pools] RP --> SE[SGLangEngine / Router - GPU 数据面] SP --> SE GW -->|快照与 request permit| IM GW -->|准入后 HTTP 代理| SE Ctrl -->|启动| RW[RolloutWorker - CPU] RW --> WL[RolloutWorkload / Agentic rollout] RW -->|激活 / 健康 / 阶段| IM WL -->|Router 推理| SE WL -->|完整训练数据| TQ[TransferQueue] TQ --> Trainer[Actor / Trainer] Trainer -->|权重同步、训练释放屏障| IMrelax/engine/inference/提供角色/模型配置、逻辑副本快照、纯路由选择、发现客户端、Placement规划、阶段计划与生命周期协调;relax/distributed/ray/inference_manager.py是运行时状态所有者。relax/components/inference_gateway.py是三个角色共用的 Serve 实现。relax/distributed/ray/rollout_worker.py与relax/engine/rollout/workload.py将业务数据流从引擎池拆开。旧genrm.py、teacher_manager.py、multi_engine_manager.py等重复控制路径已移除;SGLang GenRM 不再使用独立引擎子类,角色差异通过通用引擎配置处理。上游 #450 在旧MultiEngineManager/TeacherManager上加入的多机 Teacher 支持,由统一引擎池原生覆盖:多机副本必须占满整机(InferenceModelSpec.resolved/teacher_role_model校验),URL、健康探测与显存操作只发往副本 head,任一节点故障整副本下线(RolloutServer._retire),每模型一个 PG 并由规划器校验各节点 slot;合并时保留删除,并在test_rollout_inference_pool.py中按统一池补齐对应测试。启动、发现、路由与请求生命周期
sequenceDiagram participant C as Controller participant M as InferenceManager participant P as PlacementPlanner participant E as Engine / Router participant G as role Gateway participant U as HTTP client C->>M: create_inference_manager(args) M->>P: validate_task_layout / reserve slices Note over P: 校验阶段冲突和 PG 所有权;失败不得启动引擎 C->>M: create_rollout_role / create_role(GenRM, Teacher) M->>E: 启动逻辑副本、等待健康与路由就绪 M->>M: 发布 READY / admission / topology_revision C->>G: deploy_gateway(role, manager_handle) U->>G: GET /role/engines 或 POST /role/generate G->>M: snapshot(role) G->>G: 显式 model -> route_key -> default;选择 Router 或 direct eligible 副本 G->>M: admit_request(role, model, request_id) M-->>G: 许可或拒绝 G->>E: 转发请求 / 流式响应 E-->>G: 输出 G->>M: complete_request(request_id) G-->>U: 输出或错误快照记录
manager_epoch(控制面生命周期)、每角色topology_revision、阶段、模型准入/权重版本、完整逻辑副本及诊断用 PD workers;TP/PP 内部 rank 不作为可请求副本。/<role>/engines默认 v2,?schema_version=1保留旧投影,autoscaler 改读 v2。Gateway 提供/health、/v1/models、/generate、/chat/completions、/v1/chat/completions等入口;GenRM messages 和{"response": ...}行为由适配器维持。休眠、排空、未就绪返回 503,不因请求自动唤醒。每个角色 Gateway 的并发上限按角色配置:Rollout / GenRM 沿用ROLLOUT_SERVE_MAX_ONGOING_REQUESTS/GENRM_SERVE_MAX_ONGOING_REQUESTS,Teacher 读新增的TEACHER_GATEWAY_MAX_ONGOING_REQUESTS(均默认 256,对齐 OPD 客户端默认连接数)。文本 Rollout / GenRM / Teacher 使用 SGLang Router;RouteMode.DIRECT的选择规则及 READY 副本轮询已实现,原生 diffusion rollout 引擎声明为 direct(不加入 Router):其模型由健康、版本有效的副本直接发布 READY,不发布router_url,也不要求引擎注册 Router。Discovery
schema_version=2布局GET /<role>/engines不带参数或带?schema_version=2时结构如下(以 Teacher 为例):{ "schema_version": 2, "role": "teacher", "manager_epoch": "3f9c...e1", "topology_revision": 4, "phase": "teacher", "routing": { "default_model": "default", "route_key_to_model": {"math": "default"}, "config_version": 0 }, "models": { "default": { "state": "ready", "admission": true, "router_url": "http://127.0.0.1:4464", "required_weight_version": null, "engines": [ { "engine_id": "default/replica-0", "base_url": "http://10.0.0.3:26715", "state": "ready", "weight_version": null, "direct_eligible": false } ], "pd_workers": [] } } }manager_epochtopology_revisionrouter_url、副本或 PD worker 的engine_id/base_url)或副本重启后回到 READY 时递增;休眠/唤醒等纯状态变化不递增,客户端需同时读state/admission。phaseinference/genrm/teacher),只用于描述,不代表资源所有权或准入。routingmodel→route_key_to_model[route_key]→default_model;route key 不允许重复。modelsmodel_id为键的对象,不是数组;模型 ID 唯一。state/admissionstarting/ready/draining/sleeping/onloading/dead)与准入开关。只有state=ready且admission=true的模型可被选中;休眠、排空、未就绪时 Gateway 返回 503 +Retry-After。router_url/required_weight_versionnull)。engines[]engine_id取自注册 spec 的replica_id(超出 spec 的副本为<model>/replica-<n>),进程替换或 scale-in 位移后保持不变,TP/PP 内部 rank 不单独列出。PD 模式在此处只暴露一个聚合的<model>/pd-service副本(base_url为 Router)。direct_eligible仅在 direct 路由模型的 READY 副本上为true,由 Manager 判定。pd_workers[]worker_type;只用于诊断,不会成为请求目标。status_filter=active|dead同时过滤engines和pd_workers(dead仅匹配state=dead,其余都算active)。快照只是观测:即使字段显示可用,请求仍须经 Manageradmit_request许可。?schema_version=1返回to_legacy_dict()旧投影:{"models": {id: {"router_ip", "router_port", "engine_groups": [{"engines": [{"rank", "url", "status"}]}], "total_engines"}}, "total_engines"}。其中status只表示端点存活(active不等于 READY),不包含 epoch、revision、准入和权重版本,仅供旧客户端过渡使用。请求的准入和完成登记在 Manager;准入回复在途时调用方被取消,permit 也会归还。每次执行使用独立的后端 rid 命名空间
relax-inf-<uuid>(batch 显式下发逻辑 rid 列表,n>1由 TokenizerManager 级联中止子请求),调用方传入的rid只记录日志、不再透传给引擎,以免并发请求的相同或前缀 rid 在 SGLang 的 abort 匹配中相互波及。断连/取消会按这些逻辑 rid 尝试中止上游请求,随后完成本次 Manager 请求登记。登记清除和 abort ACK 都不证明引擎已停止;GPU 交接也不依赖它们:卸载前引擎先pause_generation、退出 Router 并确认注销,再循环 abort 直到/flush_cache报告空闲才释放显存,任一步无法确认即保留显存并失败(Router 不可达时同样失败关闭)。请求级取消本身仍无引擎侧完成凭据,这是 RFC 对排空语义的重点 review 项。模型健康、路由可用性与实际 GPU 驻留分别记录:状态标记为 DEAD/SLEEPING 不自动意味着显存已经释放。GPU 布局、阶段交接与失败恢复
flowchart LR D1[Decoupled: 独立 PG] --> D2[各角色各自资源/可并行] S1[Colocate split: 同 PG 不相交 slice] --> S2[生成与评分可并行] F1[Colocate defer: 同 PG 跨阶段复用 slice] --> F2[关闭准入] F2 --> F3[排空在途请求] F3 --> F4[卸载并确认释放] F4 --> F5[激活 Teacher 或 GenRM] F5 --> F6[评分并退出阶段] F6 --> F7[训练阶段 / 下轮生成] X[共享 bundle 但未开 defer] --> Reject[参数校验 / 引擎启动前拒绝]PlacementPlanner以稳定 PG 标识和 bundle slice 记录分配,同阶段互斥,跨阶段允许复用;只有 Manager 所有的 PG 才由 Manager 删除,Controller / external PG 不越权清理。LifecycleCoordinator用激活租约串行化加载,按实际模型位置推导相互争用的角色:关闭准入、排空、卸载并确认释放后,才允许冲突角色激活并公布 READY;训练侧等待 Rollout release barrier。失败启动会回滚本次分配:Service 删除实际的<role>_backend/<role>_gateway应用,等待在途的角色启动结束后再停止引擎,引擎未确认停止则保留 PG;每次部署向 Manager 登记启动令牌,回滚后迟到的、或来自旧部署的角色启动会被拒绝。若引擎停止、释放显存或回滚不能确认,保留可能驻留的模型和 slice,后续不能在该 GPU 上盲目重建;关机时会等待仍在运行的 stranded 副本重试结束,不会因列表被取走而误报已停止。恢复还需重新建立健康、权重和路由证据;权重只恢复但 KV 尚未恢复时不能冒充可推理状态。fully-async 下 DCS 恢复出的替补引擎须所有 PP 源都确认同步后才注册 Router / 计为 READY(hybrid、LoRA adapter、静态权重不适用此确认);fully-async 启动时 Controller 在 120 s 总时限内(含每次 snapshot / refresh RPC)等待 rollout READY。Slot 的连续性按引擎继承的可见设备下的本地序号检查,物理 GPU 编号不必连续,弹性扩容的 precheck 按相同映射选择设备。Rollout 弹性操作仍经
/rollout/scale_out与/rollout/scale_in转到任务 Manager 的引擎池:scale-out 创建候选、完成健康/权重及 Router 注册后才公布可用拓扑;失败回滚时保留无法确认停止的副本。scale-in 先围栏权重更新和新请求,再撤销 Router 注册、排空、注销 DCS、停止引擎、释放 PG/slice;失败保留未确认释放的 GPU 占用与请求状态。相关单测覆盖注册顺序、回滚、围栏和资源释放;scale-out / scale-in 已在远端多 GPU 集群的 Ray Job 中实测通过。延迟评分与训练数据闭环
sequenceDiagram participant W as RolloutWorkload / Agentic participant D as DeferredOpdSession participant M as Manager + LifecycleCoordinator participant T as Teacher Gateway / engine participant Q as TransferQueue participant A as Trainer W->>W: 学生生成 sample、rollout logprobs W->>D: stage(batch, is_last, 样本身份/路由/多模态/token 选择) Note over Q: 未评分样本此时不可消费 W->>D: 生成结束,flush staged batches D->>M: enter_phase(teacher) M->>M: 排空并卸载学生、唤醒教师 D->>T: 按 data_source / 模型路由批量 prefill T-->>D: teacher logprobs / top-k 等评分结果 D->>M: leave_phase(teacher) opt 需要学生第二次 prefill D->>M: 重新激活生成阶段 D->>W: student prefill end D->>D: 按样本身份关联;校验字段、顺序、长度与 mask D->>Q: 仅完整批次 publish,保留 is_last Q->>A: 训练数据与 OPD lossDeferredExecutor记录 STAGED -> SCORING -> VALIDATING -> PUBLISHING -> COMPLETED / FAILED;DeferredOpdSession在生成阶段暂存而非提前写入 TQ,步末逐批评分、校验、发布。任一 eligible 样本缺少必须的 teacher 字段即失败,不发布成功的子集;未知结果的评分请求不盲目自动重放。OPD 输入和输出按样本身份封存,覆盖多次 Session 导出身份、乱序结果、token-selection、多模态以及取消后的阶段归还。单 Teacher / MOPD 根据布局选择:Teacher 与 rollout 共享 bundle 时 defer;独立 slice/PG 时仍即时评分。GenRM 的 deferred reward post-process 也在框架评分阶段执行,不再通过示例访问命名 GenRM actor。Teacher 后需要学生再次 prefill 的模式,显式切回生成阶段。MOPD 按data_source选择教师模型;文档中的多教师异构大模型训练不属于当前小模型验证结果。与 RFC #71 逐项对照
relax/components/inference_gateway.py的InferenceGateway、deploy_gateway;relax/core/service.py与relax/utils/opd/opd_utils.py使用同一部署路径。relax/core/controller.py建立任务 Manager;relax/distributed/ray/inference_manager.py的create_rollout_role/create_role,三角色共用账本、状态与生命周期;允许角色引擎池实现不同。relax/backends/sglang/sglang_engine.py的角色化初始化及 GenRM 专用排空参数;无独立GenRMEngine类。relax/engine/inference/routing.py的resolve_model、select_target同时供 Gateway 和InferenceDiscoveryClient调用;direct 能力为内部支持,当前生产角色仍经 Router。types.py/discovery.py,manager_epoch+topology_revision;PD workers 与engines分列,非 READY 不能准入。schema_version=1明确读取旧格式,默认 v2。老客户端若依赖默认旧格式必须迁移。create_inference_manager先require_deferred_shared_genrm和validate_task_layout;PlacementPlanner管理稳定 PG 键与分配 slice;共享 PG 下 actor/rollout/teacher 各 4 卡的布局已在多 GPU 集群上启动并完成训练。placement.py的PlacementOwner、阶段/资源冲突检查;fully-async 独立资源布局及单副本 / 4 卡 scale 场景已在集群上跑通。phase_plans.py+lifecycle.py;共享 4 卡 bundle 上连续 4 轮inference → teacher → 训练交接全部完成,每轮均为先卸载学生、再唤醒 Teacher,评分后再释放 Teacher。--defer-reward-to-post-process或 split;examples/generate_reward_model/run-qwen3-4B-8xgpu-colocated.sh已改为 4+4 split。LifecycleState六态;Manager 管理准入、模型驻留、回滚及故障恢复;超时/失败不伪造 GPU 释放。实测 Teacher 休眠期间 Router worker 已注销,Gateway 对POST /teacher快速返回 503;唤醒时先continue_generation再重新注册 Router。complete_request清除 Manager 登记;代码没有等待引擎确认 abort 的专门凭据。不能仅凭 Manager 登记归零证明推理已结束,需确认 Router/引擎侧机制是否提供足够保证。deferred.py、deferred_opd.py的封存、评分、验证、TQ 发布;tests/engine/rollout/test_deferred_opd.py及 Agentic 回归覆盖失败/取消等路径;集群上 4 轮每批 8 个样本均在带齐teacher_log_probs(数值有限)后才发布到 TQ 并完成训练。与 RFC 原文的显式调整 / 决策
RouteMode.DIRECT的路由/准入及轮询,但现有角色默认选 Router。外部裸引擎 URL 可以发送生成请求但是 defer请求不会被接受。data_source;共享 GPU 布局的参数校验已开放。/<role>/engines默认 v2,旧客户端改用?schema_version=1;迁移代码中的 autoscaler、metrics 导出已读 v2。旧投影只表示端点存活,router_ip/router_port为null,rank按模型内序号重新编号,不再含pid、node_id、actor_state。rid透传给引擎;依赖自定义 rid 直接中止引擎请求的调用方需改为断开连接或走 Gateway 取消。--defer-reward-to-post-process走 Defer-swap。relax_genrm_manager/relax_genrm_manager_<key>已移除;自定义custom_reward_post_process改用框架评分阶段(见examples/generate_reward_model/post_process_genrm_swap.py)。RolloutManager、MultiEngineManager、TeacherManager、GenRMManager已删除;上游 feat(opd): support multi-node teacher and rollout engines in MultiEngineManager #450 对后两者的多机扩展由统一引擎池承接。