Skip to content

【No.3】feat(inference): Unified Inference Service - #381

Open
leelingrui wants to merge 16 commits into
redai-studio:mainfrom
leelingrui:rfc-71-unified-inference
Open

leelingrui wants to merge 16 commits into
redai-studio:mainfrom
leelingrui:rfc-71-unified-inference

Conversation

@leelingrui

@leelingrui leelingrui commented Sep 26, 2026 •

Copy link
Copy Markdown

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 -->|权重同步、训练释放屏障| IM
Loading

relax/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: 输出或错误
Loading

快照记录 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_epoch 一次 Manager 生命周期的不透明 ID(uuid hex);重建/重启后变化。
角色 topology_revision 同一 epoch 内单调递增的非负整数。仅在可达拓扑变化(router_url、副本或 PD worker 的 engine_id/base_url)或副本重启后回到 READY 时递增;休眠/唤醒等纯状态变化不递增,客户端需同时读 state/admission。
角色 phase Manager 当前阶段(inference / genrm / teacher),只用于描述,不代表资源所有权或准入。
角色 routing 选模规则:显式 model → route_key_to_model[route_key] → default_model;route key 不允许重复。
模型 models 以 model_id 为键的对象,不是数组;模型 ID 唯一。
模型 state / admission 模型级六态之一(starting/ready/draining/sleeping/onloading/dead)与准入开关。只有 state=ready 且 admission=true 的模型可被选中;休眠、排空、未就绪时 Gateway 返回 503 + Retry-After。
模型 router_url / required_weight_version 当前请求入口的 SGLang Router,以及副本需达到的权重版本(静态模型为 null)。
副本 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[] PD 分离的 prefill/decode worker,字段与副本相同,另加 worker_type;只用于诊断,不会成为请求目标。

status_filter=active|dead 同时过滤 engines 和 pd_workers(dead 仅匹配 state=dead,其余都算 active)。快照只是观测:即使字段显示可用,请求仍须经 Manager admit_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[参数校验 / 引擎启动前拒绝]
Loading

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 loss
Loading

DeferredExecutor 记录 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 逐项对照

RFC 条目 状态 代码及行为依据 / 剩余条件
一个 CPU Gateway 类,按 role 部署 代码已覆盖 relax/components/inference_gateway.py 的 InferenceGateway、deploy_gateway;relax/core/service.py 与 relax/utils/opd/opd_utils.py 使用同一部署路径。
一个 Manager 类/每任务一个逻辑控制实例,统一管理三种池 代码已覆盖 relax/core/controller.py 建立任务 Manager;relax/distributed/ray/inference_manager.py 的 create_rollout_role / create_role,三角色共用账本、状态与生命周期;允许角色引擎池实现不同。
一个 SGLangEngine,移除 GenRM 子类 代码已覆盖 relax/backends/sglang/sglang_engine.py 的角色化初始化及 GenRM 专用排空参数;无独立 GenRMEngine 类。
Gateway / 直连客户端共享模型路由规则 代码已覆盖 relax/engine/inference/routing.py 的 resolve_model、select_target 同时供 Gateway 和 InferenceDiscoveryClient 调用;direct 能力为内部支持,当前生产角色仍经 Router。
统一 discovery,模型状态/版本/逻辑副本、PD 诊断 代码已覆盖 types.py / discovery.py,manager_epoch + topology_revision;PD workers 与 engines 分列,非 READY 不能准入。
Gateway HTTP 接口及旧行为兼容 代码已覆盖 role Gateway 的 discovery、health、models、generate、chat;GenRM messages 适配;schema_version=1 明确读取旧格式,默认 v2。老客户端若依赖默认旧格式必须迁移。
引擎启动前解析并验证全部 GPU bundle / PG 所有权 代码已覆盖 create_inference_manager 先 require_deferred_shared_genrm 和 validate_task_layout;PlacementPlanner 管理稳定 PG 键与分配 slice;共享 PG 下 actor/rollout/teacher 各 4 卡的布局已在多 GPU 集群上启动并完成训练。
Decoupled 与 colocated split 代码已覆盖,远端 4×GPU 集群已测 placement.py 的 PlacementOwner、阶段/资源冲突检查;fully-async 独立资源布局及单副本 / 4 卡 scale 场景已在集群上跑通。
Colocated defer 串行使用共享 GPU 代码已覆盖,远端 4×GPU 集群已测 phase_plans.py + lifecycle.py;共享 4 卡 bundle 上连续 4 轮 inference → teacher → 训练 交接全部完成,每轮均为先卸载学生、再唤醒 Teacher,评分后再释放 Teacher。
shared co-resident 拒绝 / 删除 代码已覆盖 Shared / Co-resident 子模式已从代码与文档删除:共享 rollout bundle 未开 defer 时参数校验即报错并提示 --defer-reward-to-post-process 或 split;examples/generate_reward_model/run-qwen3-4B-8xgpu-colocated.sh 已改为 4+4 split。
六态生命周期和幂等激活/排空/卸载/关闭,故障恢复 代码已覆盖,远端 4×GPU 集群已测 LifecycleState 六态;Manager 管理准入、模型驻留、回滚及故障恢复;超时/失败不伪造 GPU 释放。实测 Teacher 休眠期间 Router worker 已注销,Gateway 对 POST /teacher 快速返回 503;唤醒时先 continue_generation 再重新注册 Router。
取消请求必须有可证明的排空/中止语义 代码已覆盖 Gateway 取消时请求上游 abort,随后 complete_request 清除 Manager 登记;代码没有等待引擎确认 abort 的专门凭据。不能仅凭 Manager 登记归零证明推理已结束,需确认 Router/引擎侧机制是否提供足够保证。
Teacher defer 写回 teacher 输出后训练才能消费 代码已覆盖,远端 4×GPU 集群已测 deferred.py、deferred_opd.py 的封存、评分、验证、TQ 发布;tests/engine/rollout/test_deferred_opd.py 及 Agentic 回归覆盖失败/取消等路径;集群上 4 轮每批 8 个样本均在带齐 teacher_log_probs(数值有限)后才发布到 TQ 并完成训练。
迁移阶段 0–7 / 清除旧控制面 代码迁移已覆盖 公共查询与 Gateway、统一 Manager、Placement/生命周期、defer、workload 迁移、旧 role manager 删除;是否仍有外部公开 API 用户依赖旧类型须由 PR review 评估。
多 GPU 单机测试 已测 defer OPD(Router 与 direct 两种)多轮训练、fully-async 单副本 / 4 卡 scale、scale-out / scale-in 均以 Ray Job 跑通。注意:集群实测之后的审核修复(DCS 替补确认、rid 命名空间、部署回滚与启动令牌、Gateway 并发、删除 co-resident、stranded 重试、Router 不可达失败关闭、启动 READY 时限、diffusion direct 观测、#450 合并)仅有 CPU 单测,未在集群上复测。

与 RFC 原文的显式调整 / 决策

  1. direct 路由:RFC 决策表写“首版选 Router”,API 章节同时定义 direct-eligible fallback;当前实现提供 RouteMode.DIRECT 的路由/准入及轮询,但现有角色默认选 Router。外部裸引擎 URL 可以发送生成请求但是 defer请求不会被接受。
  2. MOPD 与共享 Teacher:共用 bundle 时启用 deferred OPD,split/独立资源保持即时评分;多教师路由使用 data_source;共享 GPU 布局的参数校验已开放。
  3. 兼容边界 / 迁移说明:
    • /<role>/engines 默认 v2,旧客户端改用 ?schema_version=1;迁移代码中的 autoscaler、metrics 导出已读 v2。旧投影只表示端点存活,router_ip / router_port 为 null,rank 按模型内序号重新编号,不再含 pid、node_id、actor_state。
    • 原始 OPD Teacher engine URL 只作为兼容信息/非 defer 场景,不应绕过统一 Gateway 的共享资源准入。
    • Gateway 不再把调用方 rid 透传给引擎;依赖自定义 rid 直接中止引擎请求的调用方需改为断开连接或走 Gateway 取消。
    • Shared / Co-resident GenRM 布局(rollout = genrm = actor 全卡且未开 defer)不再支持:改为 split,或开启 --defer-reward-to-post-process 走 Defer-swap。
    • 命名 actor 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 对后两者的多机扩展由统一引擎池承接。

@rai-studio-bot

rai-studio-bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Nyanpasu 审查看板

审查状态: ✅ 已通过

审查版本: e29cc71

目标分支: main

e29cc71 复核完成,已[审查通过](https://github.com/redai-studio/Relax/pull/381#pullrequestreview-5574200032)。示例资源改为受支持的 4+4 split,参数/放置/即时评分接线一致;相关迁移说明已核对,无新增可操作问题。此前发现状态保留。

审查阶段进度范围与结果
常规审查 ✅ 已完成 153 路径准入均接受;本轮完成唯一增量启动脚本及更新的 PR 说明/迁移指南核查。其余源码与已通过的 24650b8 相同,沿用既有完成证据;RFC 要求未变。
深度审查 ✅ 已完成 Launcher 专项沿 CLI 派生 → 八卡共享 PG → rollout [0,4) / GenRM [4,8) 检查,确认四个单卡 rollout 副本与一个 TP4 GenRM 副本、即时 dapo-genrm 评分和原训练交接接线。本轮父子审查均未运行测试或训练;无提供的 GPU/NPU 集群,实际启动、模型显存适配、吞吐和多节点交接未验证。

审查发现

待处理
编号 严重性 问题状态规则来源
暂无待处理的记录。
已解决或已取代
编号 严重性 问题状态规则来源
F1 High severity diffusion/native 调用迁移后已不存在的引擎方法 ✅ 已解决 —
F2 Medium severity shutdown_all 异常提前终止全局重启 ✅ 已解决 —
F3 Medium severity defer GenRM 错误接受 split/fully-async 布局 ✅ 已解决 —
F4 Low severity 公开 API 删除和 discovery v2 的文档迁移遗漏 ✅ 已解决 —
F5 Low severity 控制面转发错误继承推理读超时 ✅ 已解决 —
F6 Low severity 单模型 Gateway 对显式模型名的兼容回退 ✅ 已解决 —
F7 Low severity DeferredOpdSession.flush 的 publish 闭包 rollout_id 晚绑定,未来传超时会错分区发布 ✅ 已解决 —
F8 Low severity 空展开批次静默丢弃,流式分区 is_last 标记可能永不送达 ✅ 已解决 —
F9 Low severity teacher colocate 校验链中 actor GPU 数存在两个定义,--use-critic 时判定矛盾或误拒 ✅ 已解决 —
F10 Medium severity checkpoint_prefetch 缺 SGLang 守卫,CPU 收集失败 ✅ 已解决 —
F11 Medium severity NPU 初始同步后 rollout 因版本探测 404 变 DEAD ✅ 已解决 —
F12 Low severity 缺少 publish 写侧准入不变量回归 ✅ 已解决 —
F13 Low severity 移除无生产消费者的 expose_engine_urls ✅ 已解决 —
F14 Medium severity placement 预检链路在 CPU 测试中导入 SGLang ✅ 已解决 —
F15 High severity admission 回包前取消会泄漏许可 ✅ 已解决 —
F16 High severity 恢复副本缺少全部 PP 接收确认 ✅ 已解决 —
F17 Medium severity native input_embeds 的 RID 与后端形状不一致 ✅ 已解决 —
F18 Medium severity 调用方 RID 前缀冲突会误中止其他请求 ✅ 已解决 —
F19 Medium severity 已中止部署的旧创建在重新开放后仍可能被接纳 ✅ 已解决 —
F20 Medium severity 探测失败被指标发现报告为成功空池 ✅ 已解决 —
F21 Medium severity 物理连续性校验误拒稀疏可见 GPU 映射 ✅ 已解决 —
F22 Medium severity 既有问题:Gateway/discovery 的模型别名规则不一致 ✅ 已解决 RFC #71:Gateway 与 direct client 共用路由规则
F23 Medium severity 初始 READY 等待未将刷新 RPC 纳入 120 秒总时限 ✅ 已解决 —
提交范围 · 接收 153 · 建议移出 0 · 待确认 0

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

文件结论仓库维护必要性依据替代去向或方案
relax/distributed/ray/inference_manager.py
relax/engine/inference/__init__.py
relax/engine/inference/config.py
relax/engine/inference/config_adapters.py
relax/engine/inference/discovery.py
relax/engine/inference/executor.py
relax/engine/inference/lifecycle.py
relax/engine/inference/phase_plans.py
relax/engine/inference/placement.py
relax/engine/inference/routing.py
relax/engine/inference/types.py
接收 任务级控制面:角色配置、路由、许可、Placement 与生命周期实现。 RFC #71;Controller 创建 Manager,Gateway 和 Worker 为实际消费者。 当前控制面目录及 Ray actor 文件承载对应职责。
relax/backends/fsdp/actor.py
relax/backends/megatron/actor.py
relax/backends/megatron/weight_update/update_weight_from_tensor.py
relax/backends/sglang/diffusion_engine.py
relax/backends/sglang/sglang_engine.py
relax/distributed/coordination.py
relax/distributed/ray/actor_group.py
relax/distributed/ray/genrm.py
relax/distributed/ray/multi_engine_manager.py
relax/distributed/ray/multi_instance_orchestrator.py
relax/distributed/ray/placement_group.py
relax/distributed/ray/rollout.py
relax/distributed/ray/rollout_worker.py
relax/distributed/ray/teacher_manager.py
relax/distributed/ray/train_actor.py
接收 引擎、PG、权重同步及恢复接入统一 Manager;旧角色 manager 删除。 RFC #71 的统一生命周期与物理放置;既有 Trainer/Service/Worker 调用方。 保留实现所在后端及分布式目录,同步清理旧 API。
relax/agentic/rollout.py
relax/engine/rollout/data_source.py
relax/engine/rollout/deferred.py
relax/engine/rollout/deferred_opd.py
relax/engine/rollout/native_generation.py
relax/engine/rollout/on_policy_distillation.py
relax/engine/rollout/scoring_phase.py
relax/engine/rollout/sglang_rollout.py
relax/engine/rollout/workload.py
relax/utils/opd/opd_utils.py
接收 生成、延迟评分及 OPD 数据流适配新控制面与合并后的 main。 RFC #71 defer;现有 Agentic/OPD 和 TransferQueue 生产调用链。 业务与评分仍放在对应 workload/OPD 模块。
relax/components/__init__.py
relax/components/actor.py
relax/components/genrm.py
relax/components/inference_gateway.py
relax/components/rollout.py
relax/core/controller.py
relax/core/service.py
relax/engine/sft/predict/runner.py
relax/utils/arguments.py
relax/utils/async_utils.py
relax/utils/autoscaler/autoscaler_service.py
relax/utils/checkpoint_write_patch.py
relax/utils/colocate_alignment.py
relax/utils/data/data_utils.py
relax/utils/device.py
relax/utils/env.py
relax/utils/health_monitor.py
relax/utils/http_utils.py
relax/utils/metrics/service.py
relax/utils/metrics/sglang_exporter.py
relax/utils/utils.py
接收 Controller/Service/组件及配置、指标等基础设施迁移与本轮修复。 PR #381 目标;现有训练、部署、自动扩缩容和观测消费者。 在既有拥有该调用边界的模块中维护。
tests/backends/fsdp/test_save_and_validation.py
tests/backends/megatron/test_actor_http_timeout.py
tests/backends/megatron/test_actor_rollout_recovery.py
tests/backends/sglang/test_genrm_offload_drain.py
tests/backends/sglang/test_router_registration.py
tests/components/test_genrm_engine_pick.py
tests/components/test_genrm_manager_lookup.py
tests/components/test_rollout_gateway_access.py
tests/components/test_rollout_weight_update_handshake.py
tests/core/test_control_plane_affinity.py
tests/core/test_controller_global_restart.py
tests/core/test_controller_s3_model_cleanup.py
tests/core/test_controller_sft_colocate.py
tests/core/test_controller_sft_loop.py
tests/core/test_pd_disposal.py
tests/core/test_service_affinity.py
tests/distributed/checkpoint_service/test_rollout_sync_recipients.py
tests/distributed/ray/conftest.py
tests/distributed/ray/test_coordination.py
tests/distributed/ray/test_engine_generation_identity.py
tests/distributed/ray/test_engine_group_placement.py
tests/distributed/ray/test_engine_metadata.py
tests/distributed/ray/test_engine_metadata_local_ray.py
tests/distributed/ray/test_genrm_recovery.py
tests/distributed/ray/test_inference_manager_actor.py
tests/distributed/ray/test_multi_engine_manager.py
tests/distributed/ray/test_opd_multi_teacher_orchestration.py
tests/distributed/ray/test_opd_teacher_controller_colocate.py
tests/distributed/ray/test_pd_router_startup.py
tests/distributed/ray/test_recovered_engine_registration.py
tests/distributed/ray/test_recovery_router_cleanup.py
tests/distributed/ray/test_rollout_engine_config.py
tests/distributed/ray/test_rollout_inference_pool.py
tests/distributed/ray/test_rollout_startup_placement.py
tests/distributed/ray/test_rollout_worker.py
tests/distributed/ray/test_scale_in.py
tests/distributed/ray/test_scale_out_registration_order.py
tests/distributed/ray/test_scale_weight_sync_precheck.py
tests/distributed/ray/test_teacher_manager.py
tests/distributed/ray/test_teacher_manager_factory.py
tests/distributed/ray/test_utils.py
tests/engine/inference/test_config_adapters.py
tests/engine/inference/test_discovery.py
tests/engine/inference/test_executor.py
tests/engine/inference/test_gateway.py
tests/engine/inference/test_manager.py
tests/engine/inference/test_phase_plans.py
tests/engine/inference/test_placement.py
tests/engine/inference/test_routing.py
tests/engine/rollout/test_checkpoint_prefetch.py
tests/engine/rollout/test_data_source.py
tests/engine/rollout/test_deferred_opd.py
tests/engine/rollout/test_native_generation.py
tests/engine/rollout/test_on_policy_distillation_routing.py
tests/engine/rollout/test_sglang_rollout_dynamic_filter.py
tests/engine/rollout/test_weight_sync_499.py
tests/entrypoints/test_startup_failure.py
tests/test_agentic_rollout.py
tests/utils/autoscaler/test_autoscaler_service.py
tests/utils/data/test_data_utils.py
tests/utils/test_arguments_genrm_instances.py
tests/utils/test_checkpoint_write_patch.py
tests/utils/test_colocate_alignment.py
tests/utils/test_health_system.py
tests/utils/test_http_utils_router_env.py
tests/utils/test_metrics_service_http.py
tests/utils/test_sglang_metrics_exporter.py
接收 持久回归覆盖统一推理、修复及既有入口;移除旧模块测试。 对应生产 API、生命周期、绑定、恢复和数据交付契约。 使用既有 tests 子目录,随生产行为长期回归。
examples/diffusion/README.md
examples/generate_reward_model/post_process_genrm_swap.py
examples/on_policy_distillation/mopd/run-mopd-qwen35-35ba3b-16xgpu-colocate.sh
接收 用户示例迁移已删除的 actor/API 与 defer 使用方式。 仓库公开示例及现有 GenRM/MOPD/diffusion 调用行为。 原示例位置适合更新其现有入口。
.opencode/agents/launcher-expert.md
.opencode/agents/ray-expert.md
AGENTS.md
README.md
README_zh.md
docs/en/api/rollout.md
docs/en/guide/architecture.md
docs/en/guide/autoscaler-k8s-keda.md
docs/en/guide/dataset-design.md
docs/en/guide/elastic-rollout.md
docs/zh/api/rollout.md
docs/zh/guide/architecture.md
docs/zh/guide/autoscaler-k8s-keda.md
docs/zh/guide/dataset-design.md
docs/zh/guide/elastic-rollout.md
skills/debug-hang/references/case-rollout-eval-onload-hang.md
skills/opd-tuning/SKILL.md
skills/opd-tuning/references/balance.md
skills/opd-tuning/references/teacher-knobs.md
接收 用户文档、架构与仓库技能同步公开 API 和 discovery 格式迁移。 RFC #71 与既有 docs/skills/README 对外说明。 保留在原文档及指导文件位置。
docs/en/api/genrm.md
接收 同步受支持 GenRM 配置和架构的持久用户文档。 GenRM CLI 与 RFC #71 的布局边界。 保留双语现有文档入口;不另建一次性验证记录。
docs/en/examples/generative-reward-model.md
接收 同步受支持 GenRM 配置和架构的持久用户文档。 GenRM CLI 与 RFC #71 的布局边界。 保留双语现有文档入口;不另建一次性验证记录。
docs/zh/api/genrm.md
接收 同步受支持 GenRM 配置和架构的持久用户文档。 GenRM CLI 与 RFC #71 的布局边界。 保留双语现有文档入口;不另建一次性验证记录。
docs/zh/examples/generative-reward-model.md
接收 同步受支持 GenRM 配置和架构的持久用户文档。 GenRM CLI 与 RFC #71 的布局边界。 保留双语现有文档入口;不另建一次性验证记录。
examples/generate_reward_model/architecture-diagram-prompts.md
接收 在既有 GenRM 示例设计说明中同步支持模式,避免文档引用已移除子模式。 既有 examples/generate_reward_model 示例及其架构说明消费者。 与该示例放在同目录便于持续维护,不引入一次性验证记录。
tests/backends/sglang/test_diffusion_engine.py
接收 覆盖本轮推理修复的生产回归。 RFC #71 生命周期/路由契约与增量修复的实际消费者。 保留在对应后端/核心测试目录,便于持续回归。
examples/generate_reward_model/run-qwen3-4B-8xgpu-colocated.sh
接收 将既有 8 GPU GenRM 示例迁移为受支持的 split 布局,避免已移除 co-resident 模式在参数校验失败。 当前 PR 的 GenRM split/defer 兼容边界与原有用户启动脚本。 在原公开示例入口更新资源配置,保留训练脚本用途。
精简审查与验证依据
审查范围进度结论
生产代码 ✅ 已完成 历史记录(截至 3740bea,本轮未重做):核心机制保留;5691b9aa 删除无消费者开关(F13)。
测试 ✅ 已完成 历史记录(截至 3740bea,本轮未复跑):子任务超时后父审查 305 例通过;3 次变异 2 检出、1 存活(F12);GPU/多节点及依赖缺失族未运行。

生产代码的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
LifecycleCoordinator:租约、阶段交接与 rollout 释放屏障 共享 bundle 角色串行交接;scoring_phase/DeferredOpdSession 与 trainer 消费。 参考方案:Megatron actor 的 Gloo barrier 排序,Manager 幂等执行。 保留 worker 步末触发 OPD/GenRM,actor 无法表达此时序;统一协调保证单一写者。参考 E1 仅验证替代机制,未集成 workload(partial)。
weight_source 控制 DCS 注册与 READY 发布 静态模型不做 DCS 更新;READY 需健康副本、Router 和一致版本。 参考方案同样按 requires_weight_sync 派生 skip_dcs_registration。 保留 历史 sglang_engine.py:479 绑定 register_dcs 与 weight_source,防止 GenRM 静默注册 DCS;test_manager 覆盖发布,写侧专测缺口见 F12。
失败启动残留、stranded 重试与 resident 跟踪 释放未确认时保留占用,禁止冲突重建。 base MultiEngineManager 的 retire/recover。 保留 shutdown 失败保留注册并阻止加载;tests/distributed/ray 覆盖 scale-in 围栏及 scale-out 回滚。参考方案未覆盖此语义。
每角色独立 Gateway 与 /rollout/backend CPU 网关统一三角色入口,休眠时可用。 将 ingress 合入现有 role Serve deployment。 保留 复杂度相当;独立部署分离控制和推理入口。历史 test_gateway 23 例覆盖;未确认可删除的重复层。
expose_engine_urls 标志与 URL 剥离分支 名义上允许不暴露 URL。 删除标志及分支,或接入实际消费者。 删除 仅测试设 False,无生产消费者;5691b9aa 已连同测试删除,搜索无残留,历史本地 115 例通过(F13)。

测试的必要性与替代方案

范围必须保留的契约更简单的方案结论依据与限制
tests/engine/inference 七组测试 启动前放置拒绝、六态幂等、400/503 选模、v2/v1 发现。 合并文件或只测纯函数。 保留 历史 113 例通过;删同相位重叠检查有 3 例失败,绕过准入被 race 用例检出。oracle 来自协议;按职责拆分,无重复脚手架。
publish 的 Only-READY-may-admit 专测 唯一写者须拒绝不一致快照。 只测 admit_request 读侧拒绝。 替换 历史删除写侧不变量的变异未检出;以读侧加 STARTING/admission=True 拒绝用例取代仅读侧覆盖(F12)。
deferred_opd 与 agentic 回归族 封存、完整评分、is_last、取消与多导出身份。 压成单一冒烟测试。 保留 历史子审查确认独立 oracle 覆盖失败/乱序/多导出;本地缺 torch 未运行。压缩会丢失独立失败边界。
distributed/ray 的 scale、pool、placement、worker 测试 注册顺序、回滚、围栏、释放和 worker 行为。 合并 startup_placement 与纯 planner 场景。 保留 入口不同,不属重复;依赖 numpy 族历史未运行,H20 CI 单测通过。checkpoint_prefetch 缺 SGLang 守卫导致 CPU CI 失败(F10)。
components/core/backends/utils 的 18 个既有测试 随 API 迁移保持回归。 删除或外移。 保留 对应生产最小适配,包括 v2、权重握手、健康系统;历史抽查未见断言弱化。
Powered by Nyanpasu with gpt-6.1-sol xhigh, please check the suggestions carefully.

@SigureMo SigureMo changed the title [task 3] feat(inference): Unified Inference Service 【No.3】feat(inference): Unified Inference Service Sep 26, 2026

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

审查结论:需要修改

按 head ec525966 完成常规审查(97 个变更文件全部纳入,范围裁定与进度见审查看板)。控制面设计总体扎实:准入/放置/生命周期不变量、publish 校验(READY 需 Router、权重版本一致)、失败时保守保留 GPU 与 slice、discovery v2/v1 双投影等均验证无误;本地可运行的 305 个单测全部通过(其余因审查环境缺 numpy/torch/GPU 无法执行,已记录为 gap)。但发现 1 个阻塞性回归与 2 个边界缺陷:

  • High severity 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 即受影响)。
  • Medium severity P2:_run_global_restart 中 shutdown_all 是唯一未包 try/except 的清理步骤,单个卡死引擎或 manager actor 死亡会把本可恢复的全局重启变成任务终止。
  • Medium severity 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 算术不一致),见行级评论。

Low severity P3 · 同步公开控制面与 /engines 文档

非行级(文档与 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 过渡)。

深度审查(独立设计对比 + 测试审计)仍在进行,结论将在看板补充。

Powered by Nyanpasu with glm-5.3[1m] xhigh, please check the suggestions carefully.

Comment thread relax/distributed/ray/rollout_worker.py Resolved
Comment thread relax/core/controller.py Resolved
Comment thread relax/engine/inference/phase_plans.py Resolved
Comment thread relax/components/inference_gateway.py Resolved
Comment thread relax/engine/inference/routing.py Resolved
Comment thread relax/engine/rollout/deferred_opd.py Resolved
Comment thread relax/engine/rollout/deferred_opd.py Resolved
Comment thread relax/utils/opd/opd_utils.py Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

深度审查补充(常规审查结论不变)

深度审查已完成,证据与逐项裁定见审查看板。要点:

  • 独立设计对比:仅从 RFC #71 与 base 出发的独立参考设计(独立性 clean,三个可执行实验全过)与本实现在关键机制上收敛:六态生命周期、topology_revision 原子发布、head-only 副本暴露、weight_source 结构性门控 DCS 注册(关闭了参考设计识别出的"删除 GenRMEngine 后 fully-async 下 GenRM 静默注册 DCS"陷阱)、503-never-wake。差异点(集中式 LifecycleCoordinator vs 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 路径回归)仍未解决,审查结论保持需要修改。

Powered by Nyanpasu with glm-5.3[1m] xhigh, please check the suggestions carefully.

Comment thread relax/core/controller.py Resolved
Comment thread relax/engine/inference/config.py Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查结论:无阻塞项(有补充意见)

两个修复轮(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 确认不构成合并阻塞。整体设计经独立参考对比验证无多余核心机制,修复质量良好。

完整证据、逐项裁定与范围决策见审查看板。

Powered by Nyanpasu with glm-5.3[1m] 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.

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 同步,非阻塞)。完整状态见审查看板。

Powered by Nyanpasu with glm-5.3[1m] xhigh, please check the suggestions carefully.

Comment thread relax/core/controller.py Resolved

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查结论:通过 ✅

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),生产/测试必要性审计完成,无多余核心机制;唯一精简建议(投机开关)已由作者采纳。

感谢高质量的修复协作。完整逐项证据见审查看板。

Powered by Nyanpasu with glm-5.3[1m] 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.

审查结论:通过 ✅(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 集成,由分支保护做最终把关。

完整记录见审查看板。

Powered by Nyanpasu with glm-5.3[1m] xhigh, please check the suggestions carefully.

@SigureMo

SigureMo commented Oct 8, 2026

Copy link
Copy Markdown
Member

辛苦解决下冲突~

@SigureMo

SigureMo commented Oct 8, 2026

Copy link
Copy Markdown
Member

另外这个 PR 也没提交 review 请求哦,解决完冲突如果觉得没问题了可以在 PR 里 @ 我一下

@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

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 沿用记录。

详情与发现索引见审查看板。

Powered by Nyanpasu with glm-5.3-flash max, please check the suggestions carefully.

@Yangruipis Yangruipis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这版实现已经形成较完整的统一推理架构:任务级 Manager 集中管理引擎所有权与资源状态,三个角色共用 Gateway,Rollout 业务也从引擎管理中独立出来,整体职责划分清晰,符合 RFC 的主要方向。

当前需要补齐的是这些边界上的行为一致性,尤其是请求准入、排空、卸载与健康观测之间的不变量;同时应收敛重复的请求执行路径,完善实际资源绑定校验、数据发布契约和接口迁移说明。

建议先修复已确认的正确性问题并加入并发回归,再逐项处理设计与验收建议,明确已有测试证据及尚未覆盖的场景,使架构上的统一落实为可验证、可维护的运行行为。

return
self.set_state(role, model_id, LifecycleState.DRAINING)
try:
entry.pool.offload()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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 的顺序调用。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

已经修复,此外额外添加排空超时强制终止参数,当force_abort参数为True时,若抵达设定的超时时间将会强制终止在引擎上正在生成的请求。若force_abort为false,则周期性打印警告,周期为所设定的超时时间。

scale-in未复用Manager的统一生命周期操作主要有以下两个原因:

  1. Manager 关闭的是整个模型的准入,复用的话,scale-in 期间该模型所有副本都会停止接收请求;而 scale-in 只是摘掉其中几个副本,其余副本需要继续服务。
  2. 这里要防的风险是:offload 之后进程还活着、显存已经释放,请求却仍然到达引擎。scale-in 不存在这种状态。它先把副本从 Router 注销,之后不会再有新请求路由过去;并在宽限期结束后直接 kill

Comment thread relax/components/inference_gateway.py Outdated
if not isinstance(response, StreamingResponse):
if not finished:
await self._abort_upstream(target, rid)
await self._manager_call("complete_request", request_id)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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 竞态分别处理。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

现在 GPU 交接要两份证据,缺一不可(inference_manager.py 模块 docstring 写明了这一契约):

  1. 网关侧:_drain_models 关准入并等 permit 账本清空。
  2. 引擎侧:pool.offload() → SGLangEngine.release_memory_occupation():先 pause_generation(不是 best-effort)、从 Router 注销并确认移除,再循环 abort 直到 /flush_cache 报告空闲,最后发送需确认的 release_memory_occupation。任何一步无法确认就抛错。

@leelingrui leelingrui Oct 20, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

offload 抛错时模型被置为 DEAD 且 resident=True,冲突角色的租约拿不到时不会 onload;shutdown 在宽限期后强制 abort 再停引擎,停不掉的模型保持注册状态以便重试。

Comment thread relax/engine/inference/placement.py Resolved
Comment thread relax/components/genrm.py Resolved
return record.snapshot
self._advance(record, DeferredState.PUBLISHING, scored=record.batch_ref.eligible_count)
try:
await publish(record.payload, record.is_last)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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。此项是验收请求,不是已复现的数据损坏。

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

核对了 TQ(SimpleStorage 后端)的实际语义,结论是:单次 async_put 本身就提供了 batch 级原子可见性,因此没有另加 staging partition / commit marker

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

仍存在的边界:

  • 写入成功但响应丢失: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}。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

感谢补充具体的 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 分布式故障实验。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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 数量撤销已经成立的职责拆分。

@SigureMo

Copy link
Copy Markdown
Member

辛苦处理一下 review 意见以及再解决下冲突,今天合入了一个大 PR 冲突项比较多~

@leelingrui
leelingrui marked this pull request as draft October 12, 2026 14:36
@rai-studio-bot

rai-studio-bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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 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, RexFlux, yuanlehome, SigureMo, NINGBENZHE, Lemon-412
CI ⏳ 等待通过

@leelingrui
leelingrui force-pushed the rfc-71-unified-inference branch 2 times, most recently from 26752a1 to 15fb9f0 Compare October 17, 2026 10:58
…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.
@leelingrui
leelingrui force-pushed the rfc-71-unified-inference branch from 83faff4 to 08e6722 Compare October 19, 2026 14:25

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

审查通过

08e67229 已修复上轮 READY 等待的时限问题。已完成新 main 基线的合并交互核查,未发现新的可操作问题。本轮依据源码及依赖契约,新增回归未在本地执行,也未做多节点 GPU/NPU 集成。

完整审查看板

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

@leelingrui

Copy link
Copy Markdown
Author

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

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

审查通过

24650b83 的测试依赖修复已复核:最小 SGLang stub 供真实恢复方法共用,模块状态会在用例结束后恢复;权重恢复与完整恢复的关键断言保留。未发现新的可操作问题。本轮只审读源码,未执行本地测试。

完整审查看板

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

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.

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

审查通过

e29cc713 的示例配置与 4+4 split 的参数派生、放置和即时 GenRM 评分路径一致,相关迁移说明已核对。未发现新的可操作问题。本轮仅作源码核查,未运行测试或 GPU/NPU 训练。

完整审查看板

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

@Yangruipis Yangruipis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

感谢这轮完善,统一请求执行和生命周期管理的方向值得肯定。建议按职责拆分 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

感谢补充具体的 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[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 同时存在时各区域不冲突。

@Yangruipis

Copy link
Copy Markdown
Collaborator

🎉 恭喜,这次我们决定选择你的方案作为 unified inference 后续合入和演进的基础!感谢你持续投入,也感谢这几轮 review 中认真回应和推进修改 👏

我们比较看重这份实现对统一推理服务边界的梳理:将资源管理、请求准入和生命周期协调收敛到公共层,让 Rollout、Teacher、GenRM 复用基础机制,同时为各角色保留独立演进的空间。最近几轮对公共请求执行、状态管理和实际资源绑定校验的完善,也让方案更扎实了。

接下来建议先解决与主分支的冲突,再拆成几个更轻量、方便评审和验证的 PR。方向可以粗略考虑:

  • 配置与布局基础:角色配置、资源描述和布局校验。
  • 公共推理管理:统一 Manager、请求执行与生命周期协调。
  • 角色接入与流程迁移:逐步接入各角色,再迁移 defer 等跨角色流程。

具体边界按依赖关系调整,重点是每一步都能独立运行和验证,必要时保留短期适配。我们内部也会配合验证,结合实际训练场景检查兼容性、稳定性和性能,一起推进问题修复。期待共同把这块基础打磨好 🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants